@granite-js/cli 2.5.4 → 3.0.0
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 +39 -0
- package/dist/index.cjs +109 -51
- package/dist/index.js +105 -47
- package/package.json +3 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @granite-js/cli
|
|
2
2
|
|
|
3
|
+
## 3.0.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @granite-js/config@3.0.0
|
|
8
|
+
- @granite-js/utils@3.0.0
|
|
9
|
+
|
|
10
|
+
## 2.5.5
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- @granite-js/mpack@2.5.5
|
|
15
|
+
- @granite-js/plugin-core@2.5.5
|
|
16
|
+
- @granite-js/utils@2.5.5
|
|
17
|
+
|
|
3
18
|
## 2.5.4
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -121,6 +136,30 @@
|
|
|
121
136
|
- @granite-js/plugin-core@2.0.0
|
|
122
137
|
- @granite-js/utils@2.0.0
|
|
123
138
|
|
|
139
|
+
## 1.0.45
|
|
140
|
+
|
|
141
|
+
### Patch Changes
|
|
142
|
+
|
|
143
|
+
- @granite-js/mpack@1.0.45
|
|
144
|
+
- @granite-js/plugin-core@1.0.45
|
|
145
|
+
- @granite-js/utils@1.0.45
|
|
146
|
+
|
|
147
|
+
## 1.0.44
|
|
148
|
+
|
|
149
|
+
### Patch Changes
|
|
150
|
+
|
|
151
|
+
- @granite-js/mpack@1.0.44
|
|
152
|
+
- @granite-js/plugin-core@1.0.44
|
|
153
|
+
- @granite-js/utils@1.0.44
|
|
154
|
+
|
|
155
|
+
## 1.0.43
|
|
156
|
+
|
|
157
|
+
### Patch Changes
|
|
158
|
+
|
|
159
|
+
- @granite-js/mpack@1.0.43
|
|
160
|
+
- @granite-js/plugin-core@1.0.43
|
|
161
|
+
- @granite-js/utils@1.0.43
|
|
162
|
+
|
|
124
163
|
## 1.0.42
|
|
125
164
|
|
|
126
165
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -36,23 +36,59 @@ module.exports = __toCommonJS(index_exports);
|
|
|
36
36
|
var import_clipanion4 = require("clipanion");
|
|
37
37
|
|
|
38
38
|
// src/commands/BuildCommand/BuildCommand.ts
|
|
39
|
-
var
|
|
40
|
-
var import_plugins = require("@granite-js/mpack/plugins");
|
|
41
|
-
var import_plugin_core = require("@granite-js/plugin-core");
|
|
39
|
+
var import_config = require("@granite-js/config");
|
|
42
40
|
var import_clipanion = require("clipanion");
|
|
41
|
+
var import_es_toolkit = require("es-toolkit");
|
|
43
42
|
|
|
44
43
|
// src/utils/command.ts
|
|
45
44
|
var import_chalk = __toESM(require("chalk"), 1);
|
|
46
45
|
function errorHandler(error) {
|
|
47
46
|
const label = import_chalk.default.red("Error");
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
47
|
+
const seen = /* @__PURE__ */ new Set();
|
|
48
|
+
function printError(error2) {
|
|
49
|
+
if (seen.has(error2)) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
seen.add(error2);
|
|
53
|
+
if (error2 instanceof Error) {
|
|
54
|
+
console.error(label, error2.message);
|
|
55
|
+
if (error2 instanceof AggregateError) {
|
|
56
|
+
for (const reason of error2.errors) {
|
|
57
|
+
printError(reason);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (error2.cause !== void 0) {
|
|
61
|
+
printError(error2.cause);
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
console.error(label, "Unknown error", error2 ?? "");
|
|
65
|
+
}
|
|
52
66
|
}
|
|
67
|
+
printError(error);
|
|
53
68
|
return 1 /* ERROR */;
|
|
54
69
|
}
|
|
55
70
|
|
|
71
|
+
// src/utils/printLogo.ts
|
|
72
|
+
var import_chalk2 = __toESM(require("chalk"), 1);
|
|
73
|
+
var LOGO = [
|
|
74
|
+
" \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557",
|
|
75
|
+
"\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2551\u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D",
|
|
76
|
+
"\u2588\u2588\u2551 \u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2554\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2557 ",
|
|
77
|
+
"\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2551\u255A\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u255D ",
|
|
78
|
+
"\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557",
|
|
79
|
+
" \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D"
|
|
80
|
+
];
|
|
81
|
+
var GREETING_MESSAGE = "Welcome to Granite";
|
|
82
|
+
function printLogo() {
|
|
83
|
+
const maxLength = LOGO.reduce((prev, line) => Math.max(line.length, prev), 0);
|
|
84
|
+
console.log();
|
|
85
|
+
console.log(LOGO.join("\n"));
|
|
86
|
+
const padding = new Array(Math.floor(maxLength / 2 - GREETING_MESSAGE.length / 2)).fill(" ").join("");
|
|
87
|
+
console.log(`
|
|
88
|
+
${padding}${import_chalk2.default.blue(GREETING_MESSAGE)}
|
|
89
|
+
`);
|
|
90
|
+
}
|
|
91
|
+
|
|
56
92
|
// src/commands/BuildCommand/BuildCommand.ts
|
|
57
93
|
var BuildCommand = class extends import_clipanion.Command {
|
|
58
94
|
static paths = [[`build`]];
|
|
@@ -67,24 +103,41 @@ var BuildCommand = class extends import_clipanion.Command {
|
|
|
67
103
|
dev = import_clipanion.Option.Boolean("--dev", {
|
|
68
104
|
description: "Build in development mode"
|
|
69
105
|
});
|
|
70
|
-
|
|
71
|
-
description: "
|
|
72
|
-
});
|
|
73
|
-
cache = import_clipanion.Option.Boolean("--cache", {
|
|
74
|
-
description: "Enable cache"
|
|
106
|
+
resetCache = import_clipanion.Option.Boolean("--reset-cache", false, {
|
|
107
|
+
description: "Clear the bundler cache before building"
|
|
75
108
|
});
|
|
76
109
|
async execute() {
|
|
110
|
+
printLogo();
|
|
77
111
|
try {
|
|
78
|
-
const { configFile,
|
|
79
|
-
const config = await (0,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
cache
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
112
|
+
const { configFile, dev = false } = this;
|
|
113
|
+
const config = await (0, import_config.loadConfig)({ configFile });
|
|
114
|
+
if (this.resetCache) {
|
|
115
|
+
await config.bundler.resetCache();
|
|
116
|
+
console.log("The transform cache was reset");
|
|
117
|
+
}
|
|
118
|
+
const buildOptions = ["android", "ios"].map(
|
|
119
|
+
(platform) => ({ platform, dev })
|
|
120
|
+
);
|
|
121
|
+
const semaphore = new import_es_toolkit.Semaphore(buildOptions.length);
|
|
122
|
+
const results = await Promise.allSettled(
|
|
123
|
+
buildOptions.map(async (buildOption) => {
|
|
124
|
+
await semaphore.acquire();
|
|
125
|
+
try {
|
|
126
|
+
return await config.bundler.runBuild(buildOption);
|
|
127
|
+
} catch (error) {
|
|
128
|
+
throw new Error(`Failed to build for ${buildOption.platform}`, { cause: error });
|
|
129
|
+
} finally {
|
|
130
|
+
semaphore.release();
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
);
|
|
134
|
+
const failures = results.filter((result) => result.status === "rejected");
|
|
135
|
+
if (failures.length > 0) {
|
|
136
|
+
throw new AggregateError(
|
|
137
|
+
failures.map((failure) => failure.reason),
|
|
138
|
+
"Granite build failed"
|
|
139
|
+
);
|
|
140
|
+
}
|
|
88
141
|
return 0 /* SUCCESS */;
|
|
89
142
|
} catch (error) {
|
|
90
143
|
return errorHandler(error);
|
|
@@ -94,14 +147,14 @@ var BuildCommand = class extends import_clipanion.Command {
|
|
|
94
147
|
|
|
95
148
|
// src/commands/HermesCommand/HermesCommand.ts
|
|
96
149
|
var import_path2 = __toESM(require("path"), 1);
|
|
97
|
-
var
|
|
150
|
+
var import_chalk3 = __toESM(require("chalk"), 1);
|
|
98
151
|
var import_clipanion2 = require("clipanion");
|
|
99
152
|
|
|
100
153
|
// src/utils/compileHbc.ts
|
|
101
154
|
var import_assert = __toESM(require("assert"), 1);
|
|
102
155
|
var import_os = __toESM(require("os"), 1);
|
|
103
156
|
var import_path = __toESM(require("path"), 1);
|
|
104
|
-
var
|
|
157
|
+
var import_es_toolkit2 = require("es-toolkit");
|
|
105
158
|
var import_execa = __toESM(require("execa"), 1);
|
|
106
159
|
var binary = {
|
|
107
160
|
Darwin: "react-native/sdks/hermesc/osx-bin/hermesc",
|
|
@@ -126,7 +179,7 @@ async function compileHbc({ rootDir, filePath, sourcemap }) {
|
|
|
126
179
|
"-out",
|
|
127
180
|
outfile,
|
|
128
181
|
filePath
|
|
129
|
-
].filter(
|
|
182
|
+
].filter(import_es_toolkit2.isNotNil)
|
|
130
183
|
);
|
|
131
184
|
return { outfile, sourcemapOutfile: sourcemap ? `${outfile}.map` : null };
|
|
132
185
|
}
|
|
@@ -163,9 +216,9 @@ var HermesCommand = class extends import_clipanion2.Command {
|
|
|
163
216
|
const rootDir = process.cwd();
|
|
164
217
|
const filePath = import_path2.default.resolve(rootDir, this.jsBundleFile);
|
|
165
218
|
const { outfile, sourcemapOutfile } = await compileHbc({ rootDir, filePath, sourcemap: this.sourcemap });
|
|
166
|
-
console.log(`\u2705 Compiled successfully: ${
|
|
219
|
+
console.log(`\u2705 Compiled successfully: ${import_chalk3.default.gray(outfile)}`);
|
|
167
220
|
if (sourcemapOutfile) {
|
|
168
|
-
console.log(`\u2705 Source map generated successfully: ${
|
|
221
|
+
console.log(`\u2705 Source map generated successfully: ${import_chalk3.default.gray(sourcemapOutfile)}`);
|
|
169
222
|
}
|
|
170
223
|
return 0 /* SUCCESS */;
|
|
171
224
|
} catch (error) {
|
|
@@ -175,11 +228,8 @@ var HermesCommand = class extends import_clipanion2.Command {
|
|
|
175
228
|
};
|
|
176
229
|
|
|
177
230
|
// src/commands/DevCommand/DevCommand.ts
|
|
178
|
-
var
|
|
179
|
-
var import_plugin_core2 = require("@granite-js/plugin-core");
|
|
231
|
+
var import_config2 = require("@granite-js/config");
|
|
180
232
|
var import_clipanion3 = require("clipanion");
|
|
181
|
-
var import_debug = __toESM(require("debug"), 1);
|
|
182
|
-
var debug = (0, import_debug.default)("cli");
|
|
183
233
|
var DevCommand = class extends import_clipanion3.Command {
|
|
184
234
|
static paths = [[`dev`]];
|
|
185
235
|
static usage = import_clipanion3.Command.Usage({
|
|
@@ -192,30 +242,38 @@ var DevCommand = class extends import_clipanion3.Command {
|
|
|
192
242
|
});
|
|
193
243
|
host = import_clipanion3.Option.String("--host");
|
|
194
244
|
port = import_clipanion3.Option.String("--port");
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
245
|
+
resetCache = import_clipanion3.Option.Boolean("--reset-cache", false, {
|
|
246
|
+
description: "Clear the bundler cache before starting the server"
|
|
247
|
+
});
|
|
248
|
+
clientLogs = import_clipanion3.Option.Boolean("--client-logs", false, {
|
|
249
|
+
description: "Enable JavaScript log streaming from connected apps"
|
|
250
|
+
});
|
|
198
251
|
async execute() {
|
|
252
|
+
printLogo();
|
|
199
253
|
try {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
254
|
+
const config = await (0, import_config2.loadConfig)({ configFile: this.configFile });
|
|
255
|
+
if (this.resetCache) {
|
|
256
|
+
await config.bundler.resetCache();
|
|
257
|
+
console.log("The transform cache was reset");
|
|
258
|
+
}
|
|
259
|
+
const port = this.port ? parseInt(this.port, 10) : void 0;
|
|
260
|
+
const server = await config.bundler.runServer({
|
|
261
|
+
port,
|
|
203
262
|
host: this.host,
|
|
204
|
-
|
|
205
|
-
};
|
|
206
|
-
debug("StartCommand", {
|
|
207
|
-
...serverOptions,
|
|
208
|
-
disableEmbeddedReactDevTools: this.disableEmbeddedReactDevTools,
|
|
209
|
-
experimentalMode: this.experimentalMode
|
|
263
|
+
clientLogs: this.clientLogs
|
|
210
264
|
});
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
})
|
|
218
|
-
|
|
265
|
+
const close = async () => {
|
|
266
|
+
process.removeListener("SIGINT", close);
|
|
267
|
+
process.removeListener("SIGTERM", close);
|
|
268
|
+
try {
|
|
269
|
+
await server.close();
|
|
270
|
+
process.exit(0 /* SUCCESS */);
|
|
271
|
+
} catch (error) {
|
|
272
|
+
process.exit(errorHandler(error));
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
process.once("SIGINT", close);
|
|
276
|
+
process.once("SIGTERM", close);
|
|
219
277
|
return 0 /* SUCCESS */;
|
|
220
278
|
} catch (error) {
|
|
221
279
|
return errorHandler(error);
|
package/dist/index.js
CHANGED
|
@@ -10,23 +10,59 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
10
10
|
import { Builtins, Cli } from "clipanion";
|
|
11
11
|
|
|
12
12
|
// src/commands/BuildCommand/BuildCommand.ts
|
|
13
|
-
import {
|
|
14
|
-
import { statusPlugin } from "@granite-js/mpack/plugins";
|
|
15
|
-
import { loadConfig } from "@granite-js/plugin-core";
|
|
13
|
+
import { loadConfig } from "@granite-js/config";
|
|
16
14
|
import { Command, Option } from "clipanion";
|
|
15
|
+
import { Semaphore } from "es-toolkit";
|
|
17
16
|
|
|
18
17
|
// src/utils/command.ts
|
|
19
18
|
import chalk from "chalk";
|
|
20
19
|
function errorHandler(error) {
|
|
21
20
|
const label = chalk.red("Error");
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
const seen = /* @__PURE__ */ new Set();
|
|
22
|
+
function printError(error2) {
|
|
23
|
+
if (seen.has(error2)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
seen.add(error2);
|
|
27
|
+
if (error2 instanceof Error) {
|
|
28
|
+
console.error(label, error2.message);
|
|
29
|
+
if (error2 instanceof AggregateError) {
|
|
30
|
+
for (const reason of error2.errors) {
|
|
31
|
+
printError(reason);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (error2.cause !== void 0) {
|
|
35
|
+
printError(error2.cause);
|
|
36
|
+
}
|
|
37
|
+
} else {
|
|
38
|
+
console.error(label, "Unknown error", error2 ?? "");
|
|
39
|
+
}
|
|
26
40
|
}
|
|
41
|
+
printError(error);
|
|
27
42
|
return 1 /* ERROR */;
|
|
28
43
|
}
|
|
29
44
|
|
|
45
|
+
// src/utils/printLogo.ts
|
|
46
|
+
import chalk2 from "chalk";
|
|
47
|
+
var LOGO = [
|
|
48
|
+
" \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557",
|
|
49
|
+
"\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2551\u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D",
|
|
50
|
+
"\u2588\u2588\u2551 \u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2554\u2588\u2588\u2557 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2557 ",
|
|
51
|
+
"\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2551\u255A\u2588\u2588\u2557\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u255D ",
|
|
52
|
+
"\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557",
|
|
53
|
+
" \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D"
|
|
54
|
+
];
|
|
55
|
+
var GREETING_MESSAGE = "Welcome to Granite";
|
|
56
|
+
function printLogo() {
|
|
57
|
+
const maxLength = LOGO.reduce((prev, line) => Math.max(line.length, prev), 0);
|
|
58
|
+
console.log();
|
|
59
|
+
console.log(LOGO.join("\n"));
|
|
60
|
+
const padding = new Array(Math.floor(maxLength / 2 - GREETING_MESSAGE.length / 2)).fill(" ").join("");
|
|
61
|
+
console.log(`
|
|
62
|
+
${padding}${chalk2.blue(GREETING_MESSAGE)}
|
|
63
|
+
`);
|
|
64
|
+
}
|
|
65
|
+
|
|
30
66
|
// src/commands/BuildCommand/BuildCommand.ts
|
|
31
67
|
var BuildCommand = class extends Command {
|
|
32
68
|
static paths = [[`build`]];
|
|
@@ -41,24 +77,41 @@ var BuildCommand = class extends Command {
|
|
|
41
77
|
dev = Option.Boolean("--dev", {
|
|
42
78
|
description: "Build in development mode"
|
|
43
79
|
});
|
|
44
|
-
|
|
45
|
-
description: "
|
|
46
|
-
});
|
|
47
|
-
cache = Option.Boolean("--cache", {
|
|
48
|
-
description: "Enable cache"
|
|
80
|
+
resetCache = Option.Boolean("--reset-cache", false, {
|
|
81
|
+
description: "Clear the bundler cache before building"
|
|
49
82
|
});
|
|
50
83
|
async execute() {
|
|
84
|
+
printLogo();
|
|
51
85
|
try {
|
|
52
|
-
const { configFile,
|
|
86
|
+
const { configFile, dev = false } = this;
|
|
53
87
|
const config = await loadConfig({ configFile });
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
cache
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
88
|
+
if (this.resetCache) {
|
|
89
|
+
await config.bundler.resetCache();
|
|
90
|
+
console.log("The transform cache was reset");
|
|
91
|
+
}
|
|
92
|
+
const buildOptions = ["android", "ios"].map(
|
|
93
|
+
(platform) => ({ platform, dev })
|
|
94
|
+
);
|
|
95
|
+
const semaphore = new Semaphore(buildOptions.length);
|
|
96
|
+
const results = await Promise.allSettled(
|
|
97
|
+
buildOptions.map(async (buildOption) => {
|
|
98
|
+
await semaphore.acquire();
|
|
99
|
+
try {
|
|
100
|
+
return await config.bundler.runBuild(buildOption);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
throw new Error(`Failed to build for ${buildOption.platform}`, { cause: error });
|
|
103
|
+
} finally {
|
|
104
|
+
semaphore.release();
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
);
|
|
108
|
+
const failures = results.filter((result) => result.status === "rejected");
|
|
109
|
+
if (failures.length > 0) {
|
|
110
|
+
throw new AggregateError(
|
|
111
|
+
failures.map((failure) => failure.reason),
|
|
112
|
+
"Granite build failed"
|
|
113
|
+
);
|
|
114
|
+
}
|
|
62
115
|
return 0 /* SUCCESS */;
|
|
63
116
|
} catch (error) {
|
|
64
117
|
return errorHandler(error);
|
|
@@ -68,7 +121,7 @@ var BuildCommand = class extends Command {
|
|
|
68
121
|
|
|
69
122
|
// src/commands/HermesCommand/HermesCommand.ts
|
|
70
123
|
import path2 from "path";
|
|
71
|
-
import
|
|
124
|
+
import chalk3 from "chalk";
|
|
72
125
|
import { Command as Command2, Option as Option2 } from "clipanion";
|
|
73
126
|
|
|
74
127
|
// src/utils/compileHbc.ts
|
|
@@ -137,9 +190,9 @@ var HermesCommand = class extends Command2 {
|
|
|
137
190
|
const rootDir = process.cwd();
|
|
138
191
|
const filePath = path2.resolve(rootDir, this.jsBundleFile);
|
|
139
192
|
const { outfile, sourcemapOutfile } = await compileHbc({ rootDir, filePath, sourcemap: this.sourcemap });
|
|
140
|
-
console.log(`\u2705 Compiled successfully: ${
|
|
193
|
+
console.log(`\u2705 Compiled successfully: ${chalk3.gray(outfile)}`);
|
|
141
194
|
if (sourcemapOutfile) {
|
|
142
|
-
console.log(`\u2705 Source map generated successfully: ${
|
|
195
|
+
console.log(`\u2705 Source map generated successfully: ${chalk3.gray(sourcemapOutfile)}`);
|
|
143
196
|
}
|
|
144
197
|
return 0 /* SUCCESS */;
|
|
145
198
|
} catch (error) {
|
|
@@ -149,11 +202,8 @@ var HermesCommand = class extends Command2 {
|
|
|
149
202
|
};
|
|
150
203
|
|
|
151
204
|
// src/commands/DevCommand/DevCommand.ts
|
|
152
|
-
import {
|
|
153
|
-
import { loadConfig as loadConfig2 } from "@granite-js/plugin-core";
|
|
205
|
+
import { loadConfig as loadConfig2 } from "@granite-js/config";
|
|
154
206
|
import { Command as Command3, Option as Option3 } from "clipanion";
|
|
155
|
-
import Debug from "debug";
|
|
156
|
-
var debug = Debug("cli");
|
|
157
207
|
var DevCommand = class extends Command3 {
|
|
158
208
|
static paths = [[`dev`]];
|
|
159
209
|
static usage = Command3.Usage({
|
|
@@ -166,30 +216,38 @@ var DevCommand = class extends Command3 {
|
|
|
166
216
|
});
|
|
167
217
|
host = Option3.String("--host");
|
|
168
218
|
port = Option3.String("--port");
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
219
|
+
resetCache = Option3.Boolean("--reset-cache", false, {
|
|
220
|
+
description: "Clear the bundler cache before starting the server"
|
|
221
|
+
});
|
|
222
|
+
clientLogs = Option3.Boolean("--client-logs", false, {
|
|
223
|
+
description: "Enable JavaScript log streaming from connected apps"
|
|
224
|
+
});
|
|
172
225
|
async execute() {
|
|
226
|
+
printLogo();
|
|
173
227
|
try {
|
|
174
|
-
process.env.MPACK_DEV_SERVER = "true";
|
|
175
228
|
const config = await loadConfig2({ configFile: this.configFile });
|
|
176
|
-
|
|
229
|
+
if (this.resetCache) {
|
|
230
|
+
await config.bundler.resetCache();
|
|
231
|
+
console.log("The transform cache was reset");
|
|
232
|
+
}
|
|
233
|
+
const port = this.port ? parseInt(this.port, 10) : void 0;
|
|
234
|
+
const server = await config.bundler.runServer({
|
|
235
|
+
port,
|
|
177
236
|
host: this.host,
|
|
178
|
-
|
|
179
|
-
};
|
|
180
|
-
debug("StartCommand", {
|
|
181
|
-
...serverOptions,
|
|
182
|
-
disableEmbeddedReactDevTools: this.disableEmbeddedReactDevTools,
|
|
183
|
-
experimentalMode: this.experimentalMode
|
|
237
|
+
clientLogs: this.clientLogs
|
|
184
238
|
});
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
})
|
|
192
|
-
|
|
239
|
+
const close = async () => {
|
|
240
|
+
process.removeListener("SIGINT", close);
|
|
241
|
+
process.removeListener("SIGTERM", close);
|
|
242
|
+
try {
|
|
243
|
+
await server.close();
|
|
244
|
+
process.exit(0 /* SUCCESS */);
|
|
245
|
+
} catch (error) {
|
|
246
|
+
process.exit(errorHandler(error));
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
process.once("SIGINT", close);
|
|
250
|
+
process.once("SIGTERM", close);
|
|
193
251
|
return 0 /* SUCCESS */;
|
|
194
252
|
} catch (error) {
|
|
195
253
|
return errorHandler(error);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@granite-js/cli",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "3.0.0",
|
|
5
5
|
"description": "The Granite CLI",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -55,9 +55,8 @@
|
|
|
55
55
|
"vitest": "^4.0.12"
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@granite-js/
|
|
59
|
-
"@granite-js/
|
|
60
|
-
"@granite-js/utils": "2.5.4",
|
|
58
|
+
"@granite-js/config": "3.0.0",
|
|
59
|
+
"@granite-js/utils": "3.0.0",
|
|
61
60
|
"@inquirer/prompts": "^7.2.3",
|
|
62
61
|
"@shopify/semaphore": "^3.1.0",
|
|
63
62
|
"chalk": "^4",
|