@@ -5,6 +5,7 @@ import { parseArgs } from 'node:util'
55
66import { context } from 'esbuild'
77
8+ import { generateLicense } from './license.js'
89import { esbuildProblemMatcherPlugin } from './plugins.js'
910
1011import type { PackageJson } from 'type-fest'
@@ -24,6 +25,11 @@ const optionsDef = {
2425 production : {
2526 type : 'boolean' ,
2627 } ,
28+ onlyLicense : {
29+ type : 'boolean' ,
30+ short : 'l' ,
31+ default : false ,
32+ } ,
2733} as const
2834
2935const { values : options } = parseArgs ( { args, options : optionsDef } )
@@ -41,6 +47,18 @@ if (!fss.existsSync(pkgPath)) {
4147const pkg = ( await import ( url . pathToFileURL ( pkgPath ) . href , { with : { type : 'json' } } ) ) . default
4248
4349const absWorkingDir = path . dirname ( pkgPath )
50+ const outdir = path . resolve ( absWorkingDir , 'dist' )
51+
52+ if ( options . onlyLicense ) {
53+ const metafile = path . join ( outdir , 'meta.json' )
54+ if ( ! fss . existsSync ( metafile ) ) {
55+ throw new Error ( `Meta file was not found: ${ metafile } \nPlease execute \`pnpm run build\` at root directory.` )
56+ }
57+ const meta = JSON . parse ( fss . readFileSync ( metafile , { encoding : 'utf-8' } ) )
58+ generateLicense ( rootDir , pkgPath , meta )
59+ console . log ( 'The license file was generated successfully.' )
60+ process . exit ( 0 )
61+ }
4462
4563const exports = ( pkg . exports || { } ) as PackageJson . ExportConditions
4664
@@ -60,8 +78,6 @@ if (entryPoints.length < 1) {
6078 throw new Error ( `No export module found to build at: ${ absWorkingDir } ` )
6179}
6280
63- const outdir = path . resolve ( absWorkingDir , 'dist' )
64-
6581const ctx = await context ( {
6682 sourceRoot : absWorkingDir ,
6783 entryPoints,
@@ -89,5 +105,7 @@ if (options.watch) {
89105
90106 if ( ! options . production ) {
91107 fss . writeFileSync ( path . join ( outdir , 'meta.json' ) , JSON . stringify ( result . metafile ) )
108+
109+ generateLicense ( rootDir , pkgPath , result . metafile )
92110 }
93111}
0 commit comments