@granite-js/cli 0.1.6 → 0.1.8
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 +19 -0
- package/dist/index.cjs +83 -469
- package/dist/index.d.cts +8 -161
- package/dist/index.d.ts +8 -161
- package/dist/index.js +85 -467
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -11,48 +11,9 @@ import { Builtins, Cli } from "clipanion";
|
|
|
11
11
|
import { cosmiconfig as cosmiconfig2 } from "cosmiconfig";
|
|
12
12
|
|
|
13
13
|
// src/commands/BuildCommand/BuildCommand.ts
|
|
14
|
-
import {
|
|
15
|
-
|
|
16
|
-
// src/build.ts
|
|
17
|
-
import { runBundle } from "@granite-js/mpack";
|
|
14
|
+
import { BuildUtils } from "@granite-js/mpack";
|
|
18
15
|
import { statusPlugin } from "@granite-js/mpack/plugins";
|
|
19
|
-
import {
|
|
20
|
-
async function build(config, {
|
|
21
|
-
tag,
|
|
22
|
-
cache
|
|
23
|
-
}) {
|
|
24
|
-
const resolvedPlugins = await resolvePlugins(config.plugins);
|
|
25
|
-
const pluginContext = {
|
|
26
|
-
meta: /* @__PURE__ */ Object.create(null)
|
|
27
|
-
};
|
|
28
|
-
for (const preHandler of resolvedPlugins.build.preHandlers) {
|
|
29
|
-
await preHandler?.call(pluginContext, {
|
|
30
|
-
cwd: config.cwd,
|
|
31
|
-
entryFile: config.entryFile,
|
|
32
|
-
appName: config.appName,
|
|
33
|
-
outdir: config.outdir,
|
|
34
|
-
buildResults: []
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
const results = await runBundle({
|
|
38
|
-
tag,
|
|
39
|
-
rootDir: config.cwd,
|
|
40
|
-
dev: false,
|
|
41
|
-
cache,
|
|
42
|
-
metafile: true,
|
|
43
|
-
plugins: [statusPlugin],
|
|
44
|
-
config: config.mpack.build.config
|
|
45
|
-
});
|
|
46
|
-
for (const postHandler of resolvedPlugins.build.postHandlers) {
|
|
47
|
-
await postHandler?.call(pluginContext, {
|
|
48
|
-
cwd: config.cwd,
|
|
49
|
-
entryFile: config.entryFile,
|
|
50
|
-
appName: config.appName,
|
|
51
|
-
outdir: config.outdir,
|
|
52
|
-
buildResults: results
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
16
|
+
import { Command, Option } from "clipanion";
|
|
56
17
|
|
|
57
18
|
// src/config/loadConfig.ts
|
|
58
19
|
import { getPackageRoot } from "@granite-js/utils";
|
|
@@ -82,26 +43,30 @@ var BuildCommand = class extends Command {
|
|
|
82
43
|
static paths = [[`build`]];
|
|
83
44
|
static usage = Command.Usage({
|
|
84
45
|
category: "Build",
|
|
85
|
-
description: "Granite App
|
|
86
|
-
examples: [
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
46
|
+
description: "Build Granite App",
|
|
47
|
+
examples: [["Build Granite App", "granite build"]]
|
|
48
|
+
});
|
|
49
|
+
dev = Option.Boolean("--dev", {
|
|
50
|
+
description: "Build in development mode"
|
|
90
51
|
});
|
|
91
|
-
|
|
92
|
-
description: "
|
|
52
|
+
metafile = Option.Boolean("--metafile", {
|
|
53
|
+
description: "Generate metafile"
|
|
93
54
|
});
|
|
94
|
-
|
|
95
|
-
description: "
|
|
55
|
+
cache = Option.Boolean("--cache", {
|
|
56
|
+
description: "Enable cache"
|
|
96
57
|
});
|
|
97
58
|
async execute() {
|
|
98
59
|
try {
|
|
99
|
-
const {
|
|
60
|
+
const { cache = true, metafile = false, dev = false } = this;
|
|
100
61
|
const config = await loadConfig();
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
cache
|
|
104
|
-
|
|
62
|
+
const options = ["android", "ios"].map((platform) => ({
|
|
63
|
+
dev,
|
|
64
|
+
cache,
|
|
65
|
+
metafile,
|
|
66
|
+
platform,
|
|
67
|
+
outfile: `bundle.${platform}.js`
|
|
68
|
+
}));
|
|
69
|
+
await BuildUtils.buildAll(options, { config, plugins: [statusPlugin] });
|
|
105
70
|
return 0;
|
|
106
71
|
} catch (error) {
|
|
107
72
|
console.error(error);
|
|
@@ -194,130 +159,42 @@ var HermesCommand = class extends Command2 {
|
|
|
194
159
|
};
|
|
195
160
|
|
|
196
161
|
// src/commands/DevCommand/DevCommand.ts
|
|
197
|
-
import
|
|
198
|
-
import * as mpack from "@granite-js/mpack";
|
|
199
|
-
import { resolvePlugins as resolvePlugins2 } from "@granite-js/plugin-core";
|
|
162
|
+
import { runServer, EXPERIMENTAL__server } from "@granite-js/mpack";
|
|
200
163
|
import { Command as Command3, Option as Option3 } from "clipanion";
|
|
201
164
|
import Debug from "debug";
|
|
202
|
-
|
|
203
|
-
// src/config/mergeTransformFromPlugins.ts
|
|
204
|
-
async function mergeTransformFromPlugins(plugins) {
|
|
205
|
-
const mergedTransformFunctions = plugins.reduce(
|
|
206
|
-
(acc, plugin) => {
|
|
207
|
-
if (plugin.transformSync) {
|
|
208
|
-
acc.transformSync.push(plugin.transformSync);
|
|
209
|
-
}
|
|
210
|
-
if (plugin.transformAsync) {
|
|
211
|
-
acc.transformAsync.push(plugin.transformAsync);
|
|
212
|
-
}
|
|
213
|
-
return acc;
|
|
214
|
-
},
|
|
215
|
-
{
|
|
216
|
-
transformSync: [],
|
|
217
|
-
transformAsync: []
|
|
218
|
-
}
|
|
219
|
-
);
|
|
220
|
-
if (mergedTransformFunctions.transformSync.length === 0 && mergedTransformFunctions.transformAsync.length > 0) {
|
|
221
|
-
console.warn(
|
|
222
|
-
`Metro is only supported 'transformSync', but ${mergedTransformFunctions.transformAsync.length} 'transformAsync' are detected and it will be ignored.`
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
return {
|
|
226
|
-
transformSync: (id, code) => {
|
|
227
|
-
return mergedTransformFunctions.transformSync.reduce((acc, transform) => transform?.(id, acc) ?? acc, code);
|
|
228
|
-
},
|
|
229
|
-
transformAsync: async (id, code) => {
|
|
230
|
-
return mergedTransformFunctions.transformAsync.reduce(async (acc, transform) => {
|
|
231
|
-
return await transform?.(id, await acc) ?? acc;
|
|
232
|
-
}, Promise.resolve(code));
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
// src/commands/DevCommand/DevCommand.ts
|
|
238
165
|
var debug = Debug("cli");
|
|
239
|
-
var DEFAULT_HOST = "0.0.0.0";
|
|
240
|
-
var DEFAULT_LOCALHOST_PORT = 8081;
|
|
241
166
|
var DevCommand = class extends Command3 {
|
|
242
167
|
static paths = [[`dev`]];
|
|
243
168
|
static usage = Command3.Usage({
|
|
244
169
|
category: "Development",
|
|
245
|
-
description: "Granite
|
|
246
|
-
examples: [["
|
|
170
|
+
description: "Run Granite development server",
|
|
171
|
+
examples: [["Run Granite development server", "granite dev"]]
|
|
247
172
|
});
|
|
248
173
|
host = Option3.String("--host");
|
|
249
174
|
port = Option3.String("--port");
|
|
250
175
|
disableEmbeddedReactDevTools = Option3.Boolean("--disable-embedded-react-devtools", false);
|
|
251
176
|
// mpack dev-server
|
|
252
177
|
experimentalMode = Option3.Boolean("--experimental-mode");
|
|
253
|
-
preloadBundle = Option3.String("--preload-bundle", {
|
|
254
|
-
description: "Preload \uD560 \uBC88\uB4E4 \uD30C\uC77C\uC758 \uACBD\uB85C"
|
|
255
|
-
});
|
|
256
178
|
async execute() {
|
|
257
179
|
try {
|
|
180
|
+
process.env.MPACK_DEV_SERVER = "true";
|
|
258
181
|
const config = await loadConfig();
|
|
259
182
|
const serverOptions = {
|
|
260
183
|
host: this.host,
|
|
261
184
|
port: this.port ? parseInt(this.port, 10) : void 0
|
|
262
185
|
};
|
|
263
|
-
assert2(config?.appName, "\uC571 \uC774\uB984\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4");
|
|
264
186
|
debug("StartCommand", {
|
|
265
187
|
...serverOptions,
|
|
266
188
|
disableEmbeddedReactDevTools: this.disableEmbeddedReactDevTools,
|
|
267
|
-
experimentalMode: this.experimentalMode
|
|
268
|
-
preloadBundle: this.preloadBundle
|
|
189
|
+
experimentalMode: this.experimentalMode
|
|
269
190
|
});
|
|
270
191
|
if (this.experimentalMode) {
|
|
271
|
-
|
|
272
|
-
const mpackDevServerConfig = mpackConfig?.devServer;
|
|
273
|
-
assert2(mpackDevServerConfig, "mpack dev server \uC124\uC815\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4");
|
|
274
|
-
await mpack.experimental_runServer({
|
|
275
|
-
appName: config.appName,
|
|
276
|
-
scheme: config.scheme,
|
|
277
|
-
devServerConfig: mpackDevServerConfig,
|
|
278
|
-
host: serverOptions.host,
|
|
279
|
-
port: serverOptions.port,
|
|
280
|
-
preloadBundle: this.preloadBundle
|
|
281
|
-
});
|
|
192
|
+
await EXPERIMENTAL__server({ config, ...serverOptions });
|
|
282
193
|
} else {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
const additionalMetroConfig = {
|
|
286
|
-
...config.metro,
|
|
287
|
-
transformSync: mergedTransform?.transformSync
|
|
288
|
-
};
|
|
289
|
-
for (const preHandler of resolvedPlugins.devServer.preHandlers) {
|
|
290
|
-
debug("preHandler", preHandler);
|
|
291
|
-
await preHandler?.({
|
|
292
|
-
host: serverOptions.host || DEFAULT_HOST,
|
|
293
|
-
port: serverOptions.port || DEFAULT_LOCALHOST_PORT,
|
|
294
|
-
appName: config.appName,
|
|
295
|
-
outdir: config.outdir,
|
|
296
|
-
cwd: config.cwd,
|
|
297
|
-
entryFile: config.entryFile
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
await mpack.runServer({
|
|
301
|
-
cwd: config.cwd,
|
|
302
|
-
host: serverOptions.host,
|
|
303
|
-
port: serverOptions.port,
|
|
304
|
-
middlewares: config.mpack.devServer.middlewares,
|
|
305
|
-
config: config.mpack.devServer.config,
|
|
306
|
-
onServerReady: async () => {
|
|
307
|
-
for (const postHandler of resolvedPlugins.devServer.postHandlers) {
|
|
308
|
-
debug("postHandler", postHandler);
|
|
309
|
-
await postHandler?.({
|
|
310
|
-
host: serverOptions.host || DEFAULT_HOST,
|
|
311
|
-
port: serverOptions.port || DEFAULT_LOCALHOST_PORT,
|
|
312
|
-
appName: config.appName,
|
|
313
|
-
outdir: config.outdir,
|
|
314
|
-
cwd: config.cwd,
|
|
315
|
-
entryFile: config.entryFile
|
|
316
|
-
});
|
|
317
|
-
}
|
|
318
|
-
},
|
|
194
|
+
await runServer({
|
|
195
|
+
config,
|
|
319
196
|
enableEmbeddedReactDevTools: !this.disableEmbeddedReactDevTools,
|
|
320
|
-
|
|
197
|
+
...serverOptions
|
|
321
198
|
});
|
|
322
199
|
}
|
|
323
200
|
} catch (error) {
|
|
@@ -333,336 +210,80 @@ var DevCommand = class extends Command3 {
|
|
|
333
210
|
// src/config/defineConfig.ts
|
|
334
211
|
import path4 from "path";
|
|
335
212
|
import {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
213
|
+
resolvePlugins,
|
|
214
|
+
mergeConfig,
|
|
215
|
+
pluginConfigSchema
|
|
216
|
+
} from "@granite-js/plugin-core";
|
|
340
217
|
import { getPackageRoot as getPackageRoot2 } from "@granite-js/utils";
|
|
341
|
-
import { merge } from "es-toolkit";
|
|
342
|
-
import { z } from "zod";
|
|
343
|
-
|
|
344
|
-
// src/config/mergeConfigFromPlugins.ts
|
|
345
|
-
import { flattenPlugins } from "@granite-js/plugin-core";
|
|
346
|
-
import { mergeWith } from "es-toolkit";
|
|
347
|
-
function concatArray(objValue, srcValue) {
|
|
348
|
-
if (Array.isArray(objValue) && Array.isArray(srcValue)) {
|
|
349
|
-
return objValue.concat(srcValue);
|
|
350
|
-
}
|
|
351
|
-
return;
|
|
352
|
-
}
|
|
353
|
-
function mergeMetroConfig(objValue, srcValue, key) {
|
|
354
|
-
if (key === "getPolyfills" && typeof objValue === "function" && typeof srcValue === "function") {
|
|
355
|
-
return () => [...objValue(), ...srcValue()];
|
|
356
|
-
}
|
|
357
|
-
return void 0;
|
|
358
|
-
}
|
|
359
|
-
function mergeEsbuildConfig(objValue, srcValue, key) {
|
|
360
|
-
if (key === "banner" && typeof objValue === "object" && typeof srcValue === "object") {
|
|
361
|
-
return Object.entries(srcValue ?? {}).reduce(
|
|
362
|
-
(acc, [key2, value]) => ({
|
|
363
|
-
...acc,
|
|
364
|
-
[key2]: [acc[key2], value].join("\n")
|
|
365
|
-
}),
|
|
366
|
-
objValue ?? {}
|
|
367
|
-
);
|
|
368
|
-
}
|
|
369
|
-
if (key === "footer" && typeof objValue === "object" && typeof srcValue === "object") {
|
|
370
|
-
return Object.entries(srcValue ?? {}).reduce(
|
|
371
|
-
(acc, [key2, value]) => ({
|
|
372
|
-
...acc,
|
|
373
|
-
[key2]: [acc[key2], value].join("\n")
|
|
374
|
-
}),
|
|
375
|
-
objValue ?? {}
|
|
376
|
-
);
|
|
377
|
-
}
|
|
378
|
-
return void 0;
|
|
379
|
-
}
|
|
380
|
-
function combineComparers(...fns) {
|
|
381
|
-
return (targetValue, sourceValue, key, target, source) => {
|
|
382
|
-
for (const fn of fns) {
|
|
383
|
-
const result = fn(targetValue, sourceValue, key, target, source);
|
|
384
|
-
if (result !== void 0) {
|
|
385
|
-
return result;
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
return void 0;
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
async function mergeConfigFromPlugins(plugins) {
|
|
392
|
-
const pluginsResolved = await flattenPlugins(plugins);
|
|
393
|
-
return pluginsResolved.reduce(
|
|
394
|
-
(acc, plugin) => mergeWith(acc, plugin.config ?? {}, combineComparers(concatArray, mergeMetroConfig, mergeEsbuildConfig)),
|
|
395
|
-
{}
|
|
396
|
-
);
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
// src/presets/service.ts
|
|
400
218
|
import { isNotNil as isNotNil2 } from "es-toolkit";
|
|
401
219
|
|
|
402
|
-
// src/
|
|
403
|
-
|
|
404
|
-
load: (args) => {
|
|
405
|
-
return { loader: "js", contents: `module.exports = __granite_require__('${args.path}');` };
|
|
406
|
-
}
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
// src/presets/common/optimizations.ts
|
|
410
|
-
var resolveTslibEsm = () => ({
|
|
411
|
-
from: "tslib",
|
|
412
|
-
to: async ({ resolve, args }) => {
|
|
413
|
-
const result = await resolve(args.path, {
|
|
414
|
-
kind: args.kind,
|
|
415
|
-
resolveDir: args.resolveDir
|
|
416
|
-
});
|
|
417
|
-
if (result.errors.length) {
|
|
418
|
-
throw new Error(`resolveTslibEsm: ${args.path}`);
|
|
419
|
-
}
|
|
420
|
-
return result.path.replace(/(tslib\.js|modules\/index\.js)$/, "tslib.es6.js");
|
|
421
|
-
},
|
|
422
|
-
exact: true
|
|
423
|
-
});
|
|
424
|
-
var optimizations = { resolveTslibEsm };
|
|
425
|
-
|
|
426
|
-
// src/presets/common/preludeScripts.ts
|
|
220
|
+
// src/config/graniteGlobals.ts
|
|
221
|
+
import fs from "fs";
|
|
427
222
|
import path3 from "path";
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
paths: [rootDir]
|
|
432
|
-
})
|
|
433
|
-
);
|
|
434
|
-
return [
|
|
435
|
-
...__require(path3.join(reactNativePath, "rn-get-polyfills"))(),
|
|
436
|
-
path3.join(reactNativePath, "Libraries/Core/InitializeCore.js")
|
|
437
|
-
];
|
|
438
|
-
}
|
|
439
|
-
function getGlobalVariables({ dev = true }) {
|
|
440
|
-
return {
|
|
441
|
-
global: "window",
|
|
442
|
-
__DEV__: JSON.stringify(dev),
|
|
443
|
-
"process.env.NODE_ENV": JSON.stringify(dev ? "development" : "production")
|
|
444
|
-
};
|
|
445
|
-
}
|
|
446
|
-
var preludePresets = {
|
|
447
|
-
globalVariables: ({ dev }) => {
|
|
448
|
-
return [
|
|
449
|
-
"var __BUNDLE_START_TIME__=this.nativePerformanceNow?nativePerformanceNow():Date.now();",
|
|
450
|
-
`var __DEV__=${JSON.stringify(dev)};`,
|
|
451
|
-
`var window=typeof globalThis!=='undefined'?globalThis:typeof global!=='undefined'?global:typeof window!=='undefined'?window:this;`
|
|
452
|
-
].join("\n");
|
|
453
|
-
},
|
|
454
|
-
graniteSharedEnvironment: ({ buildNumber }) => {
|
|
455
|
-
return [
|
|
456
|
-
"window.__granite = window.__granite || {};",
|
|
457
|
-
`window.__granite.shared = { buildNumber: ${JSON.stringify(buildNumber)} };`
|
|
458
|
-
].join("\n");
|
|
459
|
-
},
|
|
460
|
-
graniteAppEnvironment: ({
|
|
461
|
-
appName,
|
|
462
|
-
scheme,
|
|
463
|
-
buildNumber
|
|
464
|
-
}) => {
|
|
465
|
-
return [
|
|
466
|
-
"window.__granite = window.__granite || {};",
|
|
467
|
-
`window.__granite.app = { name: ${JSON.stringify(appName)}, scheme: ${JSON.stringify(scheme)}, buildNumber: ${JSON.stringify(buildNumber)} };`
|
|
468
|
-
].join("\n");
|
|
469
|
-
}
|
|
470
|
-
};
|
|
471
|
-
|
|
472
|
-
// src/presets/common/babelConditions.ts
|
|
473
|
-
var babelConditions = [
|
|
474
|
-
/**
|
|
475
|
-
* @TODO
|
|
476
|
-
* zod 에서 hermes 가 지원하지 않는 RegExp 를 사용 중이며,
|
|
477
|
-
* 대응 가능한 swc 구성/플러그인이 존재하지 않기에 babel 로 트랜스파일하도록 합니다
|
|
478
|
-
*
|
|
479
|
-
* @see zod {@link https://github.com/colinhacks/zod/issues/2302}
|
|
480
|
-
*/
|
|
481
|
-
(_code, path5) => path5.includes("node_modules/zod")
|
|
482
|
-
];
|
|
483
|
-
|
|
484
|
-
// src/presets/utils/getBuildNumber.ts
|
|
485
|
-
function getBuildNumber() {
|
|
486
|
-
const date = /* @__PURE__ */ new Date();
|
|
487
|
-
const year = date.getFullYear();
|
|
488
|
-
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
489
|
-
const day = String(date.getDate()).padStart(2, "0");
|
|
490
|
-
const hours = String(date.getHours()).padStart(2, "0");
|
|
491
|
-
const minutes = String(date.getMinutes()).padStart(2, "0");
|
|
492
|
-
const seconds = String(date.getSeconds()).padStart(2, "0");
|
|
493
|
-
return `${year}${month}${day}${hours}${minutes}${seconds}`;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
// src/presets/service.ts
|
|
497
|
-
var DEFAULT_OPTIMIZATION_OPTIONS = {
|
|
498
|
-
"tslib-esm": false
|
|
499
|
-
};
|
|
500
|
-
function commonResolver({ optimization = DEFAULT_OPTIMIZATION_OPTIONS }) {
|
|
501
|
-
return {
|
|
502
|
-
alias: [
|
|
503
|
-
...[
|
|
504
|
-
"@react-navigation/native-stack",
|
|
505
|
-
"@react-navigation/native",
|
|
506
|
-
"@react-native-async-storage/async-storage",
|
|
507
|
-
"@shopify/flash-list",
|
|
508
|
-
"lottie-react-native",
|
|
509
|
-
"react-native-safe-area-context",
|
|
510
|
-
"react-native-screens",
|
|
511
|
-
"react-native-fast-image",
|
|
512
|
-
"react-native-svg",
|
|
513
|
-
"react-native-webview",
|
|
514
|
-
"react-native-video",
|
|
515
|
-
"react-native",
|
|
516
|
-
"react",
|
|
517
|
-
"react-native-gesture-handler",
|
|
518
|
-
"react-native-pager-view",
|
|
519
|
-
"@react-native-community/blur"
|
|
520
|
-
].map((module) => ({ from: module, to: `granite-require:${module}`, exact: true })),
|
|
521
|
-
optimization["tslib-esm"] ? optimizations.resolveTslibEsm() : null
|
|
522
|
-
].filter(isNotNil2),
|
|
523
|
-
protocols: {
|
|
524
|
-
"granite-require": graniteRequireProtocol
|
|
525
|
-
}
|
|
526
|
-
};
|
|
527
|
-
}
|
|
528
|
-
function getCommonServicePreset(context, { optimization = DEFAULT_OPTIMIZATION_OPTIONS }) {
|
|
529
|
-
const { dev } = context;
|
|
530
|
-
const buildNumber = getBuildNumber();
|
|
223
|
+
import { getLocalTempDirectoryPath, prepareLocalDirectory } from "@granite-js/utils";
|
|
224
|
+
function prepareGraniteGlobalsScript(config) {
|
|
225
|
+
const filePath = writeGraniteGlobalsScript(config);
|
|
531
226
|
return {
|
|
532
|
-
resolver: commonResolver({ optimization }),
|
|
533
227
|
esbuild: {
|
|
534
|
-
|
|
535
|
-
* React Native 및 Granite 앱에서 사용되는 전역변수
|
|
536
|
-
*/
|
|
537
|
-
define: getGlobalVariables({ dev }),
|
|
538
|
-
banner: {
|
|
539
|
-
js: [
|
|
540
|
-
preludePresets.graniteAppEnvironment({
|
|
541
|
-
appName: context.appName,
|
|
542
|
-
scheme: context.scheme,
|
|
543
|
-
buildNumber
|
|
544
|
-
}),
|
|
545
|
-
// symbol-asynciterator polyfill (ES5)
|
|
546
|
-
`(function(){if(typeof Symbol!=="undefined"&&!Symbol.asyncIterator){Symbol.asyncIterator=Symbol.for("@@asyncIterator")}})();`
|
|
547
|
-
].join("\n")
|
|
548
|
-
}
|
|
228
|
+
prelude: [filePath]
|
|
549
229
|
},
|
|
550
|
-
|
|
551
|
-
|
|
230
|
+
metro: {
|
|
231
|
+
serializer: {
|
|
232
|
+
getPolyfills: () => [filePath]
|
|
233
|
+
}
|
|
552
234
|
}
|
|
553
235
|
};
|
|
554
236
|
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
return
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
js: [preludePresets.globalVariables({ dev }), preludePresets.graniteSharedEnvironment({ buildNumber })].join(
|
|
568
|
-
"\n"
|
|
569
|
-
)
|
|
570
|
-
},
|
|
571
|
-
prelude: [...getReactNativeSetupScripts(rootDir)]
|
|
572
|
-
},
|
|
573
|
-
babel: {
|
|
574
|
-
conditions: babelConditions
|
|
575
|
-
}
|
|
576
|
-
};
|
|
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");
|
|
577
249
|
}
|
|
578
|
-
var shared = () => (context) => {
|
|
579
|
-
return getCommonSharedPreset(context);
|
|
580
|
-
};
|
|
581
250
|
|
|
582
251
|
// src/config/defineConfig.ts
|
|
583
|
-
var graniteConfigSchema = z.object({
|
|
584
|
-
appName: z.string(),
|
|
585
|
-
scheme: z.string(),
|
|
586
|
-
plugins: z.custom(),
|
|
587
|
-
outdir: z.string().default("dist"),
|
|
588
|
-
entryFile: z.string().default("./src/_app.tsx"),
|
|
589
|
-
cwd: z.string().default(process.cwd()),
|
|
590
|
-
mpack: mpackConfigScheme.optional(),
|
|
591
|
-
babel: babelConfigSchema.optional(),
|
|
592
|
-
esbuild: esbuildConfigSchema.optional(),
|
|
593
|
-
metro: z.custom().optional(),
|
|
594
|
-
INTERNAL__useSharedPreset: z.boolean().optional()
|
|
595
|
-
});
|
|
596
252
|
var defineConfig = async (config) => {
|
|
597
|
-
const
|
|
598
|
-
const
|
|
599
|
-
const
|
|
600
|
-
const
|
|
601
|
-
const entryFile =
|
|
602
|
-
const
|
|
603
|
-
const
|
|
604
|
-
const
|
|
605
|
-
const
|
|
606
|
-
const
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
babel,
|
|
616
|
-
platform,
|
|
617
|
-
entry: entryFile,
|
|
618
|
-
outfile: path4.join(outdir, `bundle.${platform}.js`),
|
|
619
|
-
transformSync: mergedTransform?.transformSync,
|
|
620
|
-
transformAsync: mergedTransform?.transformAsync
|
|
621
|
-
}
|
|
622
|
-
});
|
|
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, ...buildConfig } = mergedConfig ?? {};
|
|
623
271
|
return {
|
|
624
|
-
|
|
272
|
+
cwd,
|
|
273
|
+
entryFile,
|
|
274
|
+
appName,
|
|
275
|
+
scheme,
|
|
625
276
|
outdir,
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
scheme,
|
|
632
|
-
services: {
|
|
633
|
-
/* TODO: Plugin 구조로 변경 필요 */
|
|
634
|
-
sentry: {
|
|
635
|
-
enabled: false
|
|
636
|
-
}
|
|
637
|
-
},
|
|
638
|
-
devServer: {
|
|
639
|
-
presets: [buildPreset()],
|
|
640
|
-
build: {
|
|
641
|
-
entry: entryFile
|
|
642
|
-
}
|
|
643
|
-
},
|
|
644
|
-
tasks: []
|
|
645
|
-
}
|
|
646
|
-
},
|
|
647
|
-
build: {
|
|
648
|
-
config: {
|
|
649
|
-
appName,
|
|
650
|
-
scheme,
|
|
651
|
-
services: {
|
|
652
|
-
/* TODO: Plugin 구조로 변경 필요 */
|
|
653
|
-
sentry: {
|
|
654
|
-
enabled: false
|
|
655
|
-
}
|
|
656
|
-
},
|
|
657
|
-
concurrency: 2,
|
|
658
|
-
tasks: [createTask("ios"), createTask("android")]
|
|
659
|
-
}
|
|
660
|
-
}
|
|
277
|
+
devServer,
|
|
278
|
+
pluginHooks,
|
|
279
|
+
build: {
|
|
280
|
+
...buildConfig,
|
|
281
|
+
entry: entryFile
|
|
661
282
|
},
|
|
662
283
|
metro: {
|
|
663
284
|
...metro,
|
|
664
|
-
babelConfig: babel,
|
|
665
|
-
transformSync:
|
|
285
|
+
babelConfig: mergedConfig?.babel,
|
|
286
|
+
transformSync: mergedConfig?.transformer?.transformSync
|
|
666
287
|
}
|
|
667
288
|
};
|
|
668
289
|
};
|
|
@@ -686,10 +307,7 @@ async function initialize() {
|
|
|
686
307
|
cli.runExit(process.argv.slice(2));
|
|
687
308
|
}
|
|
688
309
|
export {
|
|
689
|
-
commonResolver,
|
|
690
310
|
defineConfig,
|
|
691
|
-
getGlobalVariables,
|
|
692
311
|
initialize,
|
|
693
|
-
loadConfig
|
|
694
|
-
service
|
|
312
|
+
loadConfig
|
|
695
313
|
};
|
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.8",
|
|
5
5
|
"description": "The Granite CLI",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"@types/debug": "^4",
|
|
37
37
|
"@types/node": "^22.10.2",
|
|
38
38
|
"@types/serve-static": "^1",
|
|
39
|
-
"esbuild": "
|
|
39
|
+
"esbuild": "0.25.8",
|
|
40
40
|
"eslint": "^9.7.0",
|
|
41
41
|
"ts-prune": "^0.10.3",
|
|
42
42
|
"tsup": "^8.5.0",
|
|
@@ -44,9 +44,9 @@
|
|
|
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.8",
|
|
48
|
+
"@granite-js/plugin-core": "0.1.8",
|
|
49
|
+
"@granite-js/utils": "0.1.8",
|
|
50
50
|
"@inquirer/prompts": "^7.2.3",
|
|
51
51
|
"@shopify/semaphore": "^3.1.0",
|
|
52
52
|
"chalk": "^4",
|