diff --git a/.github/workflows/publish-cli.yml b/.github/workflows/publish-cli.yml index 98ac1392406..773a33e9e4e 100644 --- a/.github/workflows/publish-cli.yml +++ b/.github/workflows/publish-cli.yml @@ -30,16 +30,20 @@ jobs: - name: Install uses: ./.github/actions/install + - name: Build Seed + run: | + pnpm seed:build + - name: Print version run: | git_version="$(./scripts/git-version.sh)" echo Publishing version: "${git_version}" - - name: Add version to dev package.json's + - name: Publish Dev CLI run: | + echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc git_version="$(./scripts/git-version.sh)" - - pnpm seed:local publish cli --ver ${git_version} --dev --log-level debug + pnpm seed publish cli --ver ${git_version} --dev --log-level debug # Test prod and try to publish, the publish command will handle if there's no diff live-test: @@ -84,6 +88,10 @@ jobs: - name: Install uses: ./.github/actions/install + - name: Build Seed + run: | + pnpm seed:build + - name: Publish + Register CLI env: FERN_TOKEN: ${{ secrets.FERN_TOKEN }} @@ -93,13 +101,14 @@ jobs: previous_commit="$(git rev-parse --short HEAD~1)" echo "Preview of the previous file ${previous_commit}" head tmp_cli_previous_versions.yml - + current_commit="$(git rev-parse --short HEAD)" echo "Preview of the current file ${current_commit}" head packages/cli/cli/versions.yml - pnpm seed:local publish cli --changelog packages/cli/cli/versions.yml --previous-changelog tmp_cli_previous_versions.yml --log-level debug - pnpm seed:local register cli + echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc + pnpm seed publish cli --changelog packages/cli/cli/versions.yml --previous-changelog tmp_cli_previous_versions.yml --log-level debug + pnpm seed register cli publish-manually: runs-on: ubuntu-latest @@ -118,9 +127,14 @@ jobs: - name: Install uses: ./.github/actions/install + - name: Build Seed + run: | + pnpm seed:build + - name: Publish + Register CLI env: FERN_TOKEN: ${{ secrets.FERN_TOKEN }} run: | - pnpm seed:local publish cli --ver ${{ inputs.version }} --log-level debug - pnpm seed:local register cli + echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc + pnpm seed publish cli --ver ${{ inputs.version }} --log-level debug + pnpm seed register cli diff --git a/.github/workflows/validate-changelog.yml b/.github/workflows/validate-changelog.yml index c6f20ed0d85..fecd56c86de 100644 --- a/.github/workflows/validate-changelog.yml +++ b/.github/workflows/validate-changelog.yml @@ -1,4 +1,4 @@ -name: Validate Changelogs +name: Validate Changelog on: push: @@ -13,7 +13,8 @@ concurrency: cancel-in-progress: true jobs: - cli-validate: + validate-fern-cli: + name: Fern CLI runs-on: ubuntu-latest steps: - name: Checkout repo at current ref @@ -28,7 +29,7 @@ jobs: run: | pnpm seed:local validate cli --log-level debug - generator-validate: + validate-generators: strategy: matrix: generator: [ @@ -48,7 +49,7 @@ jobs: php-sdk, php-model ] - + name: ${{ matrix.generator }} runs-on: ubuntu-latest steps: - name: Checkout repo at current ref diff --git a/generators/csharp/model/package.json b/generators/csharp/model/package.json index 129e3bcf20c..36ae6ca0d3b 100644 --- a/generators/csharp/model/package.json +++ b/generators/csharp/model/package.json @@ -14,7 +14,6 @@ "main": "lib/index.js", "types": "lib/index.d.ts", "sideEffects": false, - "bin": "./dist/cli.cjs", "scripts": { "clean": "rm -rf ./lib && tsc --build --clean", "compile": "tsc --build", diff --git a/generators/php/model/package.json b/generators/php/model/package.json index b0733e5a413..e4ee5a0c129 100644 --- a/generators/php/model/package.json +++ b/generators/php/model/package.json @@ -14,7 +14,6 @@ "main": "lib/index.js", "types": "lib/index.d.ts", "sideEffects": false, - "bin": "./dist/cli.cjs", "scripts": { "clean": "rm -rf ./lib && tsc --build --clean", "compile": "tsc --build", diff --git a/generators/php/sdk/package.json b/generators/php/sdk/package.json index 95356170b71..8324f408c21 100644 --- a/generators/php/sdk/package.json +++ b/generators/php/sdk/package.json @@ -14,7 +14,6 @@ "main": "lib/index.js", "types": "lib/index.d.ts", "sideEffects": false, - "bin": "./dist/cli.cjs", "scripts": { "clean": "rm -rf ./lib && tsc --build --clean", "compile": "tsc --build", diff --git a/generators/python-v2/codegen/src/ast/Reference.ts b/generators/python-v2/codegen/src/ast/Reference.ts index fce6b41a06f..9d63aaa8c5f 100644 --- a/generators/python-v2/codegen/src/ast/Reference.ts +++ b/generators/python-v2/codegen/src/ast/Reference.ts @@ -18,7 +18,7 @@ export declare namespace Reference { /* The alias of the reference */ alias?: string; /* The path to the attribute of the reference */ - attrPath?: AttrPath; + attribute?: AttrPath; } } @@ -27,15 +27,15 @@ export class Reference extends AstNode { private modulePath: ModulePath; private genericTypes: Type[]; private alias: string | undefined; - private attrPath: AttrPath; + private attribute: AttrPath; - constructor({ name, modulePath, genericTypes, alias, attrPath }: Reference.Args) { + constructor({ name, modulePath, genericTypes, alias, attribute }: Reference.Args) { super(); this.name = name; this.modulePath = modulePath ?? []; this.genericTypes = genericTypes ?? []; this.alias = alias; - this.attrPath = attrPath ?? []; + this.attribute = attribute ?? []; } public write(writer: Writer): void { @@ -52,9 +52,9 @@ export class Reference extends AstNode { writer.write("]"); } - if (this.attrPath.length > 0) { + if (this.attribute.length > 0) { writer.write("."); - this.attrPath.forEach((attr, index) => { + this.attribute.forEach((attr, index) => { if (index > 0) { writer.write("."); } diff --git a/generators/python-v2/codegen/src/ast/__test__/PythonFile.test.ts b/generators/python-v2/codegen/src/ast/__test__/PythonFile.test.ts index fc3413b0d18..d576d6a1eff 100644 --- a/generators/python-v2/codegen/src/ast/__test__/PythonFile.test.ts +++ b/generators/python-v2/codegen/src/ast/__test__/PythonFile.test.ts @@ -88,7 +88,7 @@ describe("PythonFile", () => { const importedRef = python.reference({ modulePath: ["external_module"], name: "ImportedClass", - attrPath: ["nested", "attribute"] + attribute: ["nested", "attribute"] }); const field = python.field({ diff --git a/generators/python-v2/codegen/src/ast/__test__/Reference.test.ts b/generators/python-v2/codegen/src/ast/__test__/Reference.test.ts index c417b634401..78835725ab1 100644 --- a/generators/python-v2/codegen/src/ast/__test__/Reference.test.ts +++ b/generators/python-v2/codegen/src/ast/__test__/Reference.test.ts @@ -146,7 +146,7 @@ describe("Reference", () => { const reference = python.reference({ name: "AttrPathClass", modulePath: ["module"], - attrPath: ["attr1", "attr2"] + attribute: ["attr1", "attr2"] }); reference.write(writer); expect(await writer.toStringFormatted()).toMatchSnapshot(); diff --git a/generators/python-v2/codegen/src/ast/__test__/Type.test.ts b/generators/python-v2/codegen/src/ast/__test__/Type.test.ts index 219aae81955..19ae3808df2 100644 --- a/generators/python-v2/codegen/src/ast/__test__/Type.test.ts +++ b/generators/python-v2/codegen/src/ast/__test__/Type.test.ts @@ -104,7 +104,7 @@ describe("Type", () => { python.reference({ name: "MyClass", modulePath: ["module"], - attrPath: ["attr1", "attr2"] + attribute: ["attr1", "attr2"] }) ); referenceType.write(writer); diff --git a/generators/ruby/model/package.json b/generators/ruby/model/package.json index acf33cca7c2..4ae8d1ccc82 100644 --- a/generators/ruby/model/package.json +++ b/generators/ruby/model/package.json @@ -14,7 +14,6 @@ "main": "lib/index.js", "types": "lib/index.d.ts", "sideEffects": false, - "bin": "./dist/cli.cjs", "scripts": { "clean": "rm -rf ./lib && tsc --build --clean", "compile": "tsc --build", diff --git a/generators/ruby/sdk/package.json b/generators/ruby/sdk/package.json index 6838e0a92ae..dfd8b300eaa 100644 --- a/generators/ruby/sdk/package.json +++ b/generators/ruby/sdk/package.json @@ -14,7 +14,6 @@ "main": "lib/index.js", "types": "lib/index.d.ts", "sideEffects": false, - "bin": "./dist/cli.cjs", "scripts": { "clean": "rm -rf ./lib && tsc --build --clean", "compile": "tsc --build", diff --git a/packages/cli/cli/build.dev.cjs b/packages/cli/cli/build.dev.cjs index 469b04bb9b5..dd3d7c3fc5c 100644 --- a/packages/cli/cli/build.dev.cjs +++ b/packages/cli/cli/build.dev.cjs @@ -23,7 +23,7 @@ async function main() { DOCS_DOMAIN_SUFFIX: "dev.docs.buildwithfern.com", DOCS_PREVIEW_BUCKET: 'https://dev2-local-preview-bundle2.s3.amazonaws.com/', CLI_NAME: "fern-dev", - CLI_VERSION: packageJson.version, + CLI_VERSION: process.argv[2] || packageJson.version, CLI_PACKAGE_NAME: "@fern-api/fern-api-dev", }, }); @@ -35,11 +35,11 @@ async function main() { "package.json", JSON.stringify( { - name: "fern-api", - version: packageJson.version, + name: "@fern-api/fern-api-dev", + version: process.argv[2] || packageJson.version, repository: packageJson.repository, - files: ["bundle.cjs", "cli.cjs"], - bin: { fern: "cli.cjs" } + files: ["cli.cjs"], + bin: { "fern-dev": "cli.cjs" } }, undefined, 2 diff --git a/packages/cli/cli/build.local.cjs b/packages/cli/cli/build.local.cjs index c3340e87551..15e680ef6ff 100644 --- a/packages/cli/cli/build.local.cjs +++ b/packages/cli/cli/build.local.cjs @@ -23,7 +23,7 @@ async function main() { DOCS_DOMAIN_SUFFIX: "dev.docs.buildwithfern.com", DOCS_PREVIEW_BUCKET: 'https://dev2-local-preview-bundle2.s3.amazonaws.com/', CLI_NAME: "fern-local", - CLI_VERSION: packageJson.version, + CLI_VERSION: process.argv[2] || packageJson.version, CLI_PACKAGE_NAME: "fern-api", }, }); @@ -36,9 +36,9 @@ async function main() { JSON.stringify( { name: "fern-api", - version: packageJson.version, + version: process.argv[2] || packageJson.version, repository: packageJson.repository, - files: ["bundle.cjs", "cli.cjs"], + files: ["cli.cjs"], bin: { fern: "cli.cjs" } }, undefined, diff --git a/packages/cli/cli/build.prod.cjs b/packages/cli/cli/build.prod.cjs index 25468aa0268..444ac35cd4a 100644 --- a/packages/cli/cli/build.prod.cjs +++ b/packages/cli/cli/build.prod.cjs @@ -23,7 +23,7 @@ async function main() { DOCS_DOMAIN_SUFFIX: "docs.buildwithfern.com", DOCS_PREVIEW_BUCKET: 'https://prod-local-preview-bundle2.s3.amazonaws.com/', CLI_NAME: "fern", - CLI_VERSION: packageJson.version, + CLI_VERSION: process.argv[2] || packageJson.version, CLI_PACKAGE_NAME: "fern-api", }, }); @@ -36,9 +36,9 @@ async function main() { JSON.stringify( { name: "fern-api", - version: packageJson.version, + version: process.argv[2] || packageJson.version, repository: packageJson.repository, - files: ["bundle.cjs", "cli.cjs"], + files: ["cli.cjs"], bin: { fern: "cli.cjs" } }, undefined, diff --git a/packages/cli/cli/package.json b/packages/cli/cli/package.json index 8dfb368da9b..d2976c4c7e3 100644 --- a/packages/cli/cli/package.json +++ b/packages/cli/cli/package.json @@ -34,8 +34,8 @@ "dist:cli:dev": "pnpm compile && node build.dev.cjs", "dist:cli:local": "pnpm compile && node build.local.cjs", "dist:cli:prod": "pnpm compile && node build.prod.cjs", - "publish:cli:dev": "pnpm dist:cli:dev && cd dist/dev && npm publish", - "publish:cli:prod": "pnpm dist:cli:prod && cd dist/prod && npm publish" + "publish:cli:dev": "cd dist/dev && npm publish", + "publish:cli:prod": "cd dist/prod && npm publish" }, "devDependencies": { "@fern-api/api-workspace-commons": "workspace:*", diff --git a/packages/cli/cli/src/cli.ts b/packages/cli/cli/src/cli.ts index fa3d9481344..ada6c64898f 100644 --- a/packages/cli/cli/src/cli.ts +++ b/packages/cli/cli/src/cli.ts @@ -1,3 +1,5 @@ +#!/usr/bin/env node + import { fernConfigJson, generatorsYml, diff --git a/packages/cli/cli/versions.yml b/packages/cli/cli/versions.yml index 3d4a641b788..a0d3e6b2415 100644 --- a/packages/cli/cli/versions.yml +++ b/packages/cli/cli/versions.yml @@ -1,3 +1,24 @@ +- changelogEntry: + - summary: | + Add `#!/usr/bin/env node` to the CLI to prevent runtime errors. + type: internal + irVersion: 53 + version: 0.45.0-rc8 + +- changelogEntry: + - summary: | + Stop minifying the CLI to prevent javascript runtime errors. + type: internal + irVersion: 53 + version: 0.45.0-rc7 + +- changelogEntry: + - summary: | + Update the CLI package.json to include the correct files. + type: fix + irVersion: 53 + version: 0.45.0-rc6 + - changelogEntry: - summary: | Introduce a new command `fern jsonschema --type ` diff --git a/packages/seed/src/utils/publishUtilities.ts b/packages/seed/src/utils/publishUtilities.ts index 6bcff67a5f0..655f683305e 100644 --- a/packages/seed/src/utils/publishUtilities.ts +++ b/packages/seed/src/utils/publishUtilities.ts @@ -1,3 +1,4 @@ +import { loggingExeca } from "@fern-api/logging-execa"; import { TaskContext } from "@fern-api/task-context"; import { runScript } from "../runScript"; @@ -8,10 +9,26 @@ export function subVersion(command: string, version: string, versionSubsitution? } export async function runCommands(commands: string[], context: TaskContext, cwd: string) { - await runScript({ - commands, - doNotPipeOutput: false, - logger: context.logger, - workingDir: cwd - }); + for (const command of commands) { + const splitCommand = command.split(" "); + if (splitCommand[0] == null) { + throw new Error(`Failed to run ${command}`); + } + const { exitCode, stdout, stderr } = await loggingExeca( + context.logger, + splitCommand[0], + splitCommand.slice(1), + { + doNotPipeOutput: true, + env: { + ...process.env + }, + cwd + } + ); + if (exitCode !== 0) { + context.logger.error(`Failed to run ${command}\n${stdout}\n${stderr}`); + throw new Error(`Failed to run ${command}`); + } + } } diff --git a/seed/fern-cli/seed.yml b/seed/fern-cli/seed.yml index b072008054b..5f015675b9a 100644 --- a/seed/fern-cli/seed.yml +++ b/seed/fern-cli/seed.yml @@ -3,35 +3,24 @@ publishGa: workingDirectory: packages/cli/cli versionSubstitution: $VERSION command: - - mv package.json package.json.tmp - - version_replace="s/0.0.0/$VERSION/" - - cat package.json.tmp| sed "${version_replace}" > package.json - echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc - pnpm install - pnpm --filter @fern-api/cli compile + - pnpm --filter @fern-api/cli dist:cli:prod $VERSION - pnpm --filter @fern-api/cli publish:cli:prod --tag latest - - mv package.json.tmp package.json publishRc: workingDirectory: packages/cli/cli versionSubstitution: $VERSION command: - - mv package.json package.json.tmp - - version_replace="s/0.0.0/$VERSION/" - - cat package.json.tmp| sed "${version_replace}" > package.json - echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc - pnpm install - pnpm --filter @fern-api/cli compile + - pnpm --filter @fern-api/cli dist:cli:prod $VERSION - pnpm --filter @fern-api/cli publish:cli:prod --tag prerelease - - mv package.json.tmp package.json publishDev: workingDirectory: packages/cli/cli versionSubstitution: $VERSION command: - - mv package.json package.json.tmp - - version_replace="s/0.0.0/$VERSION/" - - cat package.json.tmp| sed "${version_replace}" > package.json - - echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc - - pnpm install - pnpm --filter @fern-api/cli compile + - pnpm --filter @fern-api/cli dist:cli:dev $VERSION - pnpm --filter @fern-api/cli publish:cli:dev --access restricted - - mv package.json.tmp package.json