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