@naseej/blox 1.4.0 → 1.4.2
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/bin/run +19 -1
- package/bin/run.ts +3 -0
- package/dist/run.js +214 -129
- package/package.json +1 -1
package/bin/run
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const disableWarningFlag = '--disable-warning=DEP0190';
|
|
4
|
+
|
|
5
|
+
if (!process.execArgv.includes(disableWarningFlag)) {
|
|
6
|
+
const { spawn } = require('node:child_process');
|
|
7
|
+
const args = [disableWarningFlag, ...process.execArgv, ...process.argv.slice(1)];
|
|
8
|
+
|
|
9
|
+
const child = spawn(process.execPath, args, { stdio: 'inherit' });
|
|
10
|
+
child.on('exit', (code, signal) => {
|
|
11
|
+
if (signal) {
|
|
12
|
+
process.kill(process.pid, signal);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
process.exit(code ?? 0);
|
|
17
|
+
});
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
require('../dist/run');
|
package/bin/run.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { checkForCliUpdate } from '@/services/cliVersion';
|
|
1
2
|
import { cli } from '@/shared/command';
|
|
2
3
|
|
|
3
4
|
import { version } from '../package.json';
|
|
@@ -8,6 +9,8 @@ async function main() {
|
|
|
8
9
|
cli.option('-d, --debug', 'work in debug mode');
|
|
9
10
|
cli.option('-m, --minimal', 'work in minimal mode');
|
|
10
11
|
|
|
12
|
+
await checkForCliUpdate(version);
|
|
13
|
+
|
|
11
14
|
commands.forEach((cmd) => cli.addCommand(cmd));
|
|
12
15
|
cli.parse();
|
|
13
16
|
}
|
package/dist/run.js
CHANGED
|
@@ -22,6 +22,28 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
mod
|
|
23
23
|
));
|
|
24
24
|
|
|
25
|
+
// src/services/cliVersion.ts
|
|
26
|
+
var import_node_https = __toESM(require("https"));
|
|
27
|
+
var import_node_path2 = __toESM(require("path"));
|
|
28
|
+
var import_fs_extra2 = __toESM(require("fs-extra"));
|
|
29
|
+
var import_ms = __toESM(require("ms"));
|
|
30
|
+
|
|
31
|
+
// src/services/config.ts
|
|
32
|
+
var import_node_path = __toESM(require("path"));
|
|
33
|
+
var import_env_paths = __toESM(require("env-paths"));
|
|
34
|
+
var import_fs_extra = __toESM(require("fs-extra"));
|
|
35
|
+
|
|
36
|
+
// src/config/index.ts
|
|
37
|
+
var defaultConfig = {
|
|
38
|
+
registries: ["https://tfs.aas.com.sa/Medad/BLOX/_git/default-registry"]
|
|
39
|
+
};
|
|
40
|
+
var bloxFilePath = ".blox";
|
|
41
|
+
var blocksDir = "blocks";
|
|
42
|
+
|
|
43
|
+
// src/shared/logger.ts
|
|
44
|
+
var console2 = __toESM(require("console"));
|
|
45
|
+
var import_prompts = require("@clack/prompts");
|
|
46
|
+
|
|
25
47
|
// src/shared/command/index.ts
|
|
26
48
|
var import_extra_typings = require("@commander-js/extra-typings");
|
|
27
49
|
var import_extra_typings2 = require("@commander-js/extra-typings");
|
|
@@ -30,30 +52,145 @@ var option = (flags, description) => {
|
|
|
30
52
|
return new import_extra_typings.Option(flags, description);
|
|
31
53
|
};
|
|
32
54
|
|
|
33
|
-
// package.json
|
|
34
|
-
var version = "1.4.0";
|
|
35
|
-
|
|
36
|
-
// src/commands/add/index.ts
|
|
37
|
-
var import_fs_extra8 = __toESM(require("fs-extra"));
|
|
38
|
-
|
|
39
55
|
// src/config/runtime.ts
|
|
40
56
|
var isDebugMode = () => !!import_extra_typings2.program.opts()?.debug;
|
|
41
57
|
var isMinimalMode = () => !!import_extra_typings2.program.opts()?.minimal;
|
|
42
58
|
|
|
43
|
-
// src/
|
|
44
|
-
var
|
|
45
|
-
var
|
|
59
|
+
// src/shared/terminal/index.ts
|
|
60
|
+
var import_ansis = __toESM(require("ansis"));
|
|
61
|
+
var fmt = import_ansis.default;
|
|
46
62
|
|
|
47
|
-
// src/
|
|
48
|
-
var
|
|
49
|
-
|
|
63
|
+
// src/shared/logger.ts
|
|
64
|
+
var import_prompts2 = require("@clack/prompts");
|
|
65
|
+
var debug = (message) => {
|
|
66
|
+
if (!isDebugMode()) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (typeof message === "string") {
|
|
70
|
+
import_prompts.log.warn(message.trim());
|
|
71
|
+
} else {
|
|
72
|
+
console2.log(JSON.stringify(message));
|
|
73
|
+
}
|
|
50
74
|
};
|
|
51
|
-
var
|
|
52
|
-
|
|
75
|
+
var logWarningSection = (title, content) => {
|
|
76
|
+
const line = fmt.yellow("=".repeat(82));
|
|
77
|
+
console2.log("\n" + line);
|
|
78
|
+
console2.log(fmt.bold(fmt.yellow("\u25B2 " + title)));
|
|
79
|
+
content && console2.log("\n" + content);
|
|
80
|
+
console2.log(line + "\n");
|
|
81
|
+
};
|
|
82
|
+
var normalizeLogMessage = (content) => {
|
|
83
|
+
return content.split("\n").map((l) => l.trim()).filter(Boolean).join("\n");
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// src/services/config.ts
|
|
87
|
+
var appPaths = (0, import_env_paths.default)("blox", { suffix: "" });
|
|
88
|
+
var configFilePath = import_node_path.default.join(appPaths.config, "config.json");
|
|
89
|
+
var getLocalConfig = () => {
|
|
90
|
+
try {
|
|
91
|
+
return import_fs_extra.default.readJSONSync(configFilePath);
|
|
92
|
+
} catch {
|
|
93
|
+
return defaultConfig;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
var updateLocalConfig = (config) => {
|
|
97
|
+
debug("Update local config");
|
|
98
|
+
import_fs_extra.default.ensureFileSync(configFilePath);
|
|
99
|
+
const current = getLocalConfig();
|
|
100
|
+
import_fs_extra.default.writeJsonSync(configFilePath, { ...current, ...config });
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// src/services/cliVersion.ts
|
|
104
|
+
var registryUrl = "https://registry.npmjs.org/%40naseej%2Fblox";
|
|
105
|
+
var checkIntervalMs = (0, import_ms.default)("24h");
|
|
106
|
+
var cacheFilePath = import_node_path2.default.join(appPaths.cache, "cli-version.json");
|
|
107
|
+
var readCache = () => {
|
|
108
|
+
try {
|
|
109
|
+
return import_fs_extra2.default.readJsonSync(cacheFilePath);
|
|
110
|
+
} catch {
|
|
111
|
+
return { lastChecked: 0 };
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
var writeCache = (cache) => {
|
|
115
|
+
import_fs_extra2.default.ensureDirSync(appPaths.cache);
|
|
116
|
+
import_fs_extra2.default.writeJsonSync(cacheFilePath, cache);
|
|
117
|
+
};
|
|
118
|
+
var fetchLatestVersion = async () => {
|
|
119
|
+
return new Promise((resolve) => {
|
|
120
|
+
const req = import_node_https.default.get(
|
|
121
|
+
registryUrl,
|
|
122
|
+
{ headers: { accept: "application/vnd.npm.install-v1+json" }, timeout: 4e3 },
|
|
123
|
+
(res) => {
|
|
124
|
+
if ((res.statusCode || 0) >= 400) {
|
|
125
|
+
res.resume();
|
|
126
|
+
resolve(null);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
let body = "";
|
|
130
|
+
res.on("data", (chunk) => {
|
|
131
|
+
body += chunk;
|
|
132
|
+
});
|
|
133
|
+
res.on("end", () => {
|
|
134
|
+
try {
|
|
135
|
+
const data = JSON.parse(body);
|
|
136
|
+
const latest = data?.["dist-tags"]?.latest;
|
|
137
|
+
resolve(typeof latest === "string" ? latest : null);
|
|
138
|
+
} catch {
|
|
139
|
+
resolve(null);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
);
|
|
144
|
+
req.on("timeout", () => {
|
|
145
|
+
req.destroy(new Error("Request timed out"));
|
|
146
|
+
});
|
|
147
|
+
req.on("error", () => resolve(null));
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
var compareVersions = (a, b) => {
|
|
151
|
+
const aParts = a.split(".").map((part) => Number.parseInt(part, 10));
|
|
152
|
+
const bParts = b.split(".").map((part) => Number.parseInt(part, 10));
|
|
153
|
+
for (let i = 0; i < Math.max(aParts.length, bParts.length); i += 1) {
|
|
154
|
+
const aValue = aParts[i] || 0;
|
|
155
|
+
const bValue = bParts[i] || 0;
|
|
156
|
+
if (aValue > bValue) return 1;
|
|
157
|
+
if (aValue < bValue) return -1;
|
|
158
|
+
}
|
|
159
|
+
return 0;
|
|
160
|
+
};
|
|
161
|
+
var checkForCliUpdate = async (currentVersion) => {
|
|
162
|
+
const cache = readCache();
|
|
163
|
+
const now = Date.now();
|
|
164
|
+
if (now - cache.lastChecked < checkIntervalMs) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
writeCache({ lastChecked: now });
|
|
168
|
+
try {
|
|
169
|
+
const latest = await fetchLatestVersion();
|
|
170
|
+
if (!latest) return;
|
|
171
|
+
if (compareVersions(latest, currentVersion) > 0) {
|
|
172
|
+
logWarningSection(
|
|
173
|
+
`Update available: ${currentVersion} -> ${latest}, Run "blox upgrade" to update.`
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
} catch (e) {
|
|
177
|
+
debug(`Failed to check for updates: ${e}`);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
// package.json
|
|
182
|
+
var version = "1.4.2";
|
|
183
|
+
|
|
184
|
+
// src/commands/add/index.ts
|
|
185
|
+
var import_fs_extra9 = __toESM(require("fs-extra"));
|
|
186
|
+
|
|
187
|
+
// src/migrations/index.ts
|
|
188
|
+
var import_node_path6 = __toESM(require("path"));
|
|
189
|
+
var import_fs_extra5 = __toESM(require("fs-extra"));
|
|
53
190
|
|
|
54
191
|
// src/migrations/utils.ts
|
|
55
|
-
var
|
|
56
|
-
var
|
|
192
|
+
var import_node_path5 = __toESM(require("path"));
|
|
193
|
+
var import_fs_extra4 = __toESM(require("fs-extra"));
|
|
57
194
|
|
|
58
195
|
// src/migrations/list/v1.ts
|
|
59
196
|
var v1 = {
|
|
@@ -89,50 +226,17 @@ var v1 = {
|
|
|
89
226
|
var migrationsList = [v1];
|
|
90
227
|
|
|
91
228
|
// src/services/git.ts
|
|
92
|
-
var
|
|
93
|
-
var
|
|
229
|
+
var import_node_path4 = __toESM(require("path"));
|
|
230
|
+
var import_fs_extra3 = __toESM(require("fs-extra"));
|
|
94
231
|
|
|
95
232
|
// src/services/path.ts
|
|
96
|
-
var
|
|
233
|
+
var import_node_path3 = __toESM(require("path"));
|
|
97
234
|
var normalizePath = (_path) => {
|
|
98
|
-
return _path.split(
|
|
235
|
+
return _path.split(import_node_path3.default.sep).join("/");
|
|
99
236
|
};
|
|
100
237
|
|
|
101
238
|
// src/services/shell.ts
|
|
102
239
|
var import_node_child_process = require("child_process");
|
|
103
|
-
|
|
104
|
-
// src/shared/logger.ts
|
|
105
|
-
var console2 = __toESM(require("console"));
|
|
106
|
-
var import_prompts = require("@clack/prompts");
|
|
107
|
-
|
|
108
|
-
// src/shared/terminal/index.ts
|
|
109
|
-
var import_ansis = __toESM(require("ansis"));
|
|
110
|
-
var fmt = import_ansis.default;
|
|
111
|
-
|
|
112
|
-
// src/shared/logger.ts
|
|
113
|
-
var import_prompts2 = require("@clack/prompts");
|
|
114
|
-
var debug = (message) => {
|
|
115
|
-
if (!isDebugMode()) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
if (typeof message === "string") {
|
|
119
|
-
import_prompts.log.warn(message.trim());
|
|
120
|
-
} else {
|
|
121
|
-
console2.log(JSON.stringify(message));
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
var logWarningSection = (title, content) => {
|
|
125
|
-
const line = fmt.yellow("=".repeat(82));
|
|
126
|
-
console2.log("\n" + line);
|
|
127
|
-
console2.log(fmt.bold(fmt.yellow("\u25B2 " + title)));
|
|
128
|
-
content && console2.log("\n" + content);
|
|
129
|
-
console2.log(line + "\n");
|
|
130
|
-
};
|
|
131
|
-
var normalizeLogMessage = (content) => {
|
|
132
|
-
return content.split("\n").map((l) => l.trim()).filter(Boolean).join("\n");
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
// src/services/shell.ts
|
|
136
240
|
var $ = async (bin, options = [], { cwd, onStdout } = {}) => {
|
|
137
241
|
debug(`Command executed: "${bin} ${options.join(" ")}" with cwd = ${cwd}`);
|
|
138
242
|
return new Promise(function(resolve, reject) {
|
|
@@ -231,8 +335,8 @@ var update = (shellOptions = {}) => {
|
|
|
231
335
|
var getLatestCommitFromRemote = async (remote) => {
|
|
232
336
|
return getLatestCommit(`${remote}/main`);
|
|
233
337
|
};
|
|
234
|
-
var getLatestCommitFromPath = async (
|
|
235
|
-
return getLatestCommit("HEAD",
|
|
338
|
+
var getLatestCommitFromPath = async (path12) => {
|
|
339
|
+
return getLatestCommit("HEAD", path12);
|
|
236
340
|
};
|
|
237
341
|
var getLatestCommit = async (rev, cwd = ".") => {
|
|
238
342
|
debug(`Get latest commit for rev: ${rev} and cwd: ${cwd}`);
|
|
@@ -276,7 +380,7 @@ var applyPatch = (patch, cwd = ".") => {
|
|
|
276
380
|
};
|
|
277
381
|
var unInit = (cwd) => {
|
|
278
382
|
debug("UnInit");
|
|
279
|
-
return
|
|
383
|
+
return import_fs_extra3.default.remove(import_node_path4.default.join(cwd, ".git"));
|
|
280
384
|
};
|
|
281
385
|
var init = async (cwd) => {
|
|
282
386
|
debug("Init");
|
|
@@ -428,24 +532,24 @@ async function migrate(name, { getPath = (f) => f, read, write }) {
|
|
|
428
532
|
}
|
|
429
533
|
function migrateOnLocal(name, cwd = ".") {
|
|
430
534
|
return migrate(name, {
|
|
431
|
-
getPath: (file) =>
|
|
432
|
-
read:
|
|
433
|
-
write:
|
|
535
|
+
getPath: (file) => import_node_path5.default.join(cwd, file),
|
|
536
|
+
read: import_fs_extra4.default.readJson,
|
|
537
|
+
write: import_fs_extra4.default.writeFile
|
|
434
538
|
});
|
|
435
539
|
}
|
|
436
540
|
function migrateOnRemote(name, commit2, cwd) {
|
|
437
541
|
return migrate(name, {
|
|
438
542
|
read: (file) => git.readJsonFromCommit(commit2, file),
|
|
439
|
-
getPath: cwd ? (file) =>
|
|
543
|
+
getPath: cwd ? (file) => import_node_path5.default.join(cwd, file) : void 0
|
|
440
544
|
});
|
|
441
545
|
}
|
|
442
546
|
|
|
443
547
|
// src/migrations/index.ts
|
|
444
548
|
async function migrateAll(autoCommit) {
|
|
445
549
|
let filesChanged = (await migrateOnLocal("app")).filesChanged;
|
|
446
|
-
const blocks =
|
|
550
|
+
const blocks = import_fs_extra5.default.existsSync(blocksDir) ? import_fs_extra5.default.readdirSync(blocksDir) : [];
|
|
447
551
|
for (const block of blocks) {
|
|
448
|
-
const res = await migrateOnLocal(block,
|
|
552
|
+
const res = await migrateOnLocal(block, import_node_path6.default.join(blocksDir, block));
|
|
449
553
|
filesChanged = filesChanged || res.filesChanged;
|
|
450
554
|
}
|
|
451
555
|
if (autoCommit && filesChanged && await git.hasUncommittedChanges()) {
|
|
@@ -456,8 +560,8 @@ async function migrateAll(autoCommit) {
|
|
|
456
560
|
}
|
|
457
561
|
|
|
458
562
|
// src/services/fs.ts
|
|
459
|
-
var
|
|
460
|
-
var
|
|
563
|
+
var import_node_path7 = __toESM(require("path"));
|
|
564
|
+
var import_fs_extra6 = __toESM(require("fs-extra"));
|
|
461
565
|
var import_ignore = __toESM(require("ignore"));
|
|
462
566
|
var import_klaw = __toESM(require("klaw"));
|
|
463
567
|
var filterBlacklisted = (item) => {
|
|
@@ -466,20 +570,20 @@ var filterBlacklisted = (item) => {
|
|
|
466
570
|
var deletePattern = async (cwd, patterns = []) => {
|
|
467
571
|
const ig = (0, import_ignore.default)().add(patterns);
|
|
468
572
|
for await (const file of (0, import_klaw.default)(cwd, { filter: filterBlacklisted })) {
|
|
469
|
-
const relativePath =
|
|
573
|
+
const relativePath = import_node_path7.default.relative(cwd, file.path);
|
|
470
574
|
if (relativePath && ig.ignores(relativePath)) {
|
|
471
|
-
if (!await
|
|
575
|
+
if (!await import_fs_extra6.default.exists(file.path)) {
|
|
472
576
|
continue;
|
|
473
577
|
}
|
|
474
578
|
debug(`deleting: ${relativePath}`);
|
|
475
|
-
await
|
|
579
|
+
await import_fs_extra6.default.remove(file.path);
|
|
476
580
|
}
|
|
477
581
|
}
|
|
478
582
|
};
|
|
479
583
|
|
|
480
584
|
// src/services/registry.ts
|
|
481
|
-
var
|
|
482
|
-
var
|
|
585
|
+
var import_node_path8 = __toESM(require("path"));
|
|
586
|
+
var import_fs_extra7 = __toESM(require("fs-extra"));
|
|
483
587
|
var import_merge = __toESM(require("lodash/merge"));
|
|
484
588
|
|
|
485
589
|
// src/shared/spinner.ts
|
|
@@ -513,44 +617,24 @@ async function runTask(message, task) {
|
|
|
513
617
|
}
|
|
514
618
|
}
|
|
515
619
|
|
|
516
|
-
// src/services/config.ts
|
|
517
|
-
var import_node_path6 = __toESM(require("path"));
|
|
518
|
-
var import_env_paths = __toESM(require("env-paths"));
|
|
519
|
-
var import_fs_extra5 = __toESM(require("fs-extra"));
|
|
520
|
-
var appPaths = (0, import_env_paths.default)("blox", { suffix: "" });
|
|
521
|
-
var configFilePath = import_node_path6.default.join(appPaths.config, "config.json");
|
|
522
|
-
var getLocalConfig = () => {
|
|
523
|
-
try {
|
|
524
|
-
return import_fs_extra5.default.readJSONSync(configFilePath);
|
|
525
|
-
} catch {
|
|
526
|
-
return defaultConfig;
|
|
527
|
-
}
|
|
528
|
-
};
|
|
529
|
-
var updateLocalConfig = (config) => {
|
|
530
|
-
debug("Update local config");
|
|
531
|
-
import_fs_extra5.default.ensureFileSync(configFilePath);
|
|
532
|
-
const current = getLocalConfig();
|
|
533
|
-
import_fs_extra5.default.writeJsonSync(configFilePath, { ...current, ...config });
|
|
534
|
-
};
|
|
535
|
-
|
|
536
620
|
// src/services/registry.ts
|
|
537
|
-
var registriesDataPath =
|
|
621
|
+
var registriesDataPath = import_node_path8.default.join(appPaths.data, "registries");
|
|
538
622
|
var upeToDate = false;
|
|
539
623
|
var syncRegistries = async () => {
|
|
540
624
|
if (upeToDate) return;
|
|
541
625
|
upeToDate = true;
|
|
542
626
|
debug("Sync registries");
|
|
543
|
-
|
|
627
|
+
import_fs_extra7.default.ensureDirSync(registriesDataPath);
|
|
544
628
|
const config = getLocalConfig();
|
|
545
629
|
return await runTask("Update registries", async () => {
|
|
546
630
|
await Promise.all(
|
|
547
631
|
config.registries.map(async (registry) => {
|
|
548
632
|
debug(`update registry: ${registry}`);
|
|
549
633
|
const repoName = registry.split("/").pop() || "";
|
|
550
|
-
const repoDir =
|
|
551
|
-
if (!
|
|
634
|
+
const repoDir = import_node_path8.default.join(registriesDataPath, repoName);
|
|
635
|
+
if (!import_fs_extra7.default.existsSync(repoDir)) {
|
|
552
636
|
await git.clone(registry, "--depth 1", { cwd: registriesDataPath });
|
|
553
|
-
} else if (
|
|
637
|
+
} else if (import_fs_extra7.default.existsSync(import_node_path8.default.join(repoDir, ".git"))) {
|
|
554
638
|
await git.update({ cwd: repoDir });
|
|
555
639
|
} else {
|
|
556
640
|
debug(`local registry`);
|
|
@@ -562,11 +646,11 @@ var syncRegistries = async () => {
|
|
|
562
646
|
var getAvailableTemplates = async () => {
|
|
563
647
|
debug("Get available templates");
|
|
564
648
|
const templates = {};
|
|
565
|
-
const registries =
|
|
649
|
+
const registries = import_fs_extra7.default.readdirSync(registriesDataPath);
|
|
566
650
|
for (const registry of registries) {
|
|
567
|
-
const indexPath =
|
|
568
|
-
if (
|
|
569
|
-
const data =
|
|
651
|
+
const indexPath = import_node_path8.default.join(registriesDataPath, registry, "index.json");
|
|
652
|
+
if (import_fs_extra7.default.existsSync(indexPath)) {
|
|
653
|
+
const data = import_fs_extra7.default.readJSONSync(indexPath);
|
|
570
654
|
Object.entries(data.templates || {}).forEach(([templateName, template]) => {
|
|
571
655
|
if (!template.source) {
|
|
572
656
|
template.source = `/template-${templateName}`;
|
|
@@ -606,29 +690,29 @@ var getAvailableBlocks = async (templateInfo) => {
|
|
|
606
690
|
return blocks;
|
|
607
691
|
};
|
|
608
692
|
var getAvailableVersions = async (source) => {
|
|
609
|
-
const registries =
|
|
693
|
+
const registries = import_fs_extra7.default.readdirSync(registriesDataPath);
|
|
610
694
|
for (const registry of registries) {
|
|
611
|
-
const registryPath =
|
|
612
|
-
const indexPath =
|
|
613
|
-
if (!
|
|
614
|
-
const registryData =
|
|
615
|
-
const versionDirPath =
|
|
695
|
+
const registryPath = import_node_path8.default.join(registriesDataPath, registry);
|
|
696
|
+
const indexPath = import_node_path8.default.join(registryPath, "index.json");
|
|
697
|
+
if (!import_fs_extra7.default.existsSync(indexPath)) continue;
|
|
698
|
+
const registryData = import_fs_extra7.default.readJSONSync(indexPath);
|
|
699
|
+
const versionDirPath = import_node_path8.default.join(registryPath, "versions");
|
|
616
700
|
const versionsFilePaths = [
|
|
617
|
-
|
|
618
|
-
|
|
701
|
+
import_node_path8.default.join(versionDirPath, `${source.replace(`${registryData.baseUrl}/`, "")}.json`),
|
|
702
|
+
import_node_path8.default.join(versionDirPath, `${encodeURIComponent(source)}.json`)
|
|
619
703
|
];
|
|
620
704
|
for (const versionsFile of versionsFilePaths) {
|
|
621
|
-
if (
|
|
622
|
-
return
|
|
705
|
+
if (import_fs_extra7.default.existsSync(versionsFile)) {
|
|
706
|
+
return import_fs_extra7.default.readJSONSync(versionsFile);
|
|
623
707
|
}
|
|
624
708
|
}
|
|
625
709
|
}
|
|
626
710
|
};
|
|
627
711
|
|
|
628
712
|
// src/services/template.ts
|
|
629
|
-
var
|
|
713
|
+
var import_node_path9 = __toESM(require("path"));
|
|
630
714
|
var import_ejs = __toESM(require("ejs"));
|
|
631
|
-
var
|
|
715
|
+
var import_fs_extra8 = __toESM(require("fs-extra"));
|
|
632
716
|
var import_klaw2 = __toESM(require("klaw"));
|
|
633
717
|
var NON_RENDERABLE_FILES = [
|
|
634
718
|
".png",
|
|
@@ -652,17 +736,17 @@ async function replacePlaceholders(dir, context) {
|
|
|
652
736
|
debug("Replace placeholders");
|
|
653
737
|
for await (const file of (0, import_klaw2.default)(dir)) {
|
|
654
738
|
if (!file.stats.isFile()) continue;
|
|
655
|
-
const ext =
|
|
739
|
+
const ext = import_node_path9.default.extname(file.path).toLowerCase();
|
|
656
740
|
if (NON_RENDERABLE_FILES.includes(ext)) {
|
|
657
741
|
continue;
|
|
658
742
|
}
|
|
659
|
-
const templateContent =
|
|
743
|
+
const templateContent = import_fs_extra8.default.readFileSync(file.path, "utf8");
|
|
660
744
|
if (!templateContent.includes("<%")) {
|
|
661
745
|
continue;
|
|
662
746
|
}
|
|
663
747
|
try {
|
|
664
748
|
const rendered = import_ejs.default.render(templateContent, context);
|
|
665
|
-
|
|
749
|
+
import_fs_extra8.default.writeFileSync(file.path, rendered, "utf8");
|
|
666
750
|
} catch (err) {
|
|
667
751
|
console.error("\u274C Error rendering EJS for file:", file.path);
|
|
668
752
|
throw err;
|
|
@@ -683,7 +767,7 @@ function getBlockDef(cwd = ".") {
|
|
|
683
767
|
}
|
|
684
768
|
function getBloxFile(cwd = ".") {
|
|
685
769
|
try {
|
|
686
|
-
const file =
|
|
770
|
+
const file = import_fs_extra8.default.readJSONSync(import_node_path9.default.join(cwd, bloxFilePath));
|
|
687
771
|
if (!file.checkpoints) {
|
|
688
772
|
file.checkpoints = {};
|
|
689
773
|
}
|
|
@@ -694,7 +778,7 @@ function getBloxFile(cwd = ".") {
|
|
|
694
778
|
}
|
|
695
779
|
function saveBloxFile(info, cwd = ".") {
|
|
696
780
|
debug("Save info");
|
|
697
|
-
|
|
781
|
+
import_fs_extra8.default.writeFileSync(import_node_path9.default.join(cwd, bloxFilePath), JSON.stringify(info, null, 2));
|
|
698
782
|
}
|
|
699
783
|
function updateCheckpoint(name, checkpoint, cwd = ".") {
|
|
700
784
|
const info = getBloxFile(cwd);
|
|
@@ -710,12 +794,12 @@ function getUsedBlocksDef() {
|
|
|
710
794
|
function getUsedBlocks() {
|
|
711
795
|
debug("Get used blocks");
|
|
712
796
|
const blocks = [];
|
|
713
|
-
if (
|
|
714
|
-
|
|
797
|
+
if (import_fs_extra8.default.existsSync(blocksDir)) {
|
|
798
|
+
import_fs_extra8.default.readdirSync(blocksDir, { withFileTypes: true }).forEach((file) => {
|
|
715
799
|
if (!file.isDirectory()) {
|
|
716
800
|
return;
|
|
717
801
|
}
|
|
718
|
-
const blockDef = getBloxFile(
|
|
802
|
+
const blockDef = getBloxFile(import_node_path9.default.join(blocksDir, file.name));
|
|
719
803
|
if (blockDef && blockDef.definition) {
|
|
720
804
|
blocks.push(blockDef);
|
|
721
805
|
}
|
|
@@ -861,7 +945,7 @@ function runInitScript(cwd) {
|
|
|
861
945
|
var addBlock = async (block, blocks) => {
|
|
862
946
|
const blockPath = `blocks/${block}`;
|
|
863
947
|
const blockRegistryData = blocks[block];
|
|
864
|
-
if (!
|
|
948
|
+
if (!import_fs_extra9.default.existsSync(blockPath)) {
|
|
865
949
|
await runTask(
|
|
866
950
|
{ start: `Fetching block: ${block}`, end: `Added block: ${block}` },
|
|
867
951
|
async () => {
|
|
@@ -988,7 +1072,7 @@ var detach = command("detach").description("Migrate blox schema").option("--basi
|
|
|
988
1072
|
});
|
|
989
1073
|
|
|
990
1074
|
// src/commands/init/index.ts
|
|
991
|
-
var
|
|
1075
|
+
var import_fs_extra10 = __toESM(require("fs-extra"));
|
|
992
1076
|
var init2 = command("init").description("Init new app").alias("i").option("-n, --name <name>", "App name").option("-t, --template <template>", "Template to use").action(async ({ name, template }) => {
|
|
993
1077
|
await syncRegistries();
|
|
994
1078
|
try {
|
|
@@ -1029,8 +1113,8 @@ var init2 = command("init").description("Init new app").alias("i").option("-n, -
|
|
|
1029
1113
|
task.stop(`App initialized in ${name}`);
|
|
1030
1114
|
await runTask("Run init script", async () => runInitScript(name || ""));
|
|
1031
1115
|
} catch (e) {
|
|
1032
|
-
if (name &&
|
|
1033
|
-
await
|
|
1116
|
+
if (name && import_fs_extra10.default.existsSync(name)) {
|
|
1117
|
+
await import_fs_extra10.default.remove(name);
|
|
1034
1118
|
}
|
|
1035
1119
|
error(e);
|
|
1036
1120
|
}
|
|
@@ -1053,11 +1137,11 @@ var migrateSchema = command("migrate").description("Migrate blox schema").action
|
|
|
1053
1137
|
var import_prompts15 = require("@clack/prompts");
|
|
1054
1138
|
|
|
1055
1139
|
// src/commands/update/utils.ts
|
|
1056
|
-
var
|
|
1140
|
+
var import_node_path11 = __toESM(require("path"));
|
|
1057
1141
|
|
|
1058
1142
|
// src/services/updater.ts
|
|
1059
|
-
var
|
|
1060
|
-
var
|
|
1143
|
+
var import_node_path10 = __toESM(require("path"));
|
|
1144
|
+
var import_fs_extra11 = __toESM(require("fs-extra"));
|
|
1061
1145
|
async function updateFromRemote({ name, source = "", ignore: ignore2 = [], dir = "." }) {
|
|
1062
1146
|
debug("Updating from remote");
|
|
1063
1147
|
await git.updateRemote(name, source);
|
|
@@ -1092,13 +1176,13 @@ async function updateFromRemote({ name, source = "", ignore: ignore2 = [], dir =
|
|
|
1092
1176
|
);
|
|
1093
1177
|
}
|
|
1094
1178
|
}
|
|
1095
|
-
const patchFilePath =
|
|
1179
|
+
const patchFilePath = import_node_path10.default.join(dir, "diff.patch");
|
|
1096
1180
|
const remoteIgnore = remoteBloxFile.definition?.ignore || [];
|
|
1097
1181
|
ignore2.push(...remoteIgnore, ".blox", "**/.blox");
|
|
1098
1182
|
await git.createPatch(fromCommit, toCommit, patchFilePath, ignore2);
|
|
1099
1183
|
const deletePatchFile = async () => {
|
|
1100
1184
|
if (!isDebugMode()) {
|
|
1101
|
-
await
|
|
1185
|
+
await import_fs_extra11.default.unlink(patchFilePath);
|
|
1102
1186
|
}
|
|
1103
1187
|
debug("make sure to delete the patch file after you're done with it.");
|
|
1104
1188
|
};
|
|
@@ -1166,7 +1250,7 @@ async function updateApp({
|
|
|
1166
1250
|
const blockRegistryData = availableBlocks[block.name];
|
|
1167
1251
|
if (!blockRegistryData) return;
|
|
1168
1252
|
await git.updateRemote(block.name, blockRegistryData.source);
|
|
1169
|
-
const blockPath =
|
|
1253
|
+
const blockPath = import_node_path11.default.join(blocksDir, block.name);
|
|
1170
1254
|
const currentBloxFile = getBloxFile(blockPath);
|
|
1171
1255
|
const remoteBloxFile = (await migrateOnRemote(block.name, toAppCommit, blockPath)).output[".blox"];
|
|
1172
1256
|
const blockFromCommit = currentBloxFile.checkpoints?.[block.name]?.commit;
|
|
@@ -1199,7 +1283,7 @@ async function updateAppBases(templateDef, templates, ignore2) {
|
|
|
1199
1283
|
}
|
|
1200
1284
|
async function updateBlock(block, blocks, ignore2) {
|
|
1201
1285
|
const blockRegistryData = blocks[block];
|
|
1202
|
-
const blockPath =
|
|
1286
|
+
const blockPath = import_node_path11.default.join(blocksDir, block);
|
|
1203
1287
|
await runTask({ start: `Update block: ${block}`, end: `Updated block: ${block}` }, async () => {
|
|
1204
1288
|
if (!blockRegistryData) {
|
|
1205
1289
|
error(`Selected block: ${block} not available in registries`, false);
|
|
@@ -1340,6 +1424,7 @@ async function main() {
|
|
|
1340
1424
|
import_extra_typings2.program.name("blox").version(version);
|
|
1341
1425
|
import_extra_typings2.program.option("-d, --debug", "work in debug mode");
|
|
1342
1426
|
import_extra_typings2.program.option("-m, --minimal", "work in minimal mode");
|
|
1427
|
+
await checkForCliUpdate(version);
|
|
1343
1428
|
commands.forEach((cmd) => import_extra_typings2.program.addCommand(cmd));
|
|
1344
1429
|
import_extra_typings2.program.parse();
|
|
1345
1430
|
}
|