@naseej/blox 1.4.1 → 1.4.3
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.ts +3 -0
- package/dist/run.js +241 -150
- package/package.json +1 -1
- package/readme.md +5 -0
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,29 @@ 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
|
+
var defaultBranch = "main";
|
|
43
|
+
|
|
44
|
+
// src/shared/logger.ts
|
|
45
|
+
var console2 = __toESM(require("console"));
|
|
46
|
+
var import_prompts = require("@clack/prompts");
|
|
47
|
+
|
|
25
48
|
// src/shared/command/index.ts
|
|
26
49
|
var import_extra_typings = require("@commander-js/extra-typings");
|
|
27
50
|
var import_extra_typings2 = require("@commander-js/extra-typings");
|
|
@@ -30,30 +53,145 @@ var option = (flags, description) => {
|
|
|
30
53
|
return new import_extra_typings.Option(flags, description);
|
|
31
54
|
};
|
|
32
55
|
|
|
33
|
-
// package.json
|
|
34
|
-
var version = "1.4.1";
|
|
35
|
-
|
|
36
|
-
// src/commands/add/index.ts
|
|
37
|
-
var import_fs_extra8 = __toESM(require("fs-extra"));
|
|
38
|
-
|
|
39
56
|
// src/config/runtime.ts
|
|
40
57
|
var isDebugMode = () => !!import_extra_typings2.program.opts()?.debug;
|
|
41
58
|
var isMinimalMode = () => !!import_extra_typings2.program.opts()?.minimal;
|
|
42
59
|
|
|
43
|
-
// src/
|
|
44
|
-
var
|
|
45
|
-
var
|
|
60
|
+
// src/shared/terminal/index.ts
|
|
61
|
+
var import_ansis = __toESM(require("ansis"));
|
|
62
|
+
var fmt = import_ansis.default;
|
|
46
63
|
|
|
47
|
-
// src/
|
|
48
|
-
var
|
|
49
|
-
|
|
64
|
+
// src/shared/logger.ts
|
|
65
|
+
var import_prompts2 = require("@clack/prompts");
|
|
66
|
+
var debug = (message) => {
|
|
67
|
+
if (!isDebugMode()) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (typeof message === "string") {
|
|
71
|
+
import_prompts.log.warn(message.trim());
|
|
72
|
+
} else {
|
|
73
|
+
console2.log(JSON.stringify(message));
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
var logWarningSection = (title, content) => {
|
|
77
|
+
const line = fmt.yellow("=".repeat(82));
|
|
78
|
+
console2.log("\n" + line);
|
|
79
|
+
console2.log(fmt.bold(fmt.yellow("\u25B2 " + title)));
|
|
80
|
+
content && console2.log("\n" + content);
|
|
81
|
+
console2.log(line + "\n");
|
|
82
|
+
};
|
|
83
|
+
var normalizeLogMessage = (content) => {
|
|
84
|
+
return content.split("\n").map((l) => l.trim()).filter(Boolean).join("\n");
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// src/services/config.ts
|
|
88
|
+
var appPaths = (0, import_env_paths.default)("blox", { suffix: "" });
|
|
89
|
+
var configFilePath = import_node_path.default.join(appPaths.config, "config.json");
|
|
90
|
+
var getLocalConfig = () => {
|
|
91
|
+
try {
|
|
92
|
+
return import_fs_extra.default.readJSONSync(configFilePath);
|
|
93
|
+
} catch {
|
|
94
|
+
return defaultConfig;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
var updateLocalConfig = (config) => {
|
|
98
|
+
debug("Update local config");
|
|
99
|
+
import_fs_extra.default.ensureFileSync(configFilePath);
|
|
100
|
+
const current = getLocalConfig();
|
|
101
|
+
import_fs_extra.default.writeJsonSync(configFilePath, { ...current, ...config });
|
|
50
102
|
};
|
|
51
|
-
|
|
52
|
-
|
|
103
|
+
|
|
104
|
+
// src/services/cliVersion.ts
|
|
105
|
+
var registryUrl = "https://registry.npmjs.org/%40naseej%2Fblox";
|
|
106
|
+
var checkIntervalMs = (0, import_ms.default)("24h");
|
|
107
|
+
var cacheFilePath = import_node_path2.default.join(appPaths.cache, "cli-version.json");
|
|
108
|
+
var readCache = () => {
|
|
109
|
+
try {
|
|
110
|
+
return import_fs_extra2.default.readJsonSync(cacheFilePath);
|
|
111
|
+
} catch {
|
|
112
|
+
return { lastChecked: 0 };
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
var writeCache = (cache) => {
|
|
116
|
+
import_fs_extra2.default.ensureDirSync(appPaths.cache);
|
|
117
|
+
import_fs_extra2.default.writeJsonSync(cacheFilePath, cache);
|
|
118
|
+
};
|
|
119
|
+
var fetchLatestVersion = async () => {
|
|
120
|
+
return new Promise((resolve) => {
|
|
121
|
+
const req = import_node_https.default.get(
|
|
122
|
+
registryUrl,
|
|
123
|
+
{ headers: { accept: "application/vnd.npm.install-v1+json" }, timeout: 4e3 },
|
|
124
|
+
(res) => {
|
|
125
|
+
if ((res.statusCode || 0) >= 400) {
|
|
126
|
+
res.resume();
|
|
127
|
+
resolve(null);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
let body = "";
|
|
131
|
+
res.on("data", (chunk) => {
|
|
132
|
+
body += chunk;
|
|
133
|
+
});
|
|
134
|
+
res.on("end", () => {
|
|
135
|
+
try {
|
|
136
|
+
const data = JSON.parse(body);
|
|
137
|
+
const latest = data?.["dist-tags"]?.latest;
|
|
138
|
+
resolve(typeof latest === "string" ? latest : null);
|
|
139
|
+
} catch {
|
|
140
|
+
resolve(null);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
);
|
|
145
|
+
req.on("timeout", () => {
|
|
146
|
+
req.destroy(new Error("Request timed out"));
|
|
147
|
+
});
|
|
148
|
+
req.on("error", () => resolve(null));
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
var compareVersions = (a, b) => {
|
|
152
|
+
const aParts = a.split(".").map((part) => Number.parseInt(part, 10));
|
|
153
|
+
const bParts = b.split(".").map((part) => Number.parseInt(part, 10));
|
|
154
|
+
for (let i = 0; i < Math.max(aParts.length, bParts.length); i += 1) {
|
|
155
|
+
const aValue = aParts[i] || 0;
|
|
156
|
+
const bValue = bParts[i] || 0;
|
|
157
|
+
if (aValue > bValue) return 1;
|
|
158
|
+
if (aValue < bValue) return -1;
|
|
159
|
+
}
|
|
160
|
+
return 0;
|
|
161
|
+
};
|
|
162
|
+
var checkForCliUpdate = async (currentVersion) => {
|
|
163
|
+
const cache = readCache();
|
|
164
|
+
const now = Date.now();
|
|
165
|
+
if (now - cache.lastChecked < checkIntervalMs) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
writeCache({ lastChecked: now });
|
|
169
|
+
try {
|
|
170
|
+
const latest = await fetchLatestVersion();
|
|
171
|
+
if (!latest) return;
|
|
172
|
+
if (compareVersions(latest, currentVersion) > 0) {
|
|
173
|
+
logWarningSection(
|
|
174
|
+
`Update available: ${currentVersion} -> ${latest}, Run "blox upgrade" to update.`
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
} catch (e) {
|
|
178
|
+
debug(`Failed to check for updates: ${e}`);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
// package.json
|
|
183
|
+
var version = "1.4.3";
|
|
184
|
+
|
|
185
|
+
// src/commands/add/index.ts
|
|
186
|
+
var import_fs_extra9 = __toESM(require("fs-extra"));
|
|
187
|
+
|
|
188
|
+
// src/migrations/index.ts
|
|
189
|
+
var import_node_path6 = __toESM(require("path"));
|
|
190
|
+
var import_fs_extra5 = __toESM(require("fs-extra"));
|
|
53
191
|
|
|
54
192
|
// src/migrations/utils.ts
|
|
55
|
-
var
|
|
56
|
-
var
|
|
193
|
+
var import_node_path5 = __toESM(require("path"));
|
|
194
|
+
var import_fs_extra4 = __toESM(require("fs-extra"));
|
|
57
195
|
|
|
58
196
|
// src/migrations/list/v1.ts
|
|
59
197
|
var v1 = {
|
|
@@ -89,50 +227,17 @@ var v1 = {
|
|
|
89
227
|
var migrationsList = [v1];
|
|
90
228
|
|
|
91
229
|
// src/services/git.ts
|
|
92
|
-
var
|
|
93
|
-
var
|
|
230
|
+
var import_node_path4 = __toESM(require("path"));
|
|
231
|
+
var import_fs_extra3 = __toESM(require("fs-extra"));
|
|
94
232
|
|
|
95
233
|
// src/services/path.ts
|
|
96
|
-
var
|
|
234
|
+
var import_node_path3 = __toESM(require("path"));
|
|
97
235
|
var normalizePath = (_path) => {
|
|
98
|
-
return _path.split(
|
|
236
|
+
return _path.split(import_node_path3.default.sep).join("/");
|
|
99
237
|
};
|
|
100
238
|
|
|
101
239
|
// src/services/shell.ts
|
|
102
240
|
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
241
|
var $ = async (bin, options = [], { cwd, onStdout } = {}) => {
|
|
137
242
|
debug(`Command executed: "${bin} ${options.join(" ")}" with cwd = ${cwd}`);
|
|
138
243
|
return new Promise(function(resolve, reject) {
|
|
@@ -172,8 +277,8 @@ var checkAuth = (message) => {
|
|
|
172
277
|
var defaultShellOptions = {
|
|
173
278
|
onStdout: checkAuth
|
|
174
279
|
};
|
|
175
|
-
var clone = (repoUrl, options, shellOptions = {}) => {
|
|
176
|
-
return $("git", ["clone", "--progress", repoUrl, options], {
|
|
280
|
+
var clone = (repoUrl, options, branch = defaultBranch, shellOptions = {}) => {
|
|
281
|
+
return $("git", ["clone", "--progress", repoUrl, "--branch", branch, options], {
|
|
177
282
|
...defaultShellOptions,
|
|
178
283
|
...shellOptions
|
|
179
284
|
});
|
|
@@ -214,8 +319,8 @@ var readJsonFromCommit = async (commit2, file) => {
|
|
|
214
319
|
return {};
|
|
215
320
|
}
|
|
216
321
|
};
|
|
217
|
-
var readJsonFromRemote = async (remote, file, commit2) => {
|
|
218
|
-
return readJsonFromCommit(commit2 || `${remote}
|
|
322
|
+
var readJsonFromRemote = async (remote, file, branch = defaultBranch, commit2) => {
|
|
323
|
+
return readJsonFromCommit(commit2 || `${remote}/${branch}`, file);
|
|
219
324
|
};
|
|
220
325
|
var isCommitOlder = async (a, b) => {
|
|
221
326
|
try {
|
|
@@ -228,11 +333,11 @@ var isCommitOlder = async (a, b) => {
|
|
|
228
333
|
var update = (shellOptions = {}) => {
|
|
229
334
|
return $("git", ["pull", "--progress"], { ...defaultShellOptions, ...shellOptions });
|
|
230
335
|
};
|
|
231
|
-
var getLatestCommitFromRemote = async (remote) => {
|
|
232
|
-
return getLatestCommit(`${remote}
|
|
336
|
+
var getLatestCommitFromRemote = async (remote, branch) => {
|
|
337
|
+
return getLatestCommit(`${remote}/${branch}`);
|
|
233
338
|
};
|
|
234
|
-
var getLatestCommitFromPath = async (
|
|
235
|
-
return getLatestCommit("HEAD",
|
|
339
|
+
var getLatestCommitFromPath = async (path12) => {
|
|
340
|
+
return getLatestCommit("HEAD", path12);
|
|
236
341
|
};
|
|
237
342
|
var getLatestCommit = async (rev, cwd = ".") => {
|
|
238
343
|
debug(`Get latest commit for rev: ${rev} and cwd: ${cwd}`);
|
|
@@ -276,14 +381,14 @@ var applyPatch = (patch, cwd = ".") => {
|
|
|
276
381
|
};
|
|
277
382
|
var unInit = (cwd) => {
|
|
278
383
|
debug("UnInit");
|
|
279
|
-
return
|
|
384
|
+
return import_fs_extra3.default.remove(import_node_path4.default.join(cwd, ".git"));
|
|
280
385
|
};
|
|
281
386
|
var init = async (cwd) => {
|
|
282
387
|
debug("Init");
|
|
283
388
|
await $("git", ["init"], { cwd });
|
|
284
389
|
await $("git", ["add", "."], { cwd });
|
|
285
390
|
await $("git", ["commit", "-m", "init"], { cwd });
|
|
286
|
-
await $("git", ["branch", "-m",
|
|
391
|
+
await $("git", ["branch", "-m", defaultBranch], { cwd });
|
|
287
392
|
};
|
|
288
393
|
var add = async (toAdd) => {
|
|
289
394
|
debug(`Git Add: ${toAdd}`);
|
|
@@ -428,24 +533,24 @@ async function migrate(name, { getPath = (f) => f, read, write }) {
|
|
|
428
533
|
}
|
|
429
534
|
function migrateOnLocal(name, cwd = ".") {
|
|
430
535
|
return migrate(name, {
|
|
431
|
-
getPath: (file) =>
|
|
432
|
-
read:
|
|
433
|
-
write:
|
|
536
|
+
getPath: (file) => import_node_path5.default.join(cwd, file),
|
|
537
|
+
read: import_fs_extra4.default.readJson,
|
|
538
|
+
write: import_fs_extra4.default.writeFile
|
|
434
539
|
});
|
|
435
540
|
}
|
|
436
541
|
function migrateOnRemote(name, commit2, cwd) {
|
|
437
542
|
return migrate(name, {
|
|
438
543
|
read: (file) => git.readJsonFromCommit(commit2, file),
|
|
439
|
-
getPath: cwd ? (file) =>
|
|
544
|
+
getPath: cwd ? (file) => import_node_path5.default.join(cwd, file) : void 0
|
|
440
545
|
});
|
|
441
546
|
}
|
|
442
547
|
|
|
443
548
|
// src/migrations/index.ts
|
|
444
549
|
async function migrateAll(autoCommit) {
|
|
445
550
|
let filesChanged = (await migrateOnLocal("app")).filesChanged;
|
|
446
|
-
const blocks =
|
|
551
|
+
const blocks = import_fs_extra5.default.existsSync(blocksDir) ? import_fs_extra5.default.readdirSync(blocksDir) : [];
|
|
447
552
|
for (const block of blocks) {
|
|
448
|
-
const res = await migrateOnLocal(block,
|
|
553
|
+
const res = await migrateOnLocal(block, import_node_path6.default.join(blocksDir, block));
|
|
449
554
|
filesChanged = filesChanged || res.filesChanged;
|
|
450
555
|
}
|
|
451
556
|
if (autoCommit && filesChanged && await git.hasUncommittedChanges()) {
|
|
@@ -456,8 +561,8 @@ async function migrateAll(autoCommit) {
|
|
|
456
561
|
}
|
|
457
562
|
|
|
458
563
|
// src/services/fs.ts
|
|
459
|
-
var
|
|
460
|
-
var
|
|
564
|
+
var import_node_path7 = __toESM(require("path"));
|
|
565
|
+
var import_fs_extra6 = __toESM(require("fs-extra"));
|
|
461
566
|
var import_ignore = __toESM(require("ignore"));
|
|
462
567
|
var import_klaw = __toESM(require("klaw"));
|
|
463
568
|
var filterBlacklisted = (item) => {
|
|
@@ -466,20 +571,20 @@ var filterBlacklisted = (item) => {
|
|
|
466
571
|
var deletePattern = async (cwd, patterns = []) => {
|
|
467
572
|
const ig = (0, import_ignore.default)().add(patterns);
|
|
468
573
|
for await (const file of (0, import_klaw.default)(cwd, { filter: filterBlacklisted })) {
|
|
469
|
-
const relativePath =
|
|
574
|
+
const relativePath = import_node_path7.default.relative(cwd, file.path);
|
|
470
575
|
if (relativePath && ig.ignores(relativePath)) {
|
|
471
|
-
if (!await
|
|
576
|
+
if (!await import_fs_extra6.default.exists(file.path)) {
|
|
472
577
|
continue;
|
|
473
578
|
}
|
|
474
579
|
debug(`deleting: ${relativePath}`);
|
|
475
|
-
await
|
|
580
|
+
await import_fs_extra6.default.remove(file.path);
|
|
476
581
|
}
|
|
477
582
|
}
|
|
478
583
|
};
|
|
479
584
|
|
|
480
585
|
// src/services/registry.ts
|
|
481
|
-
var
|
|
482
|
-
var
|
|
586
|
+
var import_node_path8 = __toESM(require("path"));
|
|
587
|
+
var import_fs_extra7 = __toESM(require("fs-extra"));
|
|
483
588
|
var import_merge = __toESM(require("lodash/merge"));
|
|
484
589
|
|
|
485
590
|
// src/shared/spinner.ts
|
|
@@ -513,44 +618,24 @@ async function runTask(message, task) {
|
|
|
513
618
|
}
|
|
514
619
|
}
|
|
515
620
|
|
|
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
621
|
// src/services/registry.ts
|
|
537
|
-
var registriesDataPath =
|
|
622
|
+
var registriesDataPath = import_node_path8.default.join(appPaths.data, "registries");
|
|
538
623
|
var upeToDate = false;
|
|
539
|
-
var syncRegistries = async () => {
|
|
624
|
+
var syncRegistries = async (branch) => {
|
|
540
625
|
if (upeToDate) return;
|
|
541
626
|
upeToDate = true;
|
|
542
627
|
debug("Sync registries");
|
|
543
|
-
|
|
628
|
+
import_fs_extra7.default.ensureDirSync(registriesDataPath);
|
|
544
629
|
const config = getLocalConfig();
|
|
545
630
|
return await runTask("Update registries", async () => {
|
|
546
631
|
await Promise.all(
|
|
547
632
|
config.registries.map(async (registry) => {
|
|
548
633
|
debug(`update registry: ${registry}`);
|
|
549
634
|
const repoName = registry.split("/").pop() || "";
|
|
550
|
-
const repoDir =
|
|
551
|
-
if (!
|
|
552
|
-
await git.clone(registry, "--depth 1", { cwd: registriesDataPath });
|
|
553
|
-
} else if (
|
|
635
|
+
const repoDir = import_node_path8.default.join(registriesDataPath, repoName);
|
|
636
|
+
if (!import_fs_extra7.default.existsSync(repoDir)) {
|
|
637
|
+
await git.clone(registry, "--depth 1", branch, { cwd: registriesDataPath });
|
|
638
|
+
} else if (import_fs_extra7.default.existsSync(import_node_path8.default.join(repoDir, ".git"))) {
|
|
554
639
|
await git.update({ cwd: repoDir });
|
|
555
640
|
} else {
|
|
556
641
|
debug(`local registry`);
|
|
@@ -562,11 +647,11 @@ var syncRegistries = async () => {
|
|
|
562
647
|
var getAvailableTemplates = async () => {
|
|
563
648
|
debug("Get available templates");
|
|
564
649
|
const templates = {};
|
|
565
|
-
const registries =
|
|
650
|
+
const registries = import_fs_extra7.default.readdirSync(registriesDataPath);
|
|
566
651
|
for (const registry of registries) {
|
|
567
|
-
const indexPath =
|
|
568
|
-
if (
|
|
569
|
-
const data =
|
|
652
|
+
const indexPath = import_node_path8.default.join(registriesDataPath, registry, "index.json");
|
|
653
|
+
if (import_fs_extra7.default.existsSync(indexPath)) {
|
|
654
|
+
const data = import_fs_extra7.default.readJSONSync(indexPath);
|
|
570
655
|
Object.entries(data.templates || {}).forEach(([templateName, template]) => {
|
|
571
656
|
if (!template.source) {
|
|
572
657
|
template.source = `/template-${templateName}`;
|
|
@@ -606,29 +691,29 @@ var getAvailableBlocks = async (templateInfo) => {
|
|
|
606
691
|
return blocks;
|
|
607
692
|
};
|
|
608
693
|
var getAvailableVersions = async (source) => {
|
|
609
|
-
const registries =
|
|
694
|
+
const registries = import_fs_extra7.default.readdirSync(registriesDataPath);
|
|
610
695
|
for (const registry of registries) {
|
|
611
|
-
const registryPath =
|
|
612
|
-
const indexPath =
|
|
613
|
-
if (!
|
|
614
|
-
const registryData =
|
|
615
|
-
const versionDirPath =
|
|
696
|
+
const registryPath = import_node_path8.default.join(registriesDataPath, registry);
|
|
697
|
+
const indexPath = import_node_path8.default.join(registryPath, "index.json");
|
|
698
|
+
if (!import_fs_extra7.default.existsSync(indexPath)) continue;
|
|
699
|
+
const registryData = import_fs_extra7.default.readJSONSync(indexPath);
|
|
700
|
+
const versionDirPath = import_node_path8.default.join(registryPath, "versions");
|
|
616
701
|
const versionsFilePaths = [
|
|
617
|
-
|
|
618
|
-
|
|
702
|
+
import_node_path8.default.join(versionDirPath, `${source.replace(`${registryData.baseUrl}/`, "")}.json`),
|
|
703
|
+
import_node_path8.default.join(versionDirPath, `${encodeURIComponent(source)}.json`)
|
|
619
704
|
];
|
|
620
705
|
for (const versionsFile of versionsFilePaths) {
|
|
621
|
-
if (
|
|
622
|
-
return
|
|
706
|
+
if (import_fs_extra7.default.existsSync(versionsFile)) {
|
|
707
|
+
return import_fs_extra7.default.readJSONSync(versionsFile);
|
|
623
708
|
}
|
|
624
709
|
}
|
|
625
710
|
}
|
|
626
711
|
};
|
|
627
712
|
|
|
628
713
|
// src/services/template.ts
|
|
629
|
-
var
|
|
714
|
+
var import_node_path9 = __toESM(require("path"));
|
|
630
715
|
var import_ejs = __toESM(require("ejs"));
|
|
631
|
-
var
|
|
716
|
+
var import_fs_extra8 = __toESM(require("fs-extra"));
|
|
632
717
|
var import_klaw2 = __toESM(require("klaw"));
|
|
633
718
|
var NON_RENDERABLE_FILES = [
|
|
634
719
|
".png",
|
|
@@ -652,17 +737,17 @@ async function replacePlaceholders(dir, context) {
|
|
|
652
737
|
debug("Replace placeholders");
|
|
653
738
|
for await (const file of (0, import_klaw2.default)(dir)) {
|
|
654
739
|
if (!file.stats.isFile()) continue;
|
|
655
|
-
const ext =
|
|
740
|
+
const ext = import_node_path9.default.extname(file.path).toLowerCase();
|
|
656
741
|
if (NON_RENDERABLE_FILES.includes(ext)) {
|
|
657
742
|
continue;
|
|
658
743
|
}
|
|
659
|
-
const templateContent =
|
|
744
|
+
const templateContent = import_fs_extra8.default.readFileSync(file.path, "utf8");
|
|
660
745
|
if (!templateContent.includes("<%")) {
|
|
661
746
|
continue;
|
|
662
747
|
}
|
|
663
748
|
try {
|
|
664
749
|
const rendered = import_ejs.default.render(templateContent, context);
|
|
665
|
-
|
|
750
|
+
import_fs_extra8.default.writeFileSync(file.path, rendered, "utf8");
|
|
666
751
|
} catch (err) {
|
|
667
752
|
console.error("\u274C Error rendering EJS for file:", file.path);
|
|
668
753
|
throw err;
|
|
@@ -683,7 +768,7 @@ function getBlockDef(cwd = ".") {
|
|
|
683
768
|
}
|
|
684
769
|
function getBloxFile(cwd = ".") {
|
|
685
770
|
try {
|
|
686
|
-
const file =
|
|
771
|
+
const file = import_fs_extra8.default.readJSONSync(import_node_path9.default.join(cwd, bloxFilePath));
|
|
687
772
|
if (!file.checkpoints) {
|
|
688
773
|
file.checkpoints = {};
|
|
689
774
|
}
|
|
@@ -694,7 +779,7 @@ function getBloxFile(cwd = ".") {
|
|
|
694
779
|
}
|
|
695
780
|
function saveBloxFile(info, cwd = ".") {
|
|
696
781
|
debug("Save info");
|
|
697
|
-
|
|
782
|
+
import_fs_extra8.default.writeFileSync(import_node_path9.default.join(cwd, bloxFilePath), JSON.stringify(info, null, 2));
|
|
698
783
|
}
|
|
699
784
|
function updateCheckpoint(name, checkpoint, cwd = ".") {
|
|
700
785
|
const info = getBloxFile(cwd);
|
|
@@ -710,12 +795,12 @@ function getUsedBlocksDef() {
|
|
|
710
795
|
function getUsedBlocks() {
|
|
711
796
|
debug("Get used blocks");
|
|
712
797
|
const blocks = [];
|
|
713
|
-
if (
|
|
714
|
-
|
|
798
|
+
if (import_fs_extra8.default.existsSync(blocksDir)) {
|
|
799
|
+
import_fs_extra8.default.readdirSync(blocksDir, { withFileTypes: true }).forEach((file) => {
|
|
715
800
|
if (!file.isDirectory()) {
|
|
716
801
|
return;
|
|
717
802
|
}
|
|
718
|
-
const blockDef = getBloxFile(
|
|
803
|
+
const blockDef = getBloxFile(import_node_path9.default.join(blocksDir, file.name));
|
|
719
804
|
if (blockDef && blockDef.definition) {
|
|
720
805
|
blocks.push(blockDef);
|
|
721
806
|
}
|
|
@@ -858,15 +943,18 @@ function runInitScript(cwd) {
|
|
|
858
943
|
}
|
|
859
944
|
|
|
860
945
|
// src/commands/add/index.ts
|
|
861
|
-
var addBlock = async (block, blocks) => {
|
|
862
|
-
const blockPath = `blocks/${block}`;
|
|
946
|
+
var addBlock = async (block, blocks, branch, destination) => {
|
|
863
947
|
const blockRegistryData = blocks[block];
|
|
864
|
-
if (!
|
|
948
|
+
if (!destination) {
|
|
949
|
+
destination = blockRegistryData?.destination || block;
|
|
950
|
+
}
|
|
951
|
+
const blockPath = `blocks/${destination}`;
|
|
952
|
+
if (!import_fs_extra9.default.existsSync(blockPath)) {
|
|
865
953
|
await runTask(
|
|
866
954
|
{ start: `Fetching block: ${block}`, end: `Added block: ${block}` },
|
|
867
955
|
async () => {
|
|
868
956
|
const blockSource = blockRegistryData?.source || "";
|
|
869
|
-
await git.clone(blockSource, blockPath);
|
|
957
|
+
await git.clone(blockSource, blockPath, branch);
|
|
870
958
|
let commit2 = await selectVersion(blockSource);
|
|
871
959
|
if (commit2) {
|
|
872
960
|
await git.resetToCommit(commit2, blockPath);
|
|
@@ -878,7 +966,7 @@ var addBlock = async (block, blocks) => {
|
|
|
878
966
|
await migrateAll();
|
|
879
967
|
const def = getBlockDef(blockPath);
|
|
880
968
|
await deletePattern(blockPath, def.ignore);
|
|
881
|
-
updateCheckpoint(block, { commit: commit2 }, blockPath);
|
|
969
|
+
updateCheckpoint(block, { commit: commit2, branch }, blockPath);
|
|
882
970
|
}
|
|
883
971
|
);
|
|
884
972
|
await runTask("Run init script", async () => runInitScript(blockPath));
|
|
@@ -890,7 +978,7 @@ var addBlock = async (block, blocks) => {
|
|
|
890
978
|
await addBlock(dep.name, blocks);
|
|
891
979
|
}
|
|
892
980
|
};
|
|
893
|
-
var add2 = command("add").description("Add block to app").alias("a").argument("[block]", "Block to be added").action(async (block) => {
|
|
981
|
+
var add2 = command("add").description("Add block to app").alias("a").argument("[block]", "Block to be added").option("--branch <name>", "branch name").option("--dest <name>", "destination dir").action(async (block, { branch, dest }) => {
|
|
894
982
|
if (await git.hasUncommittedChanges()) {
|
|
895
983
|
import_prompts2.log.warn(fmt.yellow("Make sure to commit any changes first"));
|
|
896
984
|
return;
|
|
@@ -913,7 +1001,7 @@ var add2 = command("add").description("Add block to app").alias("a").argument("[
|
|
|
913
1001
|
if (!blocks[block]) {
|
|
914
1002
|
error("Selected block not available in registries");
|
|
915
1003
|
}
|
|
916
|
-
await addBlock(block, blocks);
|
|
1004
|
+
await addBlock(block, blocks, branch, dest);
|
|
917
1005
|
await checkVersionsCompatibility();
|
|
918
1006
|
} catch (e) {
|
|
919
1007
|
if (!isDebugMode()) {
|
|
@@ -988,8 +1076,8 @@ var detach = command("detach").description("Migrate blox schema").option("--basi
|
|
|
988
1076
|
});
|
|
989
1077
|
|
|
990
1078
|
// src/commands/init/index.ts
|
|
991
|
-
var
|
|
992
|
-
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 }) => {
|
|
1079
|
+
var import_fs_extra10 = __toESM(require("fs-extra"));
|
|
1080
|
+
var init2 = command("init").description("Init new app").alias("i").option("-n, --name <name>", "App name").option("-t, --template <template>", "Template to use").option("--branch <name>", "branch name").action(async ({ name, template, branch }) => {
|
|
993
1081
|
await syncRegistries();
|
|
994
1082
|
try {
|
|
995
1083
|
if (!name) {
|
|
@@ -1012,7 +1100,7 @@ var init2 = command("init").description("Init new app").alias("i").option("-n, -
|
|
|
1012
1100
|
const task = spinner();
|
|
1013
1101
|
task.start(`Fetch template`);
|
|
1014
1102
|
const templateSource = templates[template]?.source || "";
|
|
1015
|
-
await git.clone(templateSource, name);
|
|
1103
|
+
await git.clone(templateSource, name, branch);
|
|
1016
1104
|
let commit2 = await selectVersion(templateSource);
|
|
1017
1105
|
if (commit2) {
|
|
1018
1106
|
await git.resetToCommit(commit2, name);
|
|
@@ -1024,13 +1112,13 @@ var init2 = command("init").description("Init new app").alias("i").option("-n, -
|
|
|
1024
1112
|
const def = getTemplateDef(name);
|
|
1025
1113
|
await deletePattern(name, def.ignore);
|
|
1026
1114
|
await replacePlaceholders(name, { app: { name } });
|
|
1027
|
-
updateCheckpoint(def.name, { commit: commit2 }, name);
|
|
1115
|
+
updateCheckpoint(def.name, { commit: commit2, branch }, name);
|
|
1028
1116
|
await git.init(name);
|
|
1029
1117
|
task.stop(`App initialized in ${name}`);
|
|
1030
1118
|
await runTask("Run init script", async () => runInitScript(name || ""));
|
|
1031
1119
|
} catch (e) {
|
|
1032
|
-
if (name &&
|
|
1033
|
-
await
|
|
1120
|
+
if (name && import_fs_extra10.default.existsSync(name)) {
|
|
1121
|
+
await import_fs_extra10.default.remove(name);
|
|
1034
1122
|
}
|
|
1035
1123
|
error(e);
|
|
1036
1124
|
}
|
|
@@ -1053,25 +1141,27 @@ var migrateSchema = command("migrate").description("Migrate blox schema").action
|
|
|
1053
1141
|
var import_prompts15 = require("@clack/prompts");
|
|
1054
1142
|
|
|
1055
1143
|
// src/commands/update/utils.ts
|
|
1056
|
-
var
|
|
1144
|
+
var import_node_path11 = __toESM(require("path"));
|
|
1057
1145
|
|
|
1058
1146
|
// src/services/updater.ts
|
|
1059
|
-
var
|
|
1060
|
-
var
|
|
1147
|
+
var import_node_path10 = __toESM(require("path"));
|
|
1148
|
+
var import_fs_extra11 = __toESM(require("fs-extra"));
|
|
1061
1149
|
async function updateFromRemote({ name, source = "", ignore: ignore2 = [], dir = "." }) {
|
|
1062
1150
|
debug("Updating from remote");
|
|
1063
1151
|
await git.updateRemote(name, source);
|
|
1064
1152
|
const bloxFile = getBloxFile(dir);
|
|
1065
|
-
const
|
|
1153
|
+
const checkpoint = bloxFile.checkpoints[name];
|
|
1154
|
+
const fromCommit = checkpoint?.commit;
|
|
1066
1155
|
if (!fromCommit) {
|
|
1067
1156
|
debug("Skip update, no fromCommit found");
|
|
1068
1157
|
return;
|
|
1069
1158
|
}
|
|
1159
|
+
const branch = checkpoint?.branch || defaultBranch;
|
|
1070
1160
|
let toCommit = await selectVersion(source, fromCommit);
|
|
1071
1161
|
if (!toCommit) {
|
|
1072
|
-
toCommit = await git.getLatestCommitFromRemote(name);
|
|
1162
|
+
toCommit = await git.getLatestCommitFromRemote(name, branch);
|
|
1073
1163
|
}
|
|
1074
|
-
debug({ fromCommit, toCommit });
|
|
1164
|
+
debug({ fromCommit, toCommit, branch });
|
|
1075
1165
|
if (fromCommit == toCommit) {
|
|
1076
1166
|
debug("No new version");
|
|
1077
1167
|
return;
|
|
@@ -1092,13 +1182,13 @@ async function updateFromRemote({ name, source = "", ignore: ignore2 = [], dir =
|
|
|
1092
1182
|
);
|
|
1093
1183
|
}
|
|
1094
1184
|
}
|
|
1095
|
-
const patchFilePath =
|
|
1185
|
+
const patchFilePath = import_node_path10.default.join(dir, "diff.patch");
|
|
1096
1186
|
const remoteIgnore = remoteBloxFile.definition?.ignore || [];
|
|
1097
1187
|
ignore2.push(...remoteIgnore, ".blox", "**/.blox");
|
|
1098
1188
|
await git.createPatch(fromCommit, toCommit, patchFilePath, ignore2);
|
|
1099
1189
|
const deletePatchFile = async () => {
|
|
1100
1190
|
if (!isDebugMode()) {
|
|
1101
|
-
await
|
|
1191
|
+
await import_fs_extra11.default.unlink(patchFilePath);
|
|
1102
1192
|
}
|
|
1103
1193
|
debug("make sure to delete the patch file after you're done with it.");
|
|
1104
1194
|
};
|
|
@@ -1166,7 +1256,7 @@ async function updateApp({
|
|
|
1166
1256
|
const blockRegistryData = availableBlocks[block.name];
|
|
1167
1257
|
if (!blockRegistryData) return;
|
|
1168
1258
|
await git.updateRemote(block.name, blockRegistryData.source);
|
|
1169
|
-
const blockPath =
|
|
1259
|
+
const blockPath = import_node_path11.default.join(blocksDir, block.name);
|
|
1170
1260
|
const currentBloxFile = getBloxFile(blockPath);
|
|
1171
1261
|
const remoteBloxFile = (await migrateOnRemote(block.name, toAppCommit, blockPath)).output[".blox"];
|
|
1172
1262
|
const blockFromCommit = currentBloxFile.checkpoints?.[block.name]?.commit;
|
|
@@ -1199,7 +1289,7 @@ async function updateAppBases(templateDef, templates, ignore2) {
|
|
|
1199
1289
|
}
|
|
1200
1290
|
async function updateBlock(block, blocks, ignore2) {
|
|
1201
1291
|
const blockRegistryData = blocks[block];
|
|
1202
|
-
const blockPath =
|
|
1292
|
+
const blockPath = import_node_path11.default.join(blocksDir, block);
|
|
1203
1293
|
await runTask({ start: `Update block: ${block}`, end: `Updated block: ${block}` }, async () => {
|
|
1204
1294
|
if (!blockRegistryData) {
|
|
1205
1295
|
error(`Selected block: ${block} not available in registries`, false);
|
|
@@ -1340,6 +1430,7 @@ async function main() {
|
|
|
1340
1430
|
import_extra_typings2.program.name("blox").version(version);
|
|
1341
1431
|
import_extra_typings2.program.option("-d, --debug", "work in debug mode");
|
|
1342
1432
|
import_extra_typings2.program.option("-m, --minimal", "work in minimal mode");
|
|
1433
|
+
await checkForCliUpdate(version);
|
|
1343
1434
|
commands.forEach((cmd) => import_extra_typings2.program.addCommand(cmd));
|
|
1344
1435
|
import_extra_typings2.program.parse();
|
|
1345
1436
|
}
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -69,6 +69,7 @@ Init new app
|
|
|
69
69
|
Options:
|
|
70
70
|
-n, --name App name
|
|
71
71
|
-t, --template Template to use
|
|
72
|
+
--branch, branch name to use
|
|
72
73
|
```
|
|
73
74
|
|
|
74
75
|
#### add
|
|
@@ -84,6 +85,10 @@ Add block to app
|
|
|
84
85
|
|
|
85
86
|
Params:
|
|
86
87
|
block Block name (Optional)
|
|
88
|
+
|
|
89
|
+
Options:
|
|
90
|
+
--branch, branch name to use
|
|
91
|
+
--dest, destination dir
|
|
87
92
|
```
|
|
88
93
|
|
|
89
94
|
#### update
|