@granite-js/cli 0.1.9 → 0.1.10
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/CHANGELOG.md +9 -0
- package/dist/index.cjs +13 -113
- package/dist/index.d.cts +1 -55
- package/dist/index.d.ts +1 -55
- package/dist/index.js +12 -114
- package/package.json +4 -6
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -30,43 +30,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
|
|
34
|
-
initialize: () => initialize,
|
|
35
|
-
loadConfig: () => loadConfig
|
|
33
|
+
initialize: () => initialize
|
|
36
34
|
});
|
|
37
35
|
module.exports = __toCommonJS(index_exports);
|
|
38
36
|
var import_clipanion4 = require("clipanion");
|
|
39
|
-
var import_cosmiconfig2 = require("cosmiconfig");
|
|
40
37
|
|
|
41
38
|
// src/commands/BuildCommand/BuildCommand.ts
|
|
42
39
|
var import_mpack = require("@granite-js/mpack");
|
|
43
40
|
var import_plugins = require("@granite-js/mpack/plugins");
|
|
41
|
+
var import_plugin_core = require("@granite-js/plugin-core");
|
|
44
42
|
var import_clipanion = require("clipanion");
|
|
45
|
-
|
|
46
|
-
// src/config/loadConfig.ts
|
|
47
|
-
var import_utils = require("@granite-js/utils");
|
|
48
|
-
var import_cosmiconfig = require("cosmiconfig");
|
|
49
|
-
var import_cosmiconfig_typescript_loader = require("cosmiconfig-typescript-loader");
|
|
50
|
-
var MODULE_NAME = "granite";
|
|
51
|
-
var loadConfig = async () => {
|
|
52
|
-
const explorer = (0, import_cosmiconfig.cosmiconfig)(MODULE_NAME, {
|
|
53
|
-
searchPlaces: [
|
|
54
|
-
`${MODULE_NAME}.config.ts`,
|
|
55
|
-
`${MODULE_NAME}.config.mts`,
|
|
56
|
-
`${MODULE_NAME}.config.js`,
|
|
57
|
-
`${MODULE_NAME}.config.cjs`
|
|
58
|
-
],
|
|
59
|
-
loaders: {
|
|
60
|
-
".ts": (0, import_cosmiconfig_typescript_loader.TypeScriptLoader)(),
|
|
61
|
-
".mts": (0, import_cosmiconfig_typescript_loader.TypeScriptLoader)()
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
const result = await explorer.search((0, import_utils.getPackageRoot)());
|
|
65
|
-
const config = await result?.config;
|
|
66
|
-
return config;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
// src/commands/BuildCommand/BuildCommand.ts
|
|
70
43
|
var BuildCommand = class extends import_clipanion.Command {
|
|
71
44
|
static paths = [[`build`]];
|
|
72
45
|
static usage = import_clipanion.Command.Usage({
|
|
@@ -74,6 +47,9 @@ var BuildCommand = class extends import_clipanion.Command {
|
|
|
74
47
|
description: "Build Granite App",
|
|
75
48
|
examples: [["Build Granite App", "granite build"]]
|
|
76
49
|
});
|
|
50
|
+
configFile = import_clipanion.Option.String("--config", {
|
|
51
|
+
description: "Path to config file"
|
|
52
|
+
});
|
|
77
53
|
dev = import_clipanion.Option.Boolean("--dev", {
|
|
78
54
|
description: "Build in development mode"
|
|
79
55
|
});
|
|
@@ -85,8 +61,8 @@ var BuildCommand = class extends import_clipanion.Command {
|
|
|
85
61
|
});
|
|
86
62
|
async execute() {
|
|
87
63
|
try {
|
|
88
|
-
const { cache = true, metafile = false, dev = false } = this;
|
|
89
|
-
const config = await loadConfig();
|
|
64
|
+
const { configFile, cache = true, metafile = false, dev = false } = this;
|
|
65
|
+
const config = await (0, import_plugin_core.loadConfig)({ configFile });
|
|
90
66
|
const options = ["android", "ios"].map((platform) => ({
|
|
91
67
|
dev,
|
|
92
68
|
cache,
|
|
@@ -188,6 +164,7 @@ var HermesCommand = class extends import_clipanion2.Command {
|
|
|
188
164
|
|
|
189
165
|
// src/commands/DevCommand/DevCommand.ts
|
|
190
166
|
var import_mpack2 = require("@granite-js/mpack");
|
|
167
|
+
var import_plugin_core2 = require("@granite-js/plugin-core");
|
|
191
168
|
var import_clipanion3 = require("clipanion");
|
|
192
169
|
var import_debug = __toESM(require("debug"), 1);
|
|
193
170
|
var debug = (0, import_debug.default)("cli");
|
|
@@ -198,6 +175,9 @@ var DevCommand = class extends import_clipanion3.Command {
|
|
|
198
175
|
description: "Run Granite development server",
|
|
199
176
|
examples: [["Run Granite development server", "granite dev"]]
|
|
200
177
|
});
|
|
178
|
+
configFile = import_clipanion3.Option.String("--config", {
|
|
179
|
+
description: "Path to config file"
|
|
180
|
+
});
|
|
201
181
|
host = import_clipanion3.Option.String("--host");
|
|
202
182
|
port = import_clipanion3.Option.String("--port");
|
|
203
183
|
disableEmbeddedReactDevTools = import_clipanion3.Option.Boolean("--disable-embedded-react-devtools", false);
|
|
@@ -206,7 +186,7 @@ var DevCommand = class extends import_clipanion3.Command {
|
|
|
206
186
|
async execute() {
|
|
207
187
|
try {
|
|
208
188
|
process.env.MPACK_DEV_SERVER = "true";
|
|
209
|
-
const config = await loadConfig();
|
|
189
|
+
const config = await (0, import_plugin_core2.loadConfig)({ configFile: this.configFile });
|
|
210
190
|
const serverOptions = {
|
|
211
191
|
host: this.host,
|
|
212
192
|
port: this.port ? parseInt(this.port, 10) : void 0
|
|
@@ -235,79 +215,6 @@ var DevCommand = class extends import_clipanion3.Command {
|
|
|
235
215
|
}
|
|
236
216
|
};
|
|
237
217
|
|
|
238
|
-
// src/config/defineConfig.ts
|
|
239
|
-
var import_path4 = __toESM(require("path"), 1);
|
|
240
|
-
var import_plugin_core = require("@granite-js/plugin-core");
|
|
241
|
-
var import_utils3 = require("@granite-js/utils");
|
|
242
|
-
var import_es_toolkit2 = require("es-toolkit");
|
|
243
|
-
|
|
244
|
-
// src/config/graniteGlobals.ts
|
|
245
|
-
var import_fs = __toESM(require("fs"), 1);
|
|
246
|
-
var import_path3 = __toESM(require("path"), 1);
|
|
247
|
-
var import_utils2 = require("@granite-js/utils");
|
|
248
|
-
function prepareGraniteGlobalsScript(config) {
|
|
249
|
-
const filePath = writeGraniteGlobalsScript(config);
|
|
250
|
-
return {
|
|
251
|
-
esbuild: {
|
|
252
|
-
prelude: [filePath]
|
|
253
|
-
},
|
|
254
|
-
metro: {
|
|
255
|
-
serializer: {
|
|
256
|
-
getPolyfills: () => [filePath]
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
function writeGraniteGlobalsScript(config) {
|
|
262
|
-
const script = getGraniteGlobalScript(config);
|
|
263
|
-
const filePath = import_path3.default.join((0, import_utils2.getLocalTempDirectoryPath)(config.rootDir), "granite-globals.js");
|
|
264
|
-
(0, import_utils2.prepareLocalDirectory)(config.rootDir);
|
|
265
|
-
import_fs.default.writeFileSync(filePath, script, "utf-8");
|
|
266
|
-
return filePath;
|
|
267
|
-
}
|
|
268
|
-
function getGraniteGlobalScript({ appName, scheme }) {
|
|
269
|
-
return [
|
|
270
|
-
"global.__granite = global.__granite || {};",
|
|
271
|
-
`global.__granite.app = { name: ${JSON.stringify(appName)}, scheme: ${JSON.stringify(scheme)} };`
|
|
272
|
-
].join("\n");
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// src/config/defineConfig.ts
|
|
276
|
-
var defineConfig = async (config) => {
|
|
277
|
-
const parsed = import_plugin_core.pluginConfigSchema.parse(config);
|
|
278
|
-
const cwd = parsed.cwd ?? (0, import_utils3.getPackageRoot)();
|
|
279
|
-
const appName = parsed.appName;
|
|
280
|
-
const scheme = parsed.scheme;
|
|
281
|
-
const entryFile = import_path4.default.resolve(cwd, parsed.entryFile);
|
|
282
|
-
const outdir = import_path4.default.join(cwd, parsed.outdir);
|
|
283
|
-
const parsedBuildConfig = parsed.build;
|
|
284
|
-
const parsedDevServerConfig = parsed.devServer;
|
|
285
|
-
const parsedMetroConfig = parsed.metro;
|
|
286
|
-
const parsedConfig = {
|
|
287
|
-
...parsedBuildConfig,
|
|
288
|
-
devServer: parsedDevServerConfig,
|
|
289
|
-
metro: parsedMetroConfig
|
|
290
|
-
};
|
|
291
|
-
const { configs, pluginHooks } = await (0, import_plugin_core.resolvePlugins)(parsed.plugins);
|
|
292
|
-
const globalsScriptConfig = prepareGraniteGlobalsScript({ rootDir: cwd, appName, scheme });
|
|
293
|
-
const mergedConfig = (0, import_plugin_core.mergeConfig)(parsedConfig, ...[globalsScriptConfig, ...configs].filter(import_es_toolkit2.isNotNil));
|
|
294
|
-
const { metro, devServer, ...build } = mergedConfig ?? {};
|
|
295
|
-
return {
|
|
296
|
-
cwd,
|
|
297
|
-
appName,
|
|
298
|
-
entryFile,
|
|
299
|
-
outdir,
|
|
300
|
-
build,
|
|
301
|
-
devServer,
|
|
302
|
-
pluginHooks,
|
|
303
|
-
metro: {
|
|
304
|
-
...metro,
|
|
305
|
-
babelConfig: mergedConfig?.babel,
|
|
306
|
-
transformSync: mergedConfig?.transformer?.transformSync
|
|
307
|
-
}
|
|
308
|
-
};
|
|
309
|
-
};
|
|
310
|
-
|
|
311
218
|
// src/index.ts
|
|
312
219
|
var cli = new import_clipanion4.Cli({
|
|
313
220
|
binaryLabel: "granite",
|
|
@@ -315,20 +222,13 @@ var cli = new import_clipanion4.Cli({
|
|
|
315
222
|
enableCapture: true
|
|
316
223
|
});
|
|
317
224
|
async function initialize() {
|
|
318
|
-
const explorer = await (0, import_cosmiconfig2.cosmiconfig)("mpack");
|
|
319
|
-
const result = await explorer.search(process.cwd());
|
|
320
225
|
cli.register(BuildCommand);
|
|
321
226
|
cli.register(HermesCommand);
|
|
322
227
|
cli.register(DevCommand);
|
|
323
228
|
cli.register(import_clipanion4.Builtins.HelpCommand);
|
|
324
|
-
if (Array.isArray(result?.config?.commands)) {
|
|
325
|
-
(result?.config?.commands).forEach((command) => cli.register(command));
|
|
326
|
-
}
|
|
327
229
|
cli.runExit(process.argv.slice(2));
|
|
328
230
|
}
|
|
329
231
|
// Annotate the CommonJS export names for ESM import in node:
|
|
330
232
|
0 && (module.exports = {
|
|
331
|
-
|
|
332
|
-
initialize,
|
|
333
|
-
loadConfig
|
|
233
|
+
initialize
|
|
334
234
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,57 +1,3 @@
|
|
|
1
|
-
import { GraniteConfig, CompleteGraniteConfig } from '@granite-js/plugin-core';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @public
|
|
5
|
-
* @category Configuration
|
|
6
|
-
* @name defineConfig
|
|
7
|
-
* @description
|
|
8
|
-
* Configures your Granite application by defining key settings in `granite.config.ts`.
|
|
9
|
-
*
|
|
10
|
-
* The configuration lets you specify:
|
|
11
|
-
* - How users will access your app through a URL scheme (e.g. `granite://`)
|
|
12
|
-
* - Your app's unique name that appears in the URL (e.g. `granite://my-service`)
|
|
13
|
-
* - Build settings for bundlers like ESBuild and Metro
|
|
14
|
-
* - Code transformation settings through Babel
|
|
15
|
-
* - Additional functionality through Granite plugins
|
|
16
|
-
*
|
|
17
|
-
* @param config - Configuration options
|
|
18
|
-
* @param config.cwd - Working directory for build process (defaults to process.cwd())
|
|
19
|
-
* @param config.appName - Your app's unique identifier
|
|
20
|
-
* @param config.scheme - URL scheme for launching your app (e.g. 'granite')
|
|
21
|
-
* @param config.outdir - Where to output build files (defaults to 'dist')
|
|
22
|
-
* @param config.entryFile - Your app's entry point (defaults to './src/_app.tsx')
|
|
23
|
-
* @param config.build - Customize build settings
|
|
24
|
-
* @param config.metro - Configure Metro bundler settings
|
|
25
|
-
* @param config.devServer - Configure Mpack dev server settings
|
|
26
|
-
* @param config.plugins - Granite plugins to enhance functionality
|
|
27
|
-
* @returns The processed configuration
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* Here's a basic configuration that:
|
|
31
|
-
* - Makes your app accessible via the `granite://` scheme
|
|
32
|
-
* - Names your service "my-app" so it's reachable at `granite://my-app`
|
|
33
|
-
* - Uses the Hermes plugin to optimize JavaScript bundles into bytecode
|
|
34
|
-
*
|
|
35
|
-
* ```ts
|
|
36
|
-
* import { defineConfig } from '@granite-js/react-native/config';
|
|
37
|
-
* import { hermes } from '@granite-js/plugin-hermes';
|
|
38
|
-
*
|
|
39
|
-
* export default defineConfig({
|
|
40
|
-
* // The name of your microservice
|
|
41
|
-
* appName: 'my-app',
|
|
42
|
-
* // The URL scheme for deep linking
|
|
43
|
-
* scheme: 'granite',
|
|
44
|
-
* // Entry file path
|
|
45
|
-
* entryFile: 'index.ts',
|
|
46
|
-
* // Array of plugins to use
|
|
47
|
-
* plugins: [hermes()],
|
|
48
|
-
* });
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
declare const defineConfig: (config: GraniteConfig) => Promise<CompleteGraniteConfig>;
|
|
52
|
-
|
|
53
|
-
declare const loadConfig: () => Promise<CompleteGraniteConfig>;
|
|
54
|
-
|
|
55
1
|
declare function initialize(): Promise<void>;
|
|
56
2
|
|
|
57
|
-
export {
|
|
3
|
+
export { initialize };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,57 +1,3 @@
|
|
|
1
|
-
import { GraniteConfig, CompleteGraniteConfig } from '@granite-js/plugin-core';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @public
|
|
5
|
-
* @category Configuration
|
|
6
|
-
* @name defineConfig
|
|
7
|
-
* @description
|
|
8
|
-
* Configures your Granite application by defining key settings in `granite.config.ts`.
|
|
9
|
-
*
|
|
10
|
-
* The configuration lets you specify:
|
|
11
|
-
* - How users will access your app through a URL scheme (e.g. `granite://`)
|
|
12
|
-
* - Your app's unique name that appears in the URL (e.g. `granite://my-service`)
|
|
13
|
-
* - Build settings for bundlers like ESBuild and Metro
|
|
14
|
-
* - Code transformation settings through Babel
|
|
15
|
-
* - Additional functionality through Granite plugins
|
|
16
|
-
*
|
|
17
|
-
* @param config - Configuration options
|
|
18
|
-
* @param config.cwd - Working directory for build process (defaults to process.cwd())
|
|
19
|
-
* @param config.appName - Your app's unique identifier
|
|
20
|
-
* @param config.scheme - URL scheme for launching your app (e.g. 'granite')
|
|
21
|
-
* @param config.outdir - Where to output build files (defaults to 'dist')
|
|
22
|
-
* @param config.entryFile - Your app's entry point (defaults to './src/_app.tsx')
|
|
23
|
-
* @param config.build - Customize build settings
|
|
24
|
-
* @param config.metro - Configure Metro bundler settings
|
|
25
|
-
* @param config.devServer - Configure Mpack dev server settings
|
|
26
|
-
* @param config.plugins - Granite plugins to enhance functionality
|
|
27
|
-
* @returns The processed configuration
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* Here's a basic configuration that:
|
|
31
|
-
* - Makes your app accessible via the `granite://` scheme
|
|
32
|
-
* - Names your service "my-app" so it's reachable at `granite://my-app`
|
|
33
|
-
* - Uses the Hermes plugin to optimize JavaScript bundles into bytecode
|
|
34
|
-
*
|
|
35
|
-
* ```ts
|
|
36
|
-
* import { defineConfig } from '@granite-js/react-native/config';
|
|
37
|
-
* import { hermes } from '@granite-js/plugin-hermes';
|
|
38
|
-
*
|
|
39
|
-
* export default defineConfig({
|
|
40
|
-
* // The name of your microservice
|
|
41
|
-
* appName: 'my-app',
|
|
42
|
-
* // The URL scheme for deep linking
|
|
43
|
-
* scheme: 'granite',
|
|
44
|
-
* // Entry file path
|
|
45
|
-
* entryFile: 'index.ts',
|
|
46
|
-
* // Array of plugins to use
|
|
47
|
-
* plugins: [hermes()],
|
|
48
|
-
* });
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
declare const defineConfig: (config: GraniteConfig) => Promise<CompleteGraniteConfig>;
|
|
52
|
-
|
|
53
|
-
declare const loadConfig: () => Promise<CompleteGraniteConfig>;
|
|
54
|
-
|
|
55
1
|
declare function initialize(): Promise<void>;
|
|
56
2
|
|
|
57
|
-
export {
|
|
3
|
+
export { initialize };
|
package/dist/index.js
CHANGED
|
@@ -8,37 +8,12 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
8
8
|
|
|
9
9
|
// src/index.ts
|
|
10
10
|
import { Builtins, Cli } from "clipanion";
|
|
11
|
-
import { cosmiconfig as cosmiconfig2 } from "cosmiconfig";
|
|
12
11
|
|
|
13
12
|
// src/commands/BuildCommand/BuildCommand.ts
|
|
14
13
|
import { BuildUtils } from "@granite-js/mpack";
|
|
15
14
|
import { statusPlugin } from "@granite-js/mpack/plugins";
|
|
15
|
+
import { loadConfig } from "@granite-js/plugin-core";
|
|
16
16
|
import { Command, Option } from "clipanion";
|
|
17
|
-
|
|
18
|
-
// src/config/loadConfig.ts
|
|
19
|
-
import { getPackageRoot } from "@granite-js/utils";
|
|
20
|
-
import { cosmiconfig } from "cosmiconfig";
|
|
21
|
-
import { TypeScriptLoader } from "cosmiconfig-typescript-loader";
|
|
22
|
-
var MODULE_NAME = "granite";
|
|
23
|
-
var loadConfig = async () => {
|
|
24
|
-
const explorer = cosmiconfig(MODULE_NAME, {
|
|
25
|
-
searchPlaces: [
|
|
26
|
-
`${MODULE_NAME}.config.ts`,
|
|
27
|
-
`${MODULE_NAME}.config.mts`,
|
|
28
|
-
`${MODULE_NAME}.config.js`,
|
|
29
|
-
`${MODULE_NAME}.config.cjs`
|
|
30
|
-
],
|
|
31
|
-
loaders: {
|
|
32
|
-
".ts": TypeScriptLoader(),
|
|
33
|
-
".mts": TypeScriptLoader()
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
const result = await explorer.search(getPackageRoot());
|
|
37
|
-
const config = await result?.config;
|
|
38
|
-
return config;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// src/commands/BuildCommand/BuildCommand.ts
|
|
42
17
|
var BuildCommand = class extends Command {
|
|
43
18
|
static paths = [[`build`]];
|
|
44
19
|
static usage = Command.Usage({
|
|
@@ -46,6 +21,9 @@ var BuildCommand = class extends Command {
|
|
|
46
21
|
description: "Build Granite App",
|
|
47
22
|
examples: [["Build Granite App", "granite build"]]
|
|
48
23
|
});
|
|
24
|
+
configFile = Option.String("--config", {
|
|
25
|
+
description: "Path to config file"
|
|
26
|
+
});
|
|
49
27
|
dev = Option.Boolean("--dev", {
|
|
50
28
|
description: "Build in development mode"
|
|
51
29
|
});
|
|
@@ -57,8 +35,8 @@ var BuildCommand = class extends Command {
|
|
|
57
35
|
});
|
|
58
36
|
async execute() {
|
|
59
37
|
try {
|
|
60
|
-
const { cache = true, metafile = false, dev = false } = this;
|
|
61
|
-
const config = await loadConfig();
|
|
38
|
+
const { configFile, cache = true, metafile = false, dev = false } = this;
|
|
39
|
+
const config = await loadConfig({ configFile });
|
|
62
40
|
const options = ["android", "ios"].map((platform) => ({
|
|
63
41
|
dev,
|
|
64
42
|
cache,
|
|
@@ -160,6 +138,7 @@ var HermesCommand = class extends Command2 {
|
|
|
160
138
|
|
|
161
139
|
// src/commands/DevCommand/DevCommand.ts
|
|
162
140
|
import { runServer, EXPERIMENTAL__server } from "@granite-js/mpack";
|
|
141
|
+
import { loadConfig as loadConfig2 } from "@granite-js/plugin-core";
|
|
163
142
|
import { Command as Command3, Option as Option3 } from "clipanion";
|
|
164
143
|
import Debug from "debug";
|
|
165
144
|
var debug = Debug("cli");
|
|
@@ -170,6 +149,9 @@ var DevCommand = class extends Command3 {
|
|
|
170
149
|
description: "Run Granite development server",
|
|
171
150
|
examples: [["Run Granite development server", "granite dev"]]
|
|
172
151
|
});
|
|
152
|
+
configFile = Option3.String("--config", {
|
|
153
|
+
description: "Path to config file"
|
|
154
|
+
});
|
|
173
155
|
host = Option3.String("--host");
|
|
174
156
|
port = Option3.String("--port");
|
|
175
157
|
disableEmbeddedReactDevTools = Option3.Boolean("--disable-embedded-react-devtools", false);
|
|
@@ -178,7 +160,7 @@ var DevCommand = class extends Command3 {
|
|
|
178
160
|
async execute() {
|
|
179
161
|
try {
|
|
180
162
|
process.env.MPACK_DEV_SERVER = "true";
|
|
181
|
-
const config = await
|
|
163
|
+
const config = await loadConfig2({ configFile: this.configFile });
|
|
182
164
|
const serverOptions = {
|
|
183
165
|
host: this.host,
|
|
184
166
|
port: this.port ? parseInt(this.port, 10) : void 0
|
|
@@ -207,83 +189,6 @@ var DevCommand = class extends Command3 {
|
|
|
207
189
|
}
|
|
208
190
|
};
|
|
209
191
|
|
|
210
|
-
// src/config/defineConfig.ts
|
|
211
|
-
import path4 from "path";
|
|
212
|
-
import {
|
|
213
|
-
resolvePlugins,
|
|
214
|
-
mergeConfig,
|
|
215
|
-
pluginConfigSchema
|
|
216
|
-
} from "@granite-js/plugin-core";
|
|
217
|
-
import { getPackageRoot as getPackageRoot2 } from "@granite-js/utils";
|
|
218
|
-
import { isNotNil as isNotNil2 } from "es-toolkit";
|
|
219
|
-
|
|
220
|
-
// src/config/graniteGlobals.ts
|
|
221
|
-
import fs from "fs";
|
|
222
|
-
import path3 from "path";
|
|
223
|
-
import { getLocalTempDirectoryPath, prepareLocalDirectory } from "@granite-js/utils";
|
|
224
|
-
function prepareGraniteGlobalsScript(config) {
|
|
225
|
-
const filePath = writeGraniteGlobalsScript(config);
|
|
226
|
-
return {
|
|
227
|
-
esbuild: {
|
|
228
|
-
prelude: [filePath]
|
|
229
|
-
},
|
|
230
|
-
metro: {
|
|
231
|
-
serializer: {
|
|
232
|
-
getPolyfills: () => [filePath]
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
};
|
|
236
|
-
}
|
|
237
|
-
function writeGraniteGlobalsScript(config) {
|
|
238
|
-
const script = getGraniteGlobalScript(config);
|
|
239
|
-
const filePath = path3.join(getLocalTempDirectoryPath(config.rootDir), "granite-globals.js");
|
|
240
|
-
prepareLocalDirectory(config.rootDir);
|
|
241
|
-
fs.writeFileSync(filePath, script, "utf-8");
|
|
242
|
-
return filePath;
|
|
243
|
-
}
|
|
244
|
-
function getGraniteGlobalScript({ appName, scheme }) {
|
|
245
|
-
return [
|
|
246
|
-
"global.__granite = global.__granite || {};",
|
|
247
|
-
`global.__granite.app = { name: ${JSON.stringify(appName)}, scheme: ${JSON.stringify(scheme)} };`
|
|
248
|
-
].join("\n");
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
// src/config/defineConfig.ts
|
|
252
|
-
var defineConfig = async (config) => {
|
|
253
|
-
const parsed = pluginConfigSchema.parse(config);
|
|
254
|
-
const cwd = parsed.cwd ?? getPackageRoot2();
|
|
255
|
-
const appName = parsed.appName;
|
|
256
|
-
const scheme = parsed.scheme;
|
|
257
|
-
const entryFile = path4.resolve(cwd, parsed.entryFile);
|
|
258
|
-
const outdir = path4.join(cwd, parsed.outdir);
|
|
259
|
-
const parsedBuildConfig = parsed.build;
|
|
260
|
-
const parsedDevServerConfig = parsed.devServer;
|
|
261
|
-
const parsedMetroConfig = parsed.metro;
|
|
262
|
-
const parsedConfig = {
|
|
263
|
-
...parsedBuildConfig,
|
|
264
|
-
devServer: parsedDevServerConfig,
|
|
265
|
-
metro: parsedMetroConfig
|
|
266
|
-
};
|
|
267
|
-
const { configs, pluginHooks } = await resolvePlugins(parsed.plugins);
|
|
268
|
-
const globalsScriptConfig = prepareGraniteGlobalsScript({ rootDir: cwd, appName, scheme });
|
|
269
|
-
const mergedConfig = mergeConfig(parsedConfig, ...[globalsScriptConfig, ...configs].filter(isNotNil2));
|
|
270
|
-
const { metro, devServer, ...build } = mergedConfig ?? {};
|
|
271
|
-
return {
|
|
272
|
-
cwd,
|
|
273
|
-
appName,
|
|
274
|
-
entryFile,
|
|
275
|
-
outdir,
|
|
276
|
-
build,
|
|
277
|
-
devServer,
|
|
278
|
-
pluginHooks,
|
|
279
|
-
metro: {
|
|
280
|
-
...metro,
|
|
281
|
-
babelConfig: mergedConfig?.babel,
|
|
282
|
-
transformSync: mergedConfig?.transformer?.transformSync
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
};
|
|
286
|
-
|
|
287
192
|
// src/index.ts
|
|
288
193
|
var cli = new Cli({
|
|
289
194
|
binaryLabel: "granite",
|
|
@@ -291,19 +196,12 @@ var cli = new Cli({
|
|
|
291
196
|
enableCapture: true
|
|
292
197
|
});
|
|
293
198
|
async function initialize() {
|
|
294
|
-
const explorer = await cosmiconfig2("mpack");
|
|
295
|
-
const result = await explorer.search(process.cwd());
|
|
296
199
|
cli.register(BuildCommand);
|
|
297
200
|
cli.register(HermesCommand);
|
|
298
201
|
cli.register(DevCommand);
|
|
299
202
|
cli.register(Builtins.HelpCommand);
|
|
300
|
-
if (Array.isArray(result?.config?.commands)) {
|
|
301
|
-
(result?.config?.commands).forEach((command) => cli.register(command));
|
|
302
|
-
}
|
|
303
203
|
cli.runExit(process.argv.slice(2));
|
|
304
204
|
}
|
|
305
205
|
export {
|
|
306
|
-
|
|
307
|
-
initialize,
|
|
308
|
-
loadConfig
|
|
206
|
+
initialize
|
|
309
207
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@granite-js/cli",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.10",
|
|
5
5
|
"description": "The Granite CLI",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -44,16 +44,14 @@
|
|
|
44
44
|
"vitest": "^3.0.7"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@granite-js/mpack": "0.1.
|
|
48
|
-
"@granite-js/plugin-core": "0.1.
|
|
49
|
-
"@granite-js/utils": "0.1.
|
|
47
|
+
"@granite-js/mpack": "0.1.10",
|
|
48
|
+
"@granite-js/plugin-core": "0.1.10",
|
|
49
|
+
"@granite-js/utils": "0.1.10",
|
|
50
50
|
"@inquirer/prompts": "^7.2.3",
|
|
51
51
|
"@shopify/semaphore": "^3.1.0",
|
|
52
52
|
"chalk": "^4",
|
|
53
53
|
"clipanion": "^4.0.0-rc.4",
|
|
54
54
|
"connect": "^3.7.0",
|
|
55
|
-
"cosmiconfig": "^9.0.0",
|
|
56
|
-
"cosmiconfig-typescript-loader": "^5.1.0",
|
|
57
55
|
"debug": "^4.3.7",
|
|
58
56
|
"enquirer": "^2.4.1",
|
|
59
57
|
"es-toolkit": "^1.39.8",
|