build system

This commit is contained in:
Niccolo Borgioli 2023-05-12 20:22:39 +02:00
parent 88e502562a
commit 3af5d0ef1a
No known key found for this signature in database
GPG Key ID: D93C615F75EE4F0B
4 changed files with 27 additions and 4 deletions

View File

@ -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"
},

17
packages/cli/scripts/build.js Executable file
View File

@ -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)

View File

@ -1,3 +1,5 @@
#!/usr/bin/env node
import { exec } from 'pkg'
const targets = [

View File

@ -21,6 +21,9 @@ const minutes = new Option('-m --minutes <number>', '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')