@granite-js/cli 0.1.9 → 0.1.11

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 CHANGED
@@ -1,5 +1,25 @@
1
1
  # @granite-js/cli
2
2
 
3
+ ## 0.1.11
4
+
5
+ ### Patch Changes
6
+
7
+ - 12f568f: improve error handler
8
+ - Updated dependencies [12f568f]
9
+ - Updated dependencies [d3a2b58]
10
+ - @granite-js/mpack@0.1.11
11
+ - @granite-js/plugin-core@0.1.11
12
+ - @granite-js/utils@0.1.11
13
+
14
+ ## 0.1.10
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies [9438be5]
19
+ - @granite-js/plugin-core@0.1.10
20
+ - @granite-js/mpack@0.1.10
21
+ - @granite-js/utils@0.1.10
22
+
3
23
  ## 0.1.9
4
24
 
5
25
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -30,41 +30,28 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
- defineConfig: () => defineConfig,
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
43
 
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
- };
44
+ // src/utils/command.ts
45
+ var import_chalk = __toESM(require("chalk"), 1);
46
+ function errorHandler(error) {
47
+ const label = import_chalk.default.red("Error");
48
+ if (error instanceof Error) {
49
+ console.error(label, error.message);
50
+ } else {
51
+ console.error(label, "Unknown error", (error ?? "")?.toString());
52
+ }
53
+ return 1 /* ERROR */;
54
+ }
68
55
 
69
56
  // src/commands/BuildCommand/BuildCommand.ts
70
57
  var BuildCommand = class extends import_clipanion.Command {
@@ -74,6 +61,9 @@ var BuildCommand = class extends import_clipanion.Command {
74
61
  description: "Build Granite App",
75
62
  examples: [["Build Granite App", "granite build"]]
76
63
  });
64
+ configFile = import_clipanion.Option.String("--config", {
65
+ description: "Path to config file"
66
+ });
77
67
  dev = import_clipanion.Option.Boolean("--dev", {
78
68
  description: "Build in development mode"
79
69
  });
@@ -85,8 +75,8 @@ var BuildCommand = class extends import_clipanion.Command {
85
75
  });
86
76
  async execute() {
87
77
  try {
88
- const { cache = true, metafile = false, dev = false } = this;
89
- const config = await loadConfig();
78
+ const { configFile, cache = true, metafile = false, dev = false } = this;
79
+ const config = await (0, import_plugin_core.loadConfig)({ configFile });
90
80
  const options = ["android", "ios"].map((platform) => ({
91
81
  dev,
92
82
  cache,
@@ -95,17 +85,16 @@ var BuildCommand = class extends import_clipanion.Command {
95
85
  outfile: `bundle.${platform}.js`
96
86
  }));
97
87
  await import_mpack.BuildUtils.buildAll(options, { config, plugins: [import_plugins.statusPlugin] });
98
- return 0;
88
+ return 0 /* SUCCESS */;
99
89
  } catch (error) {
100
- console.error(error);
101
- return 1;
90
+ return errorHandler(error);
102
91
  }
103
92
  }
104
93
  };
105
94
 
106
95
  // src/commands/HermesCommand/HermesCommand.ts
107
96
  var import_path2 = __toESM(require("path"), 1);
108
- var import_chalk = __toESM(require("chalk"), 1);
97
+ var import_chalk2 = __toESM(require("chalk"), 1);
109
98
  var import_clipanion2 = require("clipanion");
110
99
 
111
100
  // src/utils/compileHbc.ts
@@ -174,20 +163,20 @@ var HermesCommand = class extends import_clipanion2.Command {
174
163
  const rootDir = process.cwd();
175
164
  const filePath = import_path2.default.resolve(rootDir, this.jsBundleFile);
176
165
  const { outfile, sourcemapOutfile } = await compileHbc({ rootDir, filePath, sourcemap: this.sourcemap });
177
- console.log(`\u2705 \uCEF4\uD30C\uC77C \uC644\uB8CC: ${import_chalk.default.gray(outfile)}`);
166
+ console.log(`\u2705 Compiled successfully: ${import_chalk2.default.gray(outfile)}`);
178
167
  if (sourcemapOutfile) {
179
- console.log(`\u2705 \uC18C\uC2A4\uB9F5 \uC0DD\uC131 \uC644\uB8CC: ${import_chalk.default.gray(sourcemapOutfile)}`);
168
+ console.log(`\u2705 Source map generated successfully: ${import_chalk2.default.gray(sourcemapOutfile)}`);
180
169
  }
181
- return 0;
170
+ return 0 /* SUCCESS */;
182
171
  } catch (error) {
183
- console.error(error.stack);
184
- return 1;
172
+ return errorHandler(error);
185
173
  }
186
174
  }
187
175
  };
188
176
 
189
177
  // src/commands/DevCommand/DevCommand.ts
190
178
  var import_mpack2 = require("@granite-js/mpack");
