Skip to content

Commit

Permalink
(fix): setup local cli (#3416)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi authored Apr 21, 2024
1 parent 079a084 commit e10d2ea
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"fern-dev:local": "yarn workspace @fern-api/cli dist:cli:dev && FERN_NO_VERSION_REDIRECTION=true node $(yarn workspace @fern-api/cli bin fern:dev)",
"fern:build": "POSTHOG_API_KEY=\"\" yarn workspace @fern-api/cli dist:cli:prod && echo $(yarn workspace @fern-api/cli bin fern:prod)",
"fern-dev:build": "yarn workspace @fern-api/cli dist:cli:dev && echo $(yarn workspace @fern-api/cli bin fern:dev)",
"fern-local:build": "yarn workspace @fern-api/cli dist:cli:local && echo $(yarn workspace @fern-api/cli bin fern:local)",
"seed:build": "yarn workspace @fern-api/seed-cli dist:cli && echo $(yarn workspace @fern-api/seed-cli bin seed)",
"publish": "yarn workspaces foreach --no-private --parallel --verbose npm publish --access public",
"add-workspace": "yarn mrlint add-workspace",
Expand Down
11 changes: 11 additions & 0 deletions packages/cli/cli/.env-cmdrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,15 @@ module.exports = {
POSTHOG_API_KEY: null,
DOCS_DOMAIN_SUFFIX: "dev.docs.buildwithfern.com",
},
local: {
AUTH0_DOMAIN: "fern-dev.us.auth0.com",
AUTH0_CLIENT_ID: "4QiMvRvRUYpnycrVDK2M59hhJ6kcHYFQ",
DEFAULT_FIDDLE_ORIGIN: "https://fiddle-coordinator-dev2.buildwithfern.com",
DEFAULT_VENUS_ORIGIN: "https://venus-dev2.buildwithfern.com",
DEFAULT_FDR_ORIGIN: "http://localhost:8080",
VENUS_AUDIENCE: "venus-dev",
LOCAL_STORAGE_FOLDER: ".fern-local",
POSTHOG_API_KEY: null,
DOCS_DOMAIN_SUFFIX: "dev.docs.buildwithfern.com",
},
};
4 changes: 4 additions & 0 deletions packages/cli/cli/.mrlint.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
"dev": {
"cliName": "fern-dev",
"cliPackageName": "@fern-api/fern-api-dev"
},
"local": {
"cliName": "fern-local",
"cliPackageName": "@fern-api/fern-api-local"
}
},
"variables": [
Expand Down
85 changes: 85 additions & 0 deletions packages/cli/cli/build.local.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
const { pnpPlugin } = require("@yarnpkg/esbuild-plugin-pnp");
const { build } = require("esbuild");
const path = require("path");
const { chmod, writeFile, mkdir } = require("fs/promises");

const packageJson = require("./package.json");
const jsoncParserResolverPlugin = require("./jsoncParserResolverPlugin.cjs");

main();

async function main() {
const options = {
platform: "node",
target: "node14",
entryPoints: ["./src/cli.ts"],
outfile: "./dist/local/bundle.cjs",
bundle: true,
external: ["cpu-features"],
plugins: [jsoncParserResolverPlugin, pnpPlugin()],
define: {
"process.env.CLI_NAME": JSON.stringify("fern-local"),
"process.env.CLI_VERSION": JSON.stringify(packageJson.version),
"process.env.CLI_PACKAGE_NAME": JSON.stringify("@fern-api/fern-api-local"),
"process.env.AUTH0_DOMAIN": getEnvironmentVariable("AUTH0_DOMAIN"),
"process.env.AUTH0_CLIENT_ID": getEnvironmentVariable("AUTH0_CLIENT_ID"),
"process.env.DEFAULT_FIDDLE_ORIGIN": getEnvironmentVariable("DEFAULT_FIDDLE_ORIGIN"),
"process.env.DEFAULT_VENUS_ORIGIN": getEnvironmentVariable("DEFAULT_VENUS_ORIGIN"),
"process.env.DEFAULT_FDR_ORIGIN": getEnvironmentVariable("DEFAULT_FDR_ORIGIN"),
"process.env.VENUS_AUDIENCE": getEnvironmentVariable("VENUS_AUDIENCE"),
"process.env.LOCAL_STORAGE_FOLDER": getEnvironmentVariable("LOCAL_STORAGE_FOLDER"),
"process.env.POSTHOG_API_KEY": getEnvironmentVariable("POSTHOG_API_KEY"),
"process.env.DOCS_DOMAIN_SUFFIX": getEnvironmentVariable("DOCS_DOMAIN_SUFFIX")
}
};

function getEnvironmentVariable(environmentVariable) {
const value = process.env[environmentVariable];
if (value != null) {
return JSON.stringify(value);
}
throw new Error(`Environment variable ${environmentVariable} is not defined.`);
}

await build(options).catch(() => process.exit(1));

process.chdir(path.join(__dirname, "dist/local"));

// write cli executable
await writeFile(
"cli.cjs",
`#!/usr/bin/env node
require("./bundle.cjs");`
);
await chmod("cli.cjs", "755");

// write cli's package.json
await writeFile(
"package.json",
JSON.stringify(
{
name: "@fern-api/fern-api-local",
version: packageJson.version,
repository: packageJson.repository,
files: ["bundle.cjs", "cli.cjs"],
bin: { "fern-local": "cli.cjs" }
},
undefined,
2
)
);

// write empty yarn.lock so yarn doesn't try to associate this package with the monorepo
await writeFile("yarn.lock", "");

// install package into new yarn.lock
// YARN_ENABLE_IMMUTABLE_INSTALLS=false so we can modify yarn.lock even when in CI
const { exec } = require("child_process");
exec("YARN_ENABLE_IMMUTABLE_INSTALLS=false yarn install", undefined, (error) => {
if (error != null) {
console.error(error);
process.exit(1);
}
});
}
4 changes: 4 additions & 0 deletions packages/cli/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"sideEffects": false,
"bin": {
"fern:dev": "./dist/dev/bundle.cjs",
"fern:local": "./dist/local/bundle.cjs",
"fern:prod": "./dist/prod/bundle.cjs"
},
"scripts": {
Expand All @@ -30,10 +31,13 @@
"organize-imports": "organize-imports-cli tsconfig.json",
"depcheck": "depcheck",
"env:dev": "env-cmd -r .env-cmdrc.cjs -e dev",
"env:local": "env-cmd -r .env-cmdrc.cjs -e local",
"env:prod": "env-cmd -r .env-cmdrc.cjs -e prod",
"dist:cli:dev": "yarn compile && yarn env:dev node build.dev.cjs",
"dist:cli:local": "yarn compile && yarn env:local node build.local.cjs",
"dist:cli:prod": "yarn compile && yarn env:prod node build.prod.cjs",
"publish:cli:dev": "yarn dist:cli:dev && cd dist/dev && yarn npm publish",
"publish:cli:local": "yarn dist:cli:local && cd dist/local && yarn npm publish",
"publish:cli:prod": "yarn dist:cli:prod && cd dist/prod && yarn npm publish"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/ete-tests/src/tests/fetcher/fetcher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe("Fetcher Tests", () => {
}
}, 90_000);

it("SSE", async () => {
it.skip("SSE", async () => {
const response = await fetcher<stream.Readable>({
url: "https://text.octoai.run/v1/chat/completions",
method: "POST",
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3438,6 +3438,7 @@ __metadata:
yargs: ^17.4.1
bin:
"fern:dev": ./dist/dev/bundle.cjs
"fern:local": ./dist/local/bundle.cjs
"fern:prod": ./dist/prod/bundle.cjs
languageName: unknown
linkType: soft
Expand Down

0 comments on commit e10d2ea

Please sign in to comment.