diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..035c5be --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,83 @@ +name: Publish + +on: + workflow_dispatch: + push: + branches: + - "main" + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.sha }}-${{ github.event_name }} + cancel-in-progress: true + +defaults: + run: + shell: bash + working-directory: ./ + +jobs: + run_publish: + runs-on: ubuntu-latest + name: Publish package to NPM + steps: + - name: "Fetch current Git commit history" + uses: actions/checkout@v4 + with: + fetch-depth: 2 + + - name: Setup turbo caches + uses: actions/cache@v4 + with: + path: | + ./.turbo/ + !./.turbo/runs/ + key: ${{ runner.os }}-turbo-${{ github.workflow }}-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-turbo-${{ github.workflow }}- + ${{ runner.os }}-turbo- + save-always: true + + - name: Setup PNPM + uses: pnpm/action-setup@v4 + with: + package_json_file: package.json + + - name: Setup Node.js environment + uses: actions/setup-node@v4 + with: + node-version-file: package.json + cache: pnpm + cache-dependency-path: pnpm-lock.yaml + + - name: Install dependencies + run: pnpm install --frozen-lockfile + + - name: Build package + run: pnpm run build + + - name: Publish package + run: | + cd dist + + CURRENT_VERSION=$(grep --only-matching --perl-regexp '"version":\s*"\K[^"]+' package.json) + TARGET_VERSION="$CURRENT_VERSION-sha.${{github.sha}}" + + if pnpm view @sibe-io/mesh-file-postprocessor@"${TARGET_VERSION}" > /dev/null 2>&1; then + echo "Version already exists. Skipping publish." + else + cd bundle + + pnpm version ${TARGET_VERSION} + pnpm config set //registry.npmjs.org/:_authToken ${NODE_AUTH_TOKEN} + pnpm publish --access public --no-git-checks + fi + env: + NODE_AUTH_TOKEN: ${{ secrets.NODE_AUTH_TOKEN }} + + - name: Save turbo logs + uses: actions/upload-artifact@v4 + with: + name: turbo-run-logs + path: ./.turbo/runs/ + if-no-files-found: warn + retention-days: 1 diff --git a/README.md b/README.md index 3f87a3f..70b6b91 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,5 @@

