diff --git a/packages/cli/package.json b/packages/cli/package.json index 469f55e..60e20d6 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -6,12 +6,13 @@ "node": ">=18" }, "scripts": { - "dev": "esbuild ./src/index.ts --bundle --platform=node --outfile=dist/index.cjs --watch", - "build": "rm -rf ./dist && tsc && esbuild ./src/index.ts --bundle --platform=node --outfile=dist/index.cjs", - "package": "node ./build.js", + "dev": "./scripts/build.js --watch", + "build": "./scripts/build.js", + "package": "./scripts/package.js", "bin": "run-s build package", "prepublishOnly": "run-s build" }, + "main": "./dist/index.cjs", "bin": { "cryptgeon": "./dist/index.cjs" }, diff --git a/packages/cli/scripts/build.js b/packages/cli/scripts/build.js new file mode 100755 index 0000000..2626f51 --- /dev/null +++ b/packages/cli/scripts/build.js @@ -0,0 +1,17 @@ +#!/usr/bin/env node + +import { build, context } from 'esbuild' +import pkg from '../package.json' assert { type: 'json' } + +const options = { + entryPoints: ['./src/index.ts'], + bundle: true, + minify: true, + platform: 'node', + outfile: './dist/index.cjs', + define: { VERSION: `"${pkg.version}"` }, +} + +const watch = process.argv.slice(2)[0] === '--watch' +if (watch) (await context(options)).watch() +else await build(options) diff --git a/packages/cli/build.js b/packages/cli/scripts/package.js old mode 100644 new mode 100755 similarity index 94% rename from packages/cli/build.js rename to packages/cli/scripts/package.js index 9ddac52..658f81c --- a/packages/cli/build.js +++ b/packages/cli/scripts/package.js @@ -1,3 +1,5 @@ +#!/usr/bin/env node + import { exec } from 'pkg' const targets = [ diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index a49a8a6..19356fe 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -21,6 +21,9 @@ const minutes = new Option('-m --minutes ', 'Minutes before the note exp // Node 18 guard parseInt(process.version.slice(1).split(',')[0]) < 18 && exit('Node 18 or higher is required') +// @ts-ignore +const version: string = VERSION + async function checkConstrains(constrains: { views?: number; minutes?: number }) { const { views, minutes } = constrains if (views && minutes) exit('cannot set view and minutes constrains simultaneously') @@ -33,7 +36,7 @@ async function checkConstrains(constrains: { views?: number; minutes?: number }) exit(`Only a maximum of ${response.max_expiration} minutes allowed. ${minutes} given.`) } -program.name('cryptgeon').version('1.0.0').configureHelp({ showGlobalOptions: true }) +program.name('cryptgeon').version(version).configureHelp({ showGlobalOptions: true }) program .command('info')