@gjsify/cli 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/actions/build.js +5 -1
- package/lib/commands/build.js +15 -0
- package/lib/config.d.ts +1 -1
- package/lib/config.js +4 -4
- package/lib/types/cli-build-options.d.ts +10 -0
- package/package.json +4 -4
- package/src/actions/build.ts +7 -3
- package/src/commands/build.ts +15 -0
- package/src/config.ts +4 -4
- package/src/lodash.d.ts +46 -0
- package/src/types/cli-build-options.ts +10 -0
- package/tsconfig.json +1 -0
package/lib/actions/build.js
CHANGED
|
@@ -65,8 +65,12 @@ export class BuildAction {
|
|
|
65
65
|
}
|
|
66
66
|
/** Application mode */
|
|
67
67
|
async buildApp(app = 'gjs') {
|
|
68
|
-
const { verbose, esbuild, typescript, exclude } = this.configData;
|
|
68
|
+
const { verbose, esbuild, typescript, exclude, library: pgk } = this.configData;
|
|
69
69
|
const format = esbuild?.format || esbuild?.outfile?.endsWith('.cjs') ? 'cjs' : 'esm';
|
|
70
|
+
// Set default outfile if no outdir is set
|
|
71
|
+
if (esbuild && !esbuild?.outfile && !esbuild?.outdir && (pgk?.main || pgk?.module)) {
|
|
72
|
+
esbuild.outfile = esbuild?.format === 'cjs' ? pgk.main || pgk.module : pgk.module || pgk.main;
|
|
73
|
+
}
|
|
70
74
|
const result = await build({
|
|
71
75
|
...this.getEsBuildDefaults(),
|
|
72
76
|
...esbuild,
|
package/lib/commands/build.js
CHANGED
|
@@ -35,6 +35,18 @@ export const buildCommand = {
|
|
|
35
35
|
choices: ['gjs', 'node', 'deno', 'browser'],
|
|
36
36
|
normalize: true,
|
|
37
37
|
default: 'gjs'
|
|
38
|
+
})
|
|
39
|
+
.option('format', {
|
|
40
|
+
description: "Override the default output format",
|
|
41
|
+
type: 'string',
|
|
42
|
+
choices: ['iife', 'esm', 'cjs'],
|
|
43
|
+
normalize: true,
|
|
44
|
+
})
|
|
45
|
+
.option('minify', {
|
|
46
|
+
description: "When enabled, the generated code will be minified instead of pretty-printed",
|
|
47
|
+
type: 'boolean',
|
|
48
|
+
normalize: true,
|
|
49
|
+
default: false
|
|
38
50
|
})
|
|
39
51
|
.option('library', {
|
|
40
52
|
description: "Use this if you want to build a library for Gjsify",
|
|
@@ -43,16 +55,19 @@ export const buildCommand = {
|
|
|
43
55
|
default: false
|
|
44
56
|
})
|
|
45
57
|
.option('outfile', {
|
|
58
|
+
alias: 'o',
|
|
46
59
|
description: "Sets the output file name for the build operation. If no outfile is specified, the outfile will be parsed from the package.json. Only used if application mode is active",
|
|
47
60
|
type: 'string',
|
|
48
61
|
normalize: true,
|
|
49
62
|
})
|
|
50
63
|
.option('outdir', {
|
|
64
|
+
alias: 'd',
|
|
51
65
|
description: "Sets the output directory for the build operation. If no outdir is specified, the outdir will be parsed from the package.json. Only used if library mode is active",
|
|
52
66
|
type: 'string',
|
|
53
67
|
normalize: true,
|
|
54
68
|
})
|
|
55
69
|
.option('reflection', {
|
|
70
|
+
alias: 'r',
|
|
56
71
|
description: "Enables TypeScript types on runtime using Deepkit's type compiler",
|
|
57
72
|
type: 'boolean',
|
|
58
73
|
normalize: true,
|
package/lib/config.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { ArgumentsCamelCase } from 'yargs';
|
|
|
4
4
|
export declare class Config {
|
|
5
5
|
readonly loadOptions: LoadOptions;
|
|
6
6
|
constructor(loadOptions?: LoadOptions);
|
|
7
|
-
/** Loads gjsify config file, e.g
|
|
7
|
+
/** Loads gjsify config file, e.g `.gjsifyrc.js` */
|
|
8
8
|
private load;
|
|
9
9
|
/** Loads package.json of the current project */
|
|
10
10
|
private readPackageJSON;
|
package/lib/config.js
CHANGED
|
@@ -5,15 +5,13 @@ import { getTsconfig } from 'get-tsconfig';
|
|
|
5
5
|
import lodash from "lodash";
|
|
6
6
|
const { merge } = lodash;
|
|
7
7
|
export class Config {
|
|
8
|
-
loadOptions = {
|
|
9
|
-
searchPlaces: [APP_NAME]
|
|
10
|
-
};
|
|
8
|
+
loadOptions = {};
|
|
11
9
|
constructor(loadOptions = {}) {
|
|
12
10
|
if (Object.keys(loadOptions).length) {
|
|
13
11
|
this.loadOptions = loadOptions;
|
|
14
12
|
}
|
|
15
13
|
}
|
|
16
|
-
/** Loads gjsify config file, e.g
|
|
14
|
+
/** Loads gjsify config file, e.g `.gjsifyrc.js` */
|
|
17
15
|
async load(searchFrom) {
|
|
18
16
|
let configFile = await cosmiconfig(APP_NAME, this.loadOptions).search(searchFrom);
|
|
19
17
|
configFile ||= {
|
|
@@ -51,6 +49,8 @@ export class Config {
|
|
|
51
49
|
merge(configData.library, pkg, configData.library);
|
|
52
50
|
merge(configData.typescript, tsConfig, configData.typescript);
|
|
53
51
|
merge(configData.esbuild, {
|
|
52
|
+
format: cliArgs.format,
|
|
53
|
+
minify: cliArgs.minify,
|
|
54
54
|
entryPoints: cliArgs.entryPoints,
|
|
55
55
|
outfile: cliArgs.outfile,
|
|
56
56
|
outdir: cliArgs.outdir,
|
|
@@ -7,6 +7,16 @@ export interface CliBuildOptions {
|
|
|
7
7
|
entryPoints?: string[];
|
|
8
8
|
/** Switch on the verbose mode */
|
|
9
9
|
verbose?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* When enabled, the generated code will be minified instead of pretty-printed.
|
|
12
|
+
* @see https://esbuild.github.io/api/#minify
|
|
13
|
+
*/
|
|
14
|
+
minify?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Override the default output format.
|
|
17
|
+
* @see https://esbuild.github.io/api/#format
|
|
18
|
+
*/
|
|
19
|
+
format?: 'iife' | 'esm' | 'cjs';
|
|
10
20
|
/** Use this if you want to build a application or test, the platforms node and deno are usually only used internally to build the tests for Gjsify */
|
|
11
21
|
app?: App;
|
|
12
22
|
/** Use this if you want to build a library for Gjsify */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/cli",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "CLI for Gjsify",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -23,10 +23,10 @@
|
|
|
23
23
|
"cli"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@gjsify/esbuild-plugin-deepkit": "^0.0.
|
|
27
|
-
"@gjsify/esbuild-plugin-gjsify": "^0.0.
|
|
26
|
+
"@gjsify/esbuild-plugin-deepkit": "^0.0.3",
|
|
27
|
+
"@gjsify/esbuild-plugin-gjsify": "^0.0.3",
|
|
28
28
|
"cosmiconfig": "^8.2.0",
|
|
29
|
-
"esbuild": "^0.18.
|
|
29
|
+
"esbuild": "^0.18.3",
|
|
30
30
|
"get-tsconfig": "^4.6.0",
|
|
31
31
|
"lodash": "^4.17.21",
|
|
32
32
|
"pkg-types": "^1.0.3",
|
package/src/actions/build.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { ConfigData } from '../types/index.js';
|
|
2
2
|
import type { App } from '@gjsify/esbuild-plugin-gjsify';
|
|
3
|
-
import { build,
|
|
3
|
+
import { build, BuildOptions, BuildResult } from 'esbuild';
|
|
4
4
|
import { gjsifyPlugin } from '@gjsify/esbuild-plugin-gjsify';
|
|
5
5
|
import { dirname, extname } from 'path';
|
|
6
|
-
import { writeFile } from 'fs/promises';
|
|
7
6
|
|
|
8
7
|
export class BuildAction {
|
|
9
8
|
constructor(readonly configData: ConfigData = {}) {
|
|
@@ -78,10 +77,15 @@ export class BuildAction {
|
|
|
78
77
|
/** Application mode */
|
|
79
78
|
async buildApp(app: App = 'gjs') {
|
|
80
79
|
|
|
81
|
-
const { verbose, esbuild, typescript, exclude } = this.configData;
|
|
80
|
+
const { verbose, esbuild, typescript, exclude, library: pgk } = this.configData;
|
|
82
81
|
|
|
83
82
|
const format: 'cjs' | 'esm' = esbuild?.format || esbuild?.outfile?.endsWith('.cjs') ? 'cjs' : 'esm';
|
|
84
83
|
|
|
84
|
+
// Set default outfile if no outdir is set
|
|
85
|
+
if(esbuild && !esbuild?.outfile && !esbuild?.outdir && (pgk?.main || pgk?.module)) {
|
|
86
|
+
esbuild.outfile = esbuild?.format === 'cjs' ? pgk.main || pgk.module : pgk.module || pgk.main;
|
|
87
|
+
}
|
|
88
|
+
|
|
85
89
|
const result = await build({
|
|
86
90
|
...this.getEsBuildDefaults(),
|
|
87
91
|
...esbuild,
|
package/src/commands/build.ts
CHANGED
|
@@ -38,6 +38,18 @@ export const buildCommand: Command<any, CliBuildOptions> = {
|
|
|
38
38
|
normalize: true,
|
|
39
39
|
default: 'gjs'
|
|
40
40
|
})
|
|
41
|
+
.option('format', {
|
|
42
|
+
description: "Override the default output format",
|
|
43
|
+
type: 'string',
|
|
44
|
+
choices: ['iife', 'esm', 'cjs'],
|
|
45
|
+
normalize: true,
|
|
46
|
+
})
|
|
47
|
+
.option('minify', {
|
|
48
|
+
description: "When enabled, the generated code will be minified instead of pretty-printed",
|
|
49
|
+
type: 'boolean',
|
|
50
|
+
normalize: true,
|
|
51
|
+
default: false
|
|
52
|
+
})
|
|
41
53
|
.option('library', {
|
|
42
54
|
description: "Use this if you want to build a library for Gjsify",
|
|
43
55
|
type: 'boolean',
|
|
@@ -45,16 +57,19 @@ export const buildCommand: Command<any, CliBuildOptions> = {
|
|
|
45
57
|
default: false
|
|
46
58
|
})
|
|
47
59
|
.option('outfile', {
|
|
60
|
+
alias: 'o',
|
|
48
61
|
description: "Sets the output file name for the build operation. If no outfile is specified, the outfile will be parsed from the package.json. Only used if application mode is active",
|
|
49
62
|
type: 'string',
|
|
50
63
|
normalize: true,
|
|
51
64
|
})
|
|
52
65
|
.option('outdir', {
|
|
66
|
+
alias: 'd',
|
|
53
67
|
description: "Sets the output directory for the build operation. If no outdir is specified, the outdir will be parsed from the package.json. Only used if library mode is active",
|
|
54
68
|
type: 'string',
|
|
55
69
|
normalize: true,
|
|
56
70
|
})
|
|
57
71
|
.option('reflection', {
|
|
72
|
+
alias: 'r',
|
|
58
73
|
description: "Enables TypeScript types on runtime using Deepkit's type compiler",
|
|
59
74
|
type: 'boolean',
|
|
60
75
|
normalize: true,
|
package/src/config.ts
CHANGED
|
@@ -10,9 +10,7 @@ import type { ArgumentsCamelCase } from 'yargs';
|
|
|
10
10
|
|
|
11
11
|
export class Config {
|
|
12
12
|
|
|
13
|
-
readonly loadOptions: LoadOptions = {
|
|
14
|
-
searchPlaces: [APP_NAME]
|
|
15
|
-
}
|
|
13
|
+
readonly loadOptions: LoadOptions = {}
|
|
16
14
|
|
|
17
15
|
constructor(loadOptions: LoadOptions = {}) {
|
|
18
16
|
if(Object.keys(loadOptions).length) {
|
|
@@ -20,7 +18,7 @@ export class Config {
|
|
|
20
18
|
}
|
|
21
19
|
}
|
|
22
20
|
|
|
23
|
-
/** Loads gjsify config file, e.g
|
|
21
|
+
/** Loads gjsify config file, e.g `.gjsifyrc.js` */
|
|
24
22
|
private async load(searchFrom?: string) {
|
|
25
23
|
let configFile = await cosmiconfig(APP_NAME, this.loadOptions).search(searchFrom) as CosmiconfigResult<ConfigData> | null;
|
|
26
24
|
|
|
@@ -66,6 +64,8 @@ export class Config {
|
|
|
66
64
|
merge(configData.library, pkg, configData.library);
|
|
67
65
|
merge(configData.typescript, tsConfig, configData.typescript);
|
|
68
66
|
merge(configData.esbuild, {
|
|
67
|
+
format: cliArgs.format,
|
|
68
|
+
minify: cliArgs.minify,
|
|
69
69
|
entryPoints: cliArgs.entryPoints,
|
|
70
70
|
outfile: cliArgs.outfile,
|
|
71
71
|
outdir: cliArgs.outdir,
|
package/src/lodash.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
declare module 'lodash' {
|
|
2
|
+
/**
|
|
3
|
+
* Recursively merges own and inherited enumerable properties of source
|
|
4
|
+
* objects into the destination object, skipping source properties that resolve
|
|
5
|
+
* to `undefined`. Array and plain object properties are merged recursively.
|
|
6
|
+
* Other objects and value types are overridden by assignment. Source objects
|
|
7
|
+
* are applied from left to right. Subsequent sources overwrite property
|
|
8
|
+
* assignments of previous sources.
|
|
9
|
+
*
|
|
10
|
+
* **Note:** This method mutates `object`.
|
|
11
|
+
*
|
|
12
|
+
* @category Object
|
|
13
|
+
* @param object The destination object.
|
|
14
|
+
* @param [sources] The source objects.
|
|
15
|
+
* @returns Returns `object`.
|
|
16
|
+
* @example
|
|
17
|
+
*
|
|
18
|
+
* var users = {
|
|
19
|
+
* 'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
|
|
20
|
+
* };
|
|
21
|
+
*
|
|
22
|
+
* var ages = {
|
|
23
|
+
* 'data': [{ 'age': 36 }, { 'age': 40 }]
|
|
24
|
+
* };
|
|
25
|
+
*
|
|
26
|
+
* _.merge(users, ages);
|
|
27
|
+
* // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
|
|
28
|
+
*/
|
|
29
|
+
function merge<TObject, TSource>(object: TObject, source: TSource): TObject & TSource;
|
|
30
|
+
/**
|
|
31
|
+
* @see _.merge
|
|
32
|
+
*/
|
|
33
|
+
function merge<TObject, TSource1, TSource2>(object: TObject, source1: TSource1, source2: TSource2): TObject & TSource1 & TSource2;
|
|
34
|
+
/**
|
|
35
|
+
* @see _.merge
|
|
36
|
+
*/
|
|
37
|
+
function merge<TObject, TSource1, TSource2, TSource3>(object: TObject, source1: TSource1, source2: TSource2, source3: TSource3): TObject & TSource1 & TSource2 & TSource3;
|
|
38
|
+
/**
|
|
39
|
+
* @see _.merge
|
|
40
|
+
*/
|
|
41
|
+
function merge<TObject, TSource1, TSource2, TSource3, TSource4>(object: TObject, source1: TSource1, source2: TSource2, source3: TSource3, source4: TSource4): TObject & TSource1 & TSource2 & TSource3 & TSource4;
|
|
42
|
+
/**
|
|
43
|
+
* @see _.merge
|
|
44
|
+
*/
|
|
45
|
+
function merge(object: any, ...otherArgs: any[]): any;
|
|
46
|
+
}
|
|
@@ -8,6 +8,16 @@ export interface CliBuildOptions {
|
|
|
8
8
|
entryPoints?: string[];
|
|
9
9
|
/** Switch on the verbose mode */
|
|
10
10
|
verbose?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* When enabled, the generated code will be minified instead of pretty-printed.
|
|
13
|
+
* @see https://esbuild.github.io/api/#minify
|
|
14
|
+
*/
|
|
15
|
+
minify?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Override the default output format.
|
|
18
|
+
* @see https://esbuild.github.io/api/#format
|
|
19
|
+
*/
|
|
20
|
+
format?: 'iife' | 'esm' | 'cjs';
|
|
11
21
|
/** Use this if you want to build a application or test, the platforms node and deno are usually only used internally to build the tests for Gjsify */
|
|
12
22
|
app?: App;
|
|
13
23
|
/** Use this if you want to build a library for Gjsify */
|