--- + +> Work in progress. Not for production usage until 1.0.0. diff --git a/dist/build.script.ts b/dist/build.script.ts index d27a6e8..deb1940 100644 --- a/dist/build.script.ts +++ b/dist/build.script.ts @@ -1,59 +1,90 @@ -import { PackageJSON } from '@npm/types'; -import { build } from 'esbuild'; -import { access, copyFile, readFile, rm, writeFile } from 'fs/promises'; -import { resolve } from 'path'; +import { PackageJSON } from "@npm/types"; +import { build } from "esbuild"; +import { access, copyFile, readFile, rm, writeFile } from "fs/promises"; +import { resolve } from "path"; -const DEFAULT_CHARSET: 'utf8' = 'utf8'; +const DEFAULT_CHARSET: "utf8" = "utf8"; -const RESULT_BUNDLE_PATH: string = resolve(__dirname, 'bundle'); +const RESULT_BUNDLE_PATH: string = resolve(__dirname, "bundle"); -const ENTRY_POINT_FILE_NAME: string = 'index'; -const ENTRY_POINT_PATH: string = resolve(__dirname, 'src', `${ENTRY_POINT_FILE_NAME}.ts`); +const ENTRY_POINT_FILE_NAME: string = "index"; +const ENTRY_POINT_PATH: string = resolve( + __dirname, + "src", + `${ENTRY_POINT_FILE_NAME}.ts` +); -const TYPINGS_ENTRY_POINT_PATH: string = resolve(__dirname, 'tsc-out', 'bundle.d.ts'); -const RESULT_BUNDLE_TYPINGS_PATH: string = resolve(RESULT_BUNDLE_PATH, `${ENTRY_POINT_FILE_NAME}.d.ts`); +const TYPINGS_ENTRY_POINT_PATH: string = resolve( + __dirname, + "tsc-out", + "bundle.d.ts" +); +const RESULT_BUNDLE_TYPINGS_PATH: string = resolve( + RESULT_BUNDLE_PATH, + `${ENTRY_POINT_FILE_NAME}.d.ts` +); -const BUILD_TS_CONFIG_PATH: string = resolve(__dirname, 'tsconfig.build.json'); +const BUILD_TS_CONFIG_PATH: string = resolve(__dirname, "tsconfig.build.json"); -const PACKAGE_MANIFEST_FILE_NAME: string = 'package.json'; -const PACKAGE_MANIFEST_SOURCE_FILE_PATH: string = resolve(__dirname, PACKAGE_MANIFEST_FILE_NAME); -const PACKAGE_MANIFEST_BUNDLE_FILE_PATH: string = resolve(RESULT_BUNDLE_PATH, PACKAGE_MANIFEST_FILE_NAME); +const PACKAGE_MANIFEST_FILE_NAME: string = "package.json"; +const PACKAGE_MANIFEST_SOURCE_FILE_PATH: string = resolve( + __dirname, + PACKAGE_MANIFEST_FILE_NAME +); +const PACKAGE_MANIFEST_BUNDLE_FILE_PATH: string = resolve( + RESULT_BUNDLE_PATH, + PACKAGE_MANIFEST_FILE_NAME +); + +const README_FILE_NAME: string = "README.md"; +const README_SOURCE_FILE_PATH: string = resolve( + __dirname, + "..", + README_FILE_NAME +); +const README_BUNDLE_FILE_PATH: string = resolve( + RESULT_BUNDLE_PATH, + README_FILE_NAME +); (async () => { await rm(RESULT_BUNDLE_PATH, { recursive: true, force: true }); - new Set([ENTRY_POINT_PATH, BUILD_TS_CONFIG_PATH, PACKAGE_MANIFEST_SOURCE_FILE_PATH]).forEach( - async (entryPointPath: string) => { - await access(entryPointPath); - } - ); + new Set([ + ENTRY_POINT_PATH, + BUILD_TS_CONFIG_PATH, + PACKAGE_MANIFEST_SOURCE_FILE_PATH, + README_SOURCE_FILE_PATH, + ]).forEach(async (entryPointPath: string) => { + await access(entryPointPath); + }); await build({ entryPoints: [ENTRY_POINT_PATH], outdir: RESULT_BUNDLE_PATH, - platform: 'browser', + platform: "browser", tsconfig: BUILD_TS_CONFIG_PATH, bundle: true, minify: true, splitting: true, - format: 'esm', + format: "esm", treeShaking: true, charset: DEFAULT_CHARSET, - legalComments: 'external' + legalComments: "external", }); const { name, version }: PackageJSON = JSON.parse( await readFile(PACKAGE_MANIFEST_SOURCE_FILE_PATH, { - encoding: DEFAULT_CHARSET + encoding: DEFAULT_CHARSET, }) ); if (name === undefined) { - throw new Error('Package name is not defined'); + throw new Error("Package name is not defined"); } if (version === undefined) { - throw new Error('Package version is not defined'); + throw new Error("Package version is not defined"); } const bundlePackageJsonContent: PackageJSON = { @@ -62,20 +93,26 @@ const PACKAGE_MANIFEST_BUNDLE_FILE_PATH: string = resolve(RESULT_BUNDLE_PATH, PA browser: `./${ENTRY_POINT_FILE_NAME}.js`, types: `./${ENTRY_POINT_FILE_NAME}.d.ts`, repository: { - type: 'git', - url: 'git+https://github.com/ScarletFlash/consy.git' + type: "git", + url: "git+https://github.com/ScarletFlash/consy.git", }, author: { - email: 'scarletflash.dev@gmail.com', - name: 'Fedor Usakov', - url: 'https://scarletflash.github.io/' + email: "scarletflash.dev@gmail.com", + name: "Fedor Usakov", + url: "https://scarletflash.github.io/", }, - license: 'MIT' + license: "MIT", }; - await writeFile(PACKAGE_MANIFEST_BUNDLE_FILE_PATH, JSON.stringify(bundlePackageJsonContent), { - encoding: DEFAULT_CHARSET - }); + await writeFile( + PACKAGE_MANIFEST_BUNDLE_FILE_PATH, + JSON.stringify(bundlePackageJsonContent), + { + encoding: DEFAULT_CHARSET, + } + ); await copyFile(TYPINGS_ENTRY_POINT_PATH, RESULT_BUNDLE_TYPINGS_PATH); + + await copyFile(README_SOURCE_FILE_PATH, README_BUNDLE_FILE_PATH); })();