@gjsify/cli 0.0.1 → 0.0.2
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.d.ts +110 -6
- package/lib/actions/build.js +94 -21
- package/lib/commands/build.d.ts +2 -16
- package/lib/commands/build.js +75 -57
- package/lib/commands/index.d.ts +1 -0
- package/lib/commands/index.js +1 -0
- package/lib/config.d.ts +14 -0
- package/lib/config.js +63 -0
- package/lib/constants.d.ts +1 -0
- package/lib/constants.js +1 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.js +12 -6
- package/lib/types/cli-build-options.d.ts +35 -0
- package/lib/types/cli-build-options.js +1 -0
- package/lib/types/command.d.ts +9 -0
- package/lib/types/command.js +1 -0
- package/lib/types/config-data-library.d.ts +3 -0
- package/lib/types/config-data-library.js +1 -0
- package/lib/types/config-data-typescript.d.ts +5 -0
- package/lib/types/config-data-typescript.js +1 -0
- package/lib/types/config-data.d.ts +11 -0
- package/lib/types/config-data.js +1 -0
- package/lib/types/cosmiconfig-result.d.ts +5 -0
- package/lib/types/cosmiconfig-result.js +1 -0
- package/lib/types/index.d.ts +6 -1
- package/lib/types/index.js +6 -2
- package/package.json +31 -75
- package/src/actions/build.ts +117 -0
- package/src/actions/index.ts +1 -0
- package/src/commands/build.ts +80 -0
- package/src/commands/index.ts +1 -0
- package/src/config.ts +80 -0
- package/src/constants.ts +1 -0
- package/src/index.ts +14 -0
- package/src/types/cli-build-options.ts +36 -0
- package/src/types/command.ts +10 -0
- package/src/types/config-data-library.ts +5 -0
- package/src/types/config-data-typescript.ts +6 -0
- package/src/types/config-data.ts +12 -0
- package/src/types/cosmiconfig-result.ts +5 -0
- package/src/types/index.ts +6 -0
- package/tsconfig.json +12 -0
- package/LICENSE +0 -21
- package/README.md +0 -78
- package/bin/run +0 -5
- package/bin/run.cmd +0 -3
- package/lib/actions/init.d.ts +0 -0
- package/lib/actions/init.js +0 -6
- package/lib/defaults.d.ts +0 -6
- package/lib/defaults.js +0 -8
- package/lib/types/build-options.d.ts +0 -9
- package/lib/types/build-options.js +0 -2
- package/lib/webpack.config.default.d.ts +0 -47
- package/lib/webpack.config.default.js +0 -71
- package/oclif.manifest.json +0 -1
package/lib/actions/build.d.ts
CHANGED
|
@@ -1,8 +1,112 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import type { ConfigData } from '../types/index.js';
|
|
2
|
+
import type { App } from '@gjsify/esbuild-plugin-gjsify';
|
|
3
|
+
import { BuildOptions, BuildResult } from 'esbuild';
|
|
3
4
|
export declare class BuildAction {
|
|
4
|
-
|
|
5
|
-
constructor(
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
readonly configData: ConfigData;
|
|
6
|
+
constructor(configData?: ConfigData);
|
|
7
|
+
getEsBuildDefaults(): BuildOptions;
|
|
8
|
+
/** Library mode */
|
|
9
|
+
buildLibrary(): Promise<BuildResult<BuildOptions>[]>;
|
|
10
|
+
/** Application mode */
|
|
11
|
+
buildApp(app?: App): Promise<BuildResult<{
|
|
12
|
+
format: "cjs" | "esm";
|
|
13
|
+
plugins: import("esbuild").Plugin[];
|
|
14
|
+
bundle?: boolean | undefined;
|
|
15
|
+
splitting?: boolean | undefined;
|
|
16
|
+
preserveSymlinks?: boolean | undefined;
|
|
17
|
+
outfile?: string | undefined;
|
|
18
|
+
metafile?: boolean | undefined;
|
|
19
|
+
outdir?: string | undefined;
|
|
20
|
+
outbase?: string | undefined;
|
|
21
|
+
external?: string[] | undefined;
|
|
22
|
+
packages?: "external" | undefined;
|
|
23
|
+
alias?: Record<string, string> | undefined;
|
|
24
|
+
loader?: {
|
|
25
|
+
[ext: string]: import("esbuild").Loader;
|
|
26
|
+
} | undefined;
|
|
27
|
+
resolveExtensions?: string[] | undefined;
|
|
28
|
+
mainFields?: string[] | undefined;
|
|
29
|
+
conditions?: string[] | undefined;
|
|
30
|
+
write?: boolean | undefined;
|
|
31
|
+
allowOverwrite?: boolean | undefined;
|
|
32
|
+
tsconfig?: string | undefined;
|
|
33
|
+
outExtension?: {
|
|
34
|
+
[ext: string]: string;
|
|
35
|
+
} | undefined;
|
|
36
|
+
publicPath?: string | undefined;
|
|
37
|
+
entryNames?: string | undefined;
|
|
38
|
+
chunkNames?: string | undefined;
|
|
39
|
+
assetNames?: string | undefined;
|
|
40
|
+
inject?: string[] | undefined;
|
|
41
|
+
banner?: {
|
|
42
|
+
[type: string]: string;
|
|
43
|
+
} | undefined;
|
|
44
|
+
footer?: {
|
|
45
|
+
[type: string]: string;
|
|
46
|
+
} | undefined;
|
|
47
|
+
entryPoints?: string[] | Record<string, string> | {
|
|
48
|
+
in: string;
|
|
49
|
+
out: string;
|
|
50
|
+
}[] | undefined;
|
|
51
|
+
stdin?: import("esbuild").StdinOptions | undefined;
|
|
52
|
+
absWorkingDir?: string | undefined;
|
|
53
|
+
nodePaths?: string[] | undefined;
|
|
54
|
+
sourcemap?: boolean | "inline" | "both" | "external" | "linked" | undefined;
|
|
55
|
+
legalComments?: "inline" | "none" | "external" | "linked" | "eof" | undefined;
|
|
56
|
+
sourceRoot?: string | undefined;
|
|
57
|
+
sourcesContent?: boolean | undefined;
|
|
58
|
+
globalName?: string | undefined;
|
|
59
|
+
target?: string | string[] | undefined;
|
|
60
|
+
supported?: Record<string, boolean> | undefined;
|
|
61
|
+
platform?: import("esbuild").Platform | undefined;
|
|
62
|
+
mangleProps?: RegExp | undefined;
|
|
63
|
+
reserveProps?: RegExp | undefined;
|
|
64
|
+
mangleQuoted?: boolean | undefined;
|
|
65
|
+
mangleCache?: Record<string, string | false> | undefined;
|
|
66
|
+
drop?: import("esbuild").Drop[] | undefined;
|
|
67
|
+
minify?: boolean | undefined;
|
|
68
|
+
minifyWhitespace?: boolean | undefined;
|
|
69
|
+
minifyIdentifiers?: boolean | undefined;
|
|
70
|
+
minifySyntax?: boolean | undefined;
|
|
71
|
+
charset?: import("esbuild").Charset | undefined;
|
|
72
|
+
treeShaking?: boolean | undefined;
|
|
73
|
+
ignoreAnnotations?: boolean | undefined;
|
|
74
|
+
jsx?: "transform" | "preserve" | "automatic" | undefined;
|
|
75
|
+
jsxFactory?: string | undefined;
|
|
76
|
+
jsxFragment?: string | undefined;
|
|
77
|
+
jsxImportSource?: string | undefined;
|
|
78
|
+
jsxDev?: boolean | undefined;
|
|
79
|
+
jsxSideEffects?: boolean | undefined;
|
|
80
|
+
define?: {
|
|
81
|
+
[key: string]: string;
|
|
82
|
+
} | undefined;
|
|
83
|
+
pure?: string[] | undefined;
|
|
84
|
+
keepNames?: boolean | undefined;
|
|
85
|
+
color?: boolean | undefined;
|
|
86
|
+
logLevel?: import("esbuild").LogLevel | undefined;
|
|
87
|
+
logLimit?: number | undefined;
|
|
88
|
+
logOverride?: Record<string, import("esbuild").LogLevel> | undefined;
|
|
89
|
+
tsconfigRaw?: string | {
|
|
90
|
+
compilerOptions?: {
|
|
91
|
+
alwaysStrict?: boolean | undefined;
|
|
92
|
+
baseUrl?: boolean | undefined;
|
|
93
|
+
experimentalDecorators?: boolean | undefined;
|
|
94
|
+
importsNotUsedAsValues?: "error" | "remove" | "preserve" | undefined;
|
|
95
|
+
jsx?: "preserve" | "react" | "react-jsx" | "react-jsxdev" | "react-native" | undefined;
|
|
96
|
+
jsxFactory?: string | undefined;
|
|
97
|
+
jsxFragmentFactory?: string | undefined;
|
|
98
|
+
jsxImportSource?: string | undefined;
|
|
99
|
+
paths?: Record<string, string[]> | undefined;
|
|
100
|
+
preserveValueImports?: boolean | undefined;
|
|
101
|
+
strict?: boolean | undefined;
|
|
102
|
+
target?: string | undefined;
|
|
103
|
+
useDefineForClassFields?: boolean | undefined;
|
|
104
|
+
verbatimModuleSyntax?: boolean | undefined;
|
|
105
|
+
} | undefined;
|
|
106
|
+
} | undefined;
|
|
107
|
+
}>[]>;
|
|
108
|
+
start(buildType?: {
|
|
109
|
+
library?: boolean;
|
|
110
|
+
app?: App;
|
|
111
|
+
}): Promise<BuildResult<BuildOptions>[]>;
|
|
8
112
|
}
|
package/lib/actions/build.js
CHANGED
|
@@ -1,25 +1,98 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const path_1 = require("path");
|
|
9
|
-
class BuildAction {
|
|
10
|
-
constructor(options) {
|
|
11
|
-
webpack_config_default_1.webpackConfigDefault.entry = options.entry || webpack_config_default_1.webpackConfigDefault.entry;
|
|
12
|
-
webpack_config_default_1.webpackConfigDefault.output.filename = options.output.filename || webpack_config_default_1.webpackConfigDefault.output.filename;
|
|
13
|
-
webpack_config_default_1.webpackConfigDefault.output.path = options.output.path ? path_1.resolve(__dirname, options.output.path) : webpack_config_default_1.webpackConfigDefault.output.path;
|
|
14
|
-
webpack_config_default_1.minimizerConfigDefault.terserOptions.output.beautify = typeof options.beautify === 'boolean' ? options.beautify : webpack_config_default_1.minimizerConfigDefault.terserOptions.output.beautify;
|
|
15
|
-
webpack_config_default_1.webpackConfigDefault.optimization.minimizer.push(new terser_webpack_plugin_1.default(webpack_config_default_1.minimizerConfigDefault));
|
|
16
|
-
this.compiler = webpack_1.default(webpack_config_default_1.webpackConfigDefault);
|
|
1
|
+
import { build } from 'esbuild';
|
|
2
|
+
import { gjsifyPlugin } from '@gjsify/esbuild-plugin-gjsify';
|
|
3
|
+
import { dirname, extname } from 'path';
|
|
4
|
+
export class BuildAction {
|
|
5
|
+
configData;
|
|
6
|
+
constructor(configData = {}) {
|
|
7
|
+
this.configData = configData;
|
|
17
8
|
}
|
|
18
|
-
|
|
19
|
-
|
|
9
|
+
getEsBuildDefaults() {
|
|
10
|
+
const defaults = {
|
|
11
|
+
allowOverwrite: true
|
|
12
|
+
};
|
|
13
|
+
return defaults;
|
|
20
14
|
}
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
/** Library mode */
|
|
16
|
+
async buildLibrary() {
|
|
17
|
+
let { verbose, library, esbuild, typescript, exclude } = this.configData;
|
|
18
|
+
library ||= {};
|
|
19
|
+
esbuild ||= {};
|
|
20
|
+
typescript ||= {};
|
|
21
|
+
const moduleOutdir = library?.module ? dirname(library.module) : undefined;
|
|
22
|
+
const mainOutdir = library?.main ? dirname(library.main) : undefined;
|
|
23
|
+
const moduleOutExt = library.module ? extname(library.module) : '.js';
|
|
24
|
+
const mainOutExt = library.main ? extname(library.main) : '.js';
|
|
25
|
+
const multipleBuilds = moduleOutdir && mainOutdir && (moduleOutdir !== mainOutdir);
|
|
26
|
+
const results = [];
|
|
27
|
+
if (multipleBuilds) {
|
|
28
|
+
const moduleFormat = moduleOutdir.includes('/cjs') || moduleOutExt === '.cjs' ? 'cjs' : 'esm';
|
|
29
|
+
results.push(await build({
|
|
30
|
+
...this.getEsBuildDefaults(),
|
|
31
|
+
...esbuild,
|
|
32
|
+
format: moduleFormat,
|
|
33
|
+
outdir: moduleOutdir,
|
|
34
|
+
plugins: [
|
|
35
|
+
gjsifyPlugin({ debug: verbose, library: moduleFormat, exclude, reflection: typescript?.reflection, jsExtension: moduleOutExt }),
|
|
36
|
+
]
|
|
37
|
+
}));
|
|
38
|
+
const mainFormat = mainOutdir.includes('/cjs') || mainOutExt === '.cjs' ? 'cjs' : 'esm';
|
|
39
|
+
results.push(await build({
|
|
40
|
+
...this.getEsBuildDefaults(),
|
|
41
|
+
...esbuild,
|
|
42
|
+
format: moduleFormat,
|
|
43
|
+
outdir: mainOutdir,
|
|
44
|
+
plugins: [
|
|
45
|
+
gjsifyPlugin({ debug: verbose, library: mainFormat, exclude, reflection: typescript?.reflection, jsExtension: mainOutdir })
|
|
46
|
+
]
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
const outfilePath = esbuild?.outfile || library?.module || library?.main;
|
|
51
|
+
const outExt = outfilePath ? extname(outfilePath) : '.js';
|
|
52
|
+
const outdir = esbuild?.outdir || (outfilePath ? dirname(outfilePath) : undefined);
|
|
53
|
+
const format = esbuild?.format || outdir?.includes('/cjs') || outExt === '.cjs' ? 'cjs' : 'esm';
|
|
54
|
+
results.push(await build({
|
|
55
|
+
...this.getEsBuildDefaults(),
|
|
56
|
+
...esbuild,
|
|
57
|
+
format,
|
|
58
|
+
outdir,
|
|
59
|
+
plugins: [
|
|
60
|
+
gjsifyPlugin({ debug: verbose, library: format, exclude, reflection: typescript?.reflection, jsExtension: outExt })
|
|
61
|
+
]
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
return results;
|
|
65
|
+
}
|
|
66
|
+
/** Application mode */
|
|
67
|
+
async buildApp(app = 'gjs') {
|
|
68
|
+
const { verbose, esbuild, typescript, exclude } = this.configData;
|
|
69
|
+
const format = esbuild?.format || esbuild?.outfile?.endsWith('.cjs') ? 'cjs' : 'esm';
|
|
70
|
+
const result = await build({
|
|
71
|
+
...this.getEsBuildDefaults(),
|
|
72
|
+
...esbuild,
|
|
73
|
+
format,
|
|
74
|
+
plugins: [
|
|
75
|
+
gjsifyPlugin({ debug: verbose, app, format, exclude, reflection: typescript?.reflection }),
|
|
76
|
+
]
|
|
77
|
+
});
|
|
78
|
+
// See https://esbuild.github.io/api/#metafile
|
|
79
|
+
// TODO add cli options for this
|
|
80
|
+
// if(result.metafile) {
|
|
81
|
+
// const outFile = esbuild?.outfile ? esbuild.outfile + '.meta.json' : 'meta.json';
|
|
82
|
+
// await writeFile(outFile, JSON.stringify(result.metafile));
|
|
83
|
+
// let text = await analyzeMetafile(result.metafile)
|
|
84
|
+
// console.log(text)
|
|
85
|
+
// }
|
|
86
|
+
return [result];
|
|
87
|
+
}
|
|
88
|
+
async start(buildType = { app: 'gjs' }) {
|
|
89
|
+
const results = [];
|
|
90
|
+
if (buildType.library) {
|
|
91
|
+
results.push(...(await this.buildLibrary()));
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
results.push(...(await this.buildApp(buildType.app)));
|
|
95
|
+
}
|
|
96
|
+
return results;
|
|
23
97
|
}
|
|
24
98
|
}
|
|
25
|
-
exports.BuildAction = BuildAction;
|
package/lib/commands/build.d.ts
CHANGED
|
@@ -1,16 +1,2 @@
|
|
|
1
|
-
import { Command,
|
|
2
|
-
export
|
|
3
|
-
static description: string;
|
|
4
|
-
static examples: string[];
|
|
5
|
-
static flags: {
|
|
6
|
-
help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
|
|
7
|
-
outputFilename: flags.IOptionFlag<string>;
|
|
8
|
-
outputPath: flags.IOptionFlag<string>;
|
|
9
|
-
beautify: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
10
|
-
minimize: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
11
|
-
};
|
|
12
|
-
static args: {
|
|
13
|
-
name: string;
|
|
14
|
-
}[];
|
|
15
|
-
run(): Promise<void>;
|
|
16
|
-
}
|
|
1
|
+
import type { Command, CliBuildOptions } from '../types/index.js';
|
|
2
|
+
export declare const buildCommand: Command<any, CliBuildOptions>;
|
package/lib/commands/build.js
CHANGED
|
@@ -1,60 +1,78 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
import { Config } from '../config.js';
|
|
2
|
+
import { BuildAction } from '../actions/build.js';
|
|
3
|
+
export const buildCommand = {
|
|
4
|
+
command: 'build [entryPoints..]',
|
|
5
|
+
description: 'Build and bundle your Gjs project',
|
|
6
|
+
builder: (yargs) => {
|
|
7
|
+
return yargs
|
|
8
|
+
.option('entry-points', {
|
|
9
|
+
description: "The entry points you want to bundle",
|
|
10
|
+
array: true,
|
|
11
|
+
type: 'string',
|
|
12
|
+
normalize: true,
|
|
13
|
+
default: ['src/index.ts'],
|
|
14
|
+
coerce: (arg) => {
|
|
15
|
+
// Removes duplicates
|
|
16
|
+
return [...new Set(arg)];
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
.option('exclude', {
|
|
20
|
+
description: "An array of glob patterns to exclude entry-points and aliases",
|
|
21
|
+
array: true,
|
|
22
|
+
type: 'string',
|
|
23
|
+
normalize: true,
|
|
24
|
+
default: []
|
|
25
|
+
})
|
|
26
|
+
.option('verbose', {
|
|
27
|
+
description: "Switch on the verbose mode",
|
|
28
|
+
type: 'boolean',
|
|
29
|
+
normalize: true,
|
|
30
|
+
default: false
|
|
31
|
+
})
|
|
32
|
+
.option('app', {
|
|
33
|
+
description: "Use this if you want to build a application, the application platforms node and deno are usually only used for tests",
|
|
34
|
+
type: 'string',
|
|
35
|
+
choices: ['gjs', 'node', 'deno', 'browser'],
|
|
36
|
+
normalize: true,
|
|
37
|
+
default: 'gjs'
|
|
38
|
+
})
|
|
39
|
+
.option('library', {
|
|
40
|
+
description: "Use this if you want to build a library for Gjsify",
|
|
41
|
+
type: 'boolean',
|
|
42
|
+
normalize: true,
|
|
43
|
+
default: false
|
|
44
|
+
})
|
|
45
|
+
.option('outfile', {
|
|
46
|
+
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
|
+
type: 'string',
|
|
48
|
+
normalize: true,
|
|
49
|
+
})
|
|
50
|
+
.option('outdir', {
|
|
51
|
+
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
|
+
type: 'string',
|
|
53
|
+
normalize: true,
|
|
54
|
+
})
|
|
55
|
+
.option('reflection', {
|
|
56
|
+
description: "Enables TypeScript types on runtime using Deepkit's type compiler",
|
|
57
|
+
type: 'boolean',
|
|
58
|
+
normalize: true,
|
|
59
|
+
default: false
|
|
60
|
+
})
|
|
61
|
+
.option('log-level', {
|
|
62
|
+
description: "The log level can be changed to prevent esbuild from printing warning and/or error messages to the terminal",
|
|
63
|
+
type: 'string',
|
|
64
|
+
choices: ['silent', 'error', 'warning', 'info', 'debug', 'verbose'],
|
|
65
|
+
normalize: true,
|
|
66
|
+
default: 'warning'
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
handler: async (args) => {
|
|
70
|
+
const config = new Config();
|
|
71
|
+
const configData = await config.forBuild(args);
|
|
72
|
+
const action = new BuildAction(configData);
|
|
73
|
+
await action.start({
|
|
74
|
+
library: args.library,
|
|
75
|
+
app: args.app,
|
|
23
76
|
});
|
|
24
77
|
}
|
|
25
|
-
}
|
|
26
|
-
exports.default = Build;
|
|
27
|
-
Build.description = 'describe the command here';
|
|
28
|
-
Build.examples = [
|
|
29
|
-
'$ gjsify build ./src/hello.ts',
|
|
30
|
-
];
|
|
31
|
-
Build.flags = {
|
|
32
|
-
help: command_1.flags.help({ char: 'h' }),
|
|
33
|
-
outputFilename: command_1.flags.string({
|
|
34
|
-
char: 'o',
|
|
35
|
-
description: 'File name of the output bundle',
|
|
36
|
-
required: false,
|
|
37
|
-
multiple: false,
|
|
38
|
-
default: defaults_1.flags.outputFilename,
|
|
39
|
-
}),
|
|
40
|
-
outputPath: command_1.flags.string({
|
|
41
|
-
char: 'p',
|
|
42
|
-
description: 'Output destination path',
|
|
43
|
-
required: false,
|
|
44
|
-
multiple: false,
|
|
45
|
-
default: defaults_1.flags.outputPath,
|
|
46
|
-
}),
|
|
47
|
-
beautify: command_1.flags.boolean({
|
|
48
|
-
char: 'b',
|
|
49
|
-
description: 'Beautify build output',
|
|
50
|
-
required: false,
|
|
51
|
-
default: defaults_1.flags.beautify,
|
|
52
|
-
}),
|
|
53
|
-
minimize: command_1.flags.boolean({
|
|
54
|
-
char: 'm',
|
|
55
|
-
description: 'Minimize build output',
|
|
56
|
-
required: false,
|
|
57
|
-
default: defaults_1.flags.minimize,
|
|
58
|
-
}),
|
|
59
78
|
};
|
|
60
|
-
Build.args = [{ name: 'file' }];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './build.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './build.js';
|
package/lib/config.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Options as LoadOptions } from 'cosmiconfig';
|
|
2
|
+
import type { CliBuildOptions, ConfigData } from './types/index.js';
|
|
3
|
+
import type { ArgumentsCamelCase } from 'yargs';
|
|
4
|
+
export declare class Config {
|
|
5
|
+
readonly loadOptions: LoadOptions;
|
|
6
|
+
constructor(loadOptions?: LoadOptions);
|
|
7
|
+
/** Loads gjsify config file, e.g `gjsify.js` */
|
|
8
|
+
private load;
|
|
9
|
+
/** Loads package.json of the current project */
|
|
10
|
+
private readPackageJSON;
|
|
11
|
+
/** Loads tsconfig.json of the current project */
|
|
12
|
+
private readTSConfig;
|
|
13
|
+
forBuild(cliArgs: ArgumentsCamelCase<CliBuildOptions>): Promise<ConfigData>;
|
|
14
|
+
}
|
package/lib/config.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { APP_NAME } from './constants.js';
|
|
2
|
+
import { cosmiconfig } from 'cosmiconfig';
|
|
3
|
+
import { readPackageJSON, resolvePackageJSON } from 'pkg-types';
|
|
4
|
+
import { getTsconfig } from 'get-tsconfig';
|
|
5
|
+
import lodash from "lodash";
|
|
6
|
+
const { merge } = lodash;
|
|
7
|
+
export class Config {
|
|
8
|
+
loadOptions = {
|
|
9
|
+
searchPlaces: [APP_NAME]
|
|
10
|
+
};
|
|
11
|
+
constructor(loadOptions = {}) {
|
|
12
|
+
if (Object.keys(loadOptions).length) {
|
|
13
|
+
this.loadOptions = loadOptions;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/** Loads gjsify config file, e.g `gjsify.js` */
|
|
17
|
+
async load(searchFrom) {
|
|
18
|
+
let configFile = await cosmiconfig(APP_NAME, this.loadOptions).search(searchFrom);
|
|
19
|
+
configFile ||= {
|
|
20
|
+
config: {},
|
|
21
|
+
filepath: '',
|
|
22
|
+
isEmpty: true,
|
|
23
|
+
};
|
|
24
|
+
configFile.config ||= {};
|
|
25
|
+
configFile.config.esbuild ||= {};
|
|
26
|
+
configFile.config.library ||= {};
|
|
27
|
+
configFile.config.typescript ||= {};
|
|
28
|
+
return configFile;
|
|
29
|
+
}
|
|
30
|
+
/** Loads package.json of the current project */
|
|
31
|
+
async readPackageJSON(dirPath) {
|
|
32
|
+
dirPath = await resolvePackageJSON(dirPath);
|
|
33
|
+
const pkg = await readPackageJSON(dirPath);
|
|
34
|
+
return pkg;
|
|
35
|
+
}
|
|
36
|
+
/** Loads tsconfig.json of the current project */
|
|
37
|
+
async readTSConfig(dirPath) {
|
|
38
|
+
const tsconfig = getTsconfig(dirPath)?.config || {};
|
|
39
|
+
return tsconfig;
|
|
40
|
+
}
|
|
41
|
+
async forBuild(cliArgs) {
|
|
42
|
+
const configFile = await this.load(process.cwd());
|
|
43
|
+
const configData = { ...configFile.config };
|
|
44
|
+
const configFilePath = configFile.filepath || process.cwd();
|
|
45
|
+
const pkg = await this.readPackageJSON(configFilePath);
|
|
46
|
+
const tsConfig = await this.readTSConfig(configFilePath);
|
|
47
|
+
tsConfig.reflection ||= cliArgs.reflection;
|
|
48
|
+
// TODO replace with `cliArgs.logLevel`
|
|
49
|
+
configData.verbose = cliArgs.verbose || false;
|
|
50
|
+
configData.exclude = cliArgs.exclude || [];
|
|
51
|
+
merge(configData.library, pkg, configData.library);
|
|
52
|
+
merge(configData.typescript, tsConfig, configData.typescript);
|
|
53
|
+
merge(configData.esbuild, {
|
|
54
|
+
entryPoints: cliArgs.entryPoints,
|
|
55
|
+
outfile: cliArgs.outfile,
|
|
56
|
+
outdir: cliArgs.outdir,
|
|
57
|
+
logLevel: cliArgs.logLevel || 'warning'
|
|
58
|
+
});
|
|
59
|
+
if (configData.verbose)
|
|
60
|
+
console.debug("configData", configData);
|
|
61
|
+
return configData;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const APP_NAME = "gjsify";
|
package/lib/constants.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const APP_NAME = 'gjsify';
|
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
export {};
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import yargs from 'yargs';
|
|
3
|
+
import { hideBin } from 'yargs/helpers';
|
|
4
|
+
import { buildCommand as build } from './commands/index.js';
|
|
5
|
+
import { APP_NAME } from './constants.js';
|
|
6
|
+
void yargs(hideBin(process.argv))
|
|
7
|
+
.scriptName(APP_NAME)
|
|
8
|
+
.strict()
|
|
9
|
+
// .usage(Config.usage)
|
|
10
|
+
.command(build.command, build.description, build.builder, build.handler)
|
|
11
|
+
.demandCommand(1)
|
|
12
|
+
.help().argv;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { App } from '@gjsify/esbuild-plugin-gjsify';
|
|
2
|
+
export interface CliBuildOptions {
|
|
3
|
+
/**
|
|
4
|
+
* This is an array of files that each serve as an input to the bundling algorithm.
|
|
5
|
+
* @see https://esbuild.github.io/api/#entry-points
|
|
6
|
+
*/
|
|
7
|
+
entryPoints?: string[];
|
|
8
|
+
/** Switch on the verbose mode */
|
|
9
|
+
verbose?: boolean;
|
|
10
|
+
/** 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
|
+
app?: App;
|
|
12
|
+
/** Use this if you want to build a library for Gjsify */
|
|
13
|
+
library?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* This option sets the output file name for the build operation.
|
|
16
|
+
* This is only applicable if there is a single entry point.
|
|
17
|
+
* If there are multiple entry points, you must use the outdir option instead to specify an output directory.
|
|
18
|
+
* @see https://esbuild.github.io/api/#outfile
|
|
19
|
+
*/
|
|
20
|
+
outfile?: string;
|
|
21
|
+
/**
|
|
22
|
+
* This option sets the output directory for the build operation.
|
|
23
|
+
* @see https://esbuild.github.io/api/#outdir
|
|
24
|
+
*/
|
|
25
|
+
outdir?: string;
|
|
26
|
+
/** Enables TypeScript types on runtime using Deepkit's type compiler */
|
|
27
|
+
reflection?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* The log level can be changed to prevent esbuild from printing warning and/or error messages to the terminal
|
|
30
|
+
* @see https://esbuild.github.io/api/#log-level
|
|
31
|
+
*/
|
|
32
|
+
logLevel: 'silent' | 'error' | 'warning' | 'info' | 'debug' | 'verbose';
|
|
33
|
+
/** An array of glob patterns to exclude matches and aliases */
|
|
34
|
+
exclude?: string[];
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ArgumentsCamelCase, MiddlewareFunction, BuilderCallback } from 'yargs';
|
|
2
|
+
export interface Command<T = any, U = T> {
|
|
3
|
+
command: string | ReadonlyArray<string>;
|
|
4
|
+
description: string;
|
|
5
|
+
builder?: BuilderCallback<T, U>;
|
|
6
|
+
handler?: (args: ArgumentsCamelCase<U>) => void | Promise<void>;
|
|
7
|
+
middlewares?: MiddlewareFunction[];
|
|
8
|
+
deprecated?: boolean | string;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { BuildOptions as EsbuildOptions } from 'esbuild';
|
|
2
|
+
import type { ConfigDataLibrary, ConfigDataTypescript } from './index.js';
|
|
3
|
+
export interface ConfigData {
|
|
4
|
+
/** Switch on the verbose mode */
|
|
5
|
+
verbose?: boolean;
|
|
6
|
+
esbuild?: EsbuildOptions;
|
|
7
|
+
library?: ConfigDataLibrary;
|
|
8
|
+
typescript?: ConfigDataTypescript;
|
|
9
|
+
/** An array of glob patterns to exclude matches and aliases */
|
|
10
|
+
exclude?: string[];
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
|
-
export * from './build-options';
|
|
1
|
+
export * from './cli-build-options.js';
|
|
2
|
+
export * from './command.js';
|
|
3
|
+
export * from './config-data-library.js';
|
|
4
|
+
export * from './config-data-typescript.js';
|
|
5
|
+
export * from './config-data.js';
|
|
6
|
+
export * from './cosmiconfig-result.js';
|
package/lib/types/index.js
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
export * from './cli-build-options.js';
|
|
2
|
+
export * from './command.js';
|
|
3
|
+
export * from './config-data-library.js';
|
|
4
|
+
export * from './config-data-typescript.js';
|
|
5
|
+
export * from './config-data.js';
|
|
6
|
+
export * from './cosmiconfig-result.js';
|