179
+ var import_plugin_core2 = require("@granite-js/plugin-core");
191
180
  var import_clipanion3 = require("clipanion");
192
181
  var import_debug = __toESM(require("debug"), 1);
193
182
  var debug = (0, import_debug.default)("cli");
@@ -198,6 +187,9 @@ var DevCommand = class extends import_clipanion3.Command {
198
187
  description: "Run Granite development server",
199
188
  examples: [["Run Granite development server", "granite dev"]]
200
189
  });
190
+ configFile = import_clipanion3.Option.String("--config", {
191
+ description: "Path to config file"
192
+ });
201
193
  host = import_clipanion3.Option.String("--host");
202
194
  port = import_clipanion3.Option.String("--port");
203
195
  disableEmbeddedReactDevTools = import_clipanion3.Option.Boolean("--disable-embedded-react-devtools", false);
@@ -206,7 +198,7 @@ var DevCommand = class extends import_clipanion3.Command {
206
198
  async execute() {
207
199
  try {
208
200
  process.env.MPACK_DEV_SERVER = "true";
209
- const config = await loadConfig();
201
+ const config = await (0, import_plugin_core2.loadConfig)({ configFile: this.configFile });
210
202
  const serverOptions = {
211
203
  host: this.host,
212
204
  port: this.port ? parseInt(this.port, 10) : void 0
@@ -225,89 +217,13 @@ var DevCommand = class extends import_clipanion3.Command {
225
217
  ...serverOptions
226
218
  });
227
219
  }
220
+ return 0 /* SUCCESS */;
228
221
  } catch (error) {
229
- console.log(`ERROR OCCURRED`);
230
- console.log(error);
231
- console.log(error.message);
232
- console.error(error.stack);
233
- process.exit(1);
222
+ return errorHandler(error);
234
223
  }
235
224
  }
236
225
  };
237
226
 
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
227
  // src/index.ts
312
228
  var cli = new import_clipanion4.Cli({
313
229
  binaryLabel: "granite",
@@ -315,20 +231,13 @@ var cli = new import_clipanion4.Cli({
315
231
  enableCapture: true
316
232
  });
317
233
  async function initialize() {
318
- const explorer = await (0, import_cosmiconfig2.cosmiconfig)("mpack");
319
- const result = await explorer.search(process.cwd());
320
234
  cli.register(BuildCommand);
321
235
  cli.register(HermesCommand);
322
236
  cli.register(DevCommand);
323
237
  cli.register(import_clipanion4.Builtins.HelpCommand);
324
- if (Array.isArray(result?.config?.commands)) {
325
- (result?.config?.commands).forEach((command) => cli.register(command));
326
- }
327
238
  cli.runExit(process.argv.slice(2));
328
239
  }
329
240
  // Annotate the CommonJS export names for ESM import in node:
330
241
  0 && (module.exports = {
331
- defineConfig,
332
- initialize,
333
- loadConfig
242
+ initialize
334
243
  });
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 { defineConfig, initialize, loadConfig };
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 { defineConfig, initialize, loadConfig };
3
+ export { initialize };
package/dist/index.js CHANGED
@@ -8,35 +8,24 @@ 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
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
- };
18
+ // src/utils/command.ts
19
+ import chalk from "chalk";
20
+ function errorHandler(error) {
21
+ const label = chalk.red("Error");
22
+ if (error instanceof Error) {
23
+ console.error(label, error.message);
24
+ } else {
25
+ console.error(label, "Unknown error", (error ?? "")?.toString());
26
+ }
27
+ return 1 /* ERROR */;
28
+ }
40
29
 
41
30
  // src/commands/BuildCommand/BuildCommand.ts
42
31
  var BuildCommand = class extends Command {
@@ -46,6 +35,9 @@ var BuildCommand = class extends Command {
46
35
  description: "Build Granite App",
47
36
  examples: [["Build Granite App", "granite build"]]
48
37
  });
38
+ configFile = Option.String("--config", {
39
+ description: "Path to config file"
40
+ });
49
41
  dev = Option.Boolean("--dev", {
50
42
  description: "Build in development mode"
51
43
  });
@@ -57,8 +49,8 @@ var BuildCommand = class extends Command {
57
49
  });
58
50
  async execute() {
59
51
  try {
60
- const { cache = true, metafile = false, dev = false } = this;
61
- const config = await loadConfig();
52
+ const { configFile, cache = true, metafile = false, dev = false } = this;
53
+ const config = await loadConfig({ configFile });
62
54
  const options = ["android", "ios"].map((platform) => ({
63
55
  dev,
64
56
  cache,
@@ -67,17 +59,16 @@ var BuildCommand = class extends Command {
67
59
  outfile: `bundle.${platform}.js`
68
60
  }));
69
61
  await BuildUtils.buildAll(options, { config, plugins: [statusPlugin] });
70
- return 0;
62
+ return 0 /* SUCCESS */;
71
63
  } catch (error) {
72
- console.error(error);
73
- return 1;
64
+ return errorHandler(error);
74
65
  }
75
66
  }
76
67
  };
