Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
55 changes: 47 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,62 @@ jobs:
id: vars
run: echo "COMMIT_HASH=$(git rev-parse --short HEAD)" >> $GITHUB_ENV

- name: Update version to -<commit-hash>
run: npm version --no-git-tag-version "${{ steps.package-version.outputs.current-version }}-experimental-${{ env.COMMIT_HASH }}"

- name: Package npm project
run: npm pack
- name: Update workspace versions to -<commit-hash>
env:
PACKAGE_VERSION: ${{ steps.package-version.outputs.current-version }}-experimental-${{ env.COMMIT_HASH }}
run: |
node <<'NODE'
const fs = require("node:fs");
const path = require("node:path");

const packagesDir = path.join(process.cwd(), "packages");
const version = process.env.PACKAGE_VERSION;
const packages = fs
.readdirSync(packagesDir)
.filter((dir) => fs.existsSync(path.join(packagesDir, dir, "package.json")))
.map((dir) => {
const packageJsonPath = path.join(packagesDir, dir, "package.json");
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
return { packageJsonPath, packageJson };
});
const workspaceNames = new Set(packages.map(({ packageJson }) => packageJson.name));

for (const { packageJsonPath, packageJson } of packages) {
packageJson.version = version;

for (const field of ["dependencies", "peerDependencies", "devDependencies"]) {
if (!packageJson[field]) continue;

for (const dependencyName of Object.keys(packageJson[field])) {
if (workspaceNames.has(dependencyName)) {
packageJson[field][dependencyName] = version;
}
}
}

fs.writeFileSync(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}\n`);
}
NODE

- name: Package npm workspaces
run: npm pack --workspaces

- name: Upload npm package artifact
uses: actions/upload-artifact@v7
with:
name: npm-package
name: npm-packages
path: "*.tgz"

- name: Publish to npm
- name: Publish npm packages
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
env:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }}
run: npm publish --access public ./*.tgz --tag experimental
run: |
for package in packages/*; do
if [ -f "$package/package.json" ]; then
npm publish --workspace "$package" --access public --tag experimental
fi
done

deploy-docs:
needs: build
Expand Down
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,12 @@ dist/
tmp/
docs/public/llm.txt
*~

**/lib/bs/
**/lib/ocaml

.DS_Store

rescript.lock

**/*.res.js
11 changes: 7 additions & 4 deletions docs/llm.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ async function getDocJson(filePath) {

async function processFile(filePath) {
const json = await getDocJson(filePath);

const moduleName = "WebAPI." + json.name.replace("-WebAPI", "");
const relativePath = path.relative(path.join(import.meta.dirname, ".."), filePath);
const parts = relativePath.split(path.sep);
const packageName = parts[1];
const leafName = path.basename(filePath, ".res");
const moduleName = leafName === "Types" ? packageName : `${packageName}.${leafName}`;

const types = [];
const functions = [];
Expand Down Expand Up @@ -89,12 +92,12 @@ async function processFile(filePath) {
functionString = "\n\nFunctions:\n\n" + functions.join("\n\n");
}

return `File: ${json.source.filepath}
return `WebApiFile: ${json.source.filepath}
Module: ${moduleName}${typeString}${functionString}
`;
}

const pattern = "../src/**/*.res";
const pattern = "../packages/*/src/**/*.res";
const files = [];
for await (const file of fs.glob(pattern, { recursive: true, cwd: import.meta.dirname })) {
files.push(path.join(import.meta.dirname, file));
Expand Down
23 changes: 13 additions & 10 deletions docs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ export function createTypeModuleLink(parentModuleLink, typeName) {
}

function mapTypeModules(parentModuleLink, file) {
const folder = file.replace(".res", "");
const folder = path.dirname(file);

if (!existsSync(folder)) {
return [];
}

const files = readdirSync(folder);
return files
.filter((f) => f.endsWith(".res"))
.filter((f) => f.endsWith(".res") && f !== "Types.res")
.map((file) => {
const filePath = path.join(folder, file);

const moduleName = file.replace("$", "").replace(folder, "").replace(".res", "");
const moduleName = file.replace("$", "").replace(".res", "");
const apiRouteParameter = toKebabCase(moduleName);
const link = createTypeModuleLink(parentModuleLink, moduleName);
const typeName = moduleName[0].toLocaleLowerCase() + moduleName.slice(1);
Expand All @@ -54,8 +54,8 @@ function mapTypeModules(parentModuleLink, file) {
}

function mapRescriptFile(srcDir, file) {
const moduleName = path.basename(file, ".res").replace("$", "");
const filePath = path.join(srcDir, file);
const moduleName = path.basename(path.dirname(srcDir)).replace("$", "");
const link = createAPIModuleLink(moduleName);
const items = Object.fromEntries(mapTypeModules(link, filePath));

Expand All @@ -68,10 +68,13 @@ function mapRescriptFile(srcDir, file) {
};
}

const srcDir = path.resolve(process.cwd(), "src");
export const apiModules = readdirSync(srcDir)
.filter((f) => f.endsWith(".res"))
.map((r) => mapRescriptFile(srcDir, r));
const packagesDir = path.resolve(process.cwd(), "packages");
export const apiModules = readdirSync(packagesDir, { withFileTypes: true })
.filter((entry) => entry.isDirectory())
.map((entry) => path.join(packagesDir, entry.name, "src"))
.filter((srcDir) => existsSync(path.join(srcDir, "Types.res")))
.map((srcDir) => mapRescriptFile(srcDir, "Types.res"))
.sort((a, b) => a.moduleName.localeCompare(b.moduleName));

async function getRescriptDoc(absoluteFilePath) {
const { stdout, stderr } = await execAsync(`rescript-tools doc ${absoluteFilePath}`, {
Expand Down Expand Up @@ -149,11 +152,11 @@ export const testFiles = readdirSync(testDir, { recursive: true })
.map((tf) => {
const sourcePath = path.join(testDir, tf);
const source = readFileSync(sourcePath, "utf-8");
const outputPath = sourcePath.replace(".res", ".js");
const outputPath = sourcePath.replace(".res", ".res.js");
const output = readFileSync(outputPath, "utf-8");

const parts = tf.split(path.sep);
const name = parts[parts.length - 1].replace("__tests.res", "");
const name = parts[parts.length - 1].replace(".res", "");

return {
sourcePath: sourcePath.replace(testDir, ""),
Expand Down
Loading