77
68
 
78
69
  // src/commands/HermesCommand/HermesCommand.ts
79
70
  import path2 from "path";
80
- import chalk from "chalk";
71
+ import chalk2 from "chalk";
81
72
  import { Command as Command2, Option as Option2 } from "clipanion";
82
73
 
83
74
  // src/utils/compileHbc.ts
@@ -146,20 +137,20 @@ var HermesCommand = class extends Command2 {
146
137
  const rootDir = process.cwd();
147
138
  const filePath = path2.resolve(rootDir, this.jsBundleFile);
148
139
  const { outfile, sourcemapOutfile } = await compileHbc({ rootDir, filePath, sourcemap: this.sourcemap });
149
- console.log(`\u2705 \uCEF4\uD30C\uC77C \uC644\uB8CC: ${chalk.gray(outfile)}`);
140
+ console.log(`\u2705 Compiled successfully: ${chalk2.gray(outfile)}`);
150
141
  if (sourcemapOutfile) {
151
- console.log(`\u2705 \uC18C\uC2A4\uB9F5 \uC0DD\uC131 \uC644\uB8CC: ${chalk.gray(sourcemapOutfile)}`);
142
+ console.log(`\u2705 Source map generated successfully: ${chalk2.gray(sourcemapOutfile)}`);
152
143
  }
153
- return 0;
144
+ return 0 /* SUCCESS */;
154
145
  } catch (error) {
155
- console.error(error.stack);
156
- return 1;
146
+ return errorHandler(error);
157
147
  }
158
148
  }
159
149
  };
160
150
 
161
151
  // src/commands/DevCommand/DevCommand.ts
162
152
  import { runServer, EXPERIMENTAL__server } from "@granite-js/mpack";
153
+ import { loadConfig as loadConfig2 } from "@granite-js/plugin-core";
163
154
  import { Command as Command3, Option as Option3 } from "clipanion";
164
155
  import Debug from "debug";
165
156
  var debug = Debug("cli");
@@ -170,6 +161,9 @@ var DevCommand = class extends Command3 {
170
161
  description: "Run Granite development server",
171
162
  examples: [["Run Granite development server", "granite dev"]]
172
163
  });
164
+ configFile = Option3.String("--config", {
165
+ description: "Path to config file"
166
+ });
173
167
  host = Option3.String("--host");
174
168
  port = Option3.String("--port");
175
169
  disableEmbeddedReactDevTools = Option3.Boolean("--disable-embedded-react-devtools", false);
@@ -178,7 +172,7 @@ var DevCommand = class extends Command3 {
178
172
  async execute() {
179
173
  try {
180
174
  process.env.MPACK_DEV_SERVER = "true";
181
- const config = await loadConfig();
175
+ const config = await loadConfig2({ configFile: this.configFile });
182
176
  const serverOptions = {
183
177
  host: this.host,
184
178
  port: this.port ? parseInt(this.port, 10) : void 0
@@ -197,93 +191,13 @@ var DevCommand = class extends Command3 {
197
191
  ...serverOptions
198
192
  });
199
193
  }
194
+ return 0 /* SUCCESS */;
200
195
  } catch (error) {
201
- console.log(`ERROR OCCURRED`);
202
- console.log(error);
203
- console.log(error.message);
204
- console.error(error.stack);
205
- process.exit(1);
196
+ return errorHandler(error);
206
197
  }
207
198
  }
208
199
  };
209
200
 
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
201
  // src/index.ts
288
202
  var cli = new Cli({
289
203
  binaryLabel: "granite",
@@ -291,19 +205,12 @@ var cli = new Cli({
291
205
  enableCapture: true
292
206
  });
293
207
  async function initialize() {
294
- const explorer = await cosmiconfig2("mpack");
295
- const result = await explorer.search(process.cwd());
296
208
  cli.register(BuildCommand);
297
209
  cli.register(HermesCommand);
298
210
  cli.register(DevCommand);
299
211
  cli.register(Builtins.HelpCommand);
300
- if (Array.isArray(result?.config?.commands)) {
301
- (result?.config?.commands).forEach((command) => cli.register(command));
302
- }
303
212
  cli.runExit(process.argv.slice(2));
304
213
  }
305
214
  export {
306
- defineConfig,
307
- initialize,
308
- loadConfig
215
+ initialize
309
216
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@granite-js/cli",
3
3
  "type": "module",
4
- "version": "0.1.9",
4
+ "version": "0.1.11",
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.9",
48
- "@granite-js/plugin-core": "0.1.9",
49
- "@granite-js/utils": "0.1.9",
47
+ "@granite-js/mpack": "0.1.11",
48
+ "@granite-js/plugin-core": "0.1.11",
49
+ "@granite-js/utils": "0.1.11",
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",