@naseej/blox 0.1.0 → 0.1.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.ts +3 -0
- package/dist/run.js +83 -23
- package/package.json +1 -1
- package/readme.md +3 -2
package/bin/run.ts
CHANGED
|
@@ -4,7 +4,10 @@ import { version } from '../package.json';
|
|
|
4
4
|
import { commands } from '../src';
|
|
5
5
|
|
|
6
6
|
cli.name('blox').version(version);
|
|
7
|
+
cli.option('-d, --debug', 'work in debug mode');
|
|
7
8
|
|
|
8
9
|
commands.forEach((cmd) => cli.addCommand(cmd));
|
|
9
10
|
|
|
10
11
|
cli.parse();
|
|
12
|
+
|
|
13
|
+
export const isDebugMode = (cli.opts() as any)?.debug;
|
package/dist/run.js
CHANGED
|
@@ -5,6 +5,10 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
8
12
|
var __copyProps = (to, from, except, desc) => {
|
|
9
13
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
14
|
for (let key of __getOwnPropNames(from))
|
|
@@ -21,6 +25,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
25
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
26
|
mod
|
|
23
27
|
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// bin/run.ts
|
|
31
|
+
var run_exports = {};
|
|
32
|
+
__export(run_exports, {
|
|
33
|
+
isDebugMode: () => isDebugMode
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(run_exports);
|
|
24
36
|
|
|
25
37
|
// src/shared/command/index.ts
|
|
26
38
|
var import_extra_typings = require("@commander-js/extra-typings");
|
|
@@ -31,7 +43,7 @@ var option = (flags, description) => {
|
|
|
31
43
|
};
|
|
32
44
|
|
|
33
45
|
// package.json
|
|
34
|
-
var version = "0.1.
|
|
46
|
+
var version = "0.1.2";
|
|
35
47
|
|
|
36
48
|
// src/services/git.ts
|
|
37
49
|
var import_node_path = __toESM(require("path"));
|
|
@@ -39,12 +51,30 @@ var import_fs_extra = __toESM(require("fs-extra"));
|
|
|
39
51
|
|
|
40
52
|
// src/services/shell.ts
|
|
41
53
|
var import_node_child_process = require("child_process");
|
|
54
|
+
|
|
55
|
+
// src/shared/logger.ts
|
|
56
|
+
var console = __toESM(require("console"));
|
|
57
|
+
var import_prompts = require("@clack/prompts");
|
|
58
|
+
var import_prompts2 = require("@clack/prompts");
|
|
59
|
+
var debug = (message) => {
|
|
60
|
+
if (!isDebugMode) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (typeof message === "string") {
|
|
64
|
+
import_prompts.log.warn(message.trim());
|
|
65
|
+
} else {
|
|
66
|
+
console.log(JSON.stringify(message));
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// src/services/shell.ts
|
|
42
71
|
var $ = async (bin, options = [], { cwd, onStdout } = {}) => {
|
|
43
72
|
return new Promise(function(resolve, reject) {
|
|
44
73
|
const child = (0, import_node_child_process.spawn)(bin, options, { cwd, shell: true, stdio: ["pipe", "pipe", "pipe"] });
|
|
45
74
|
let error2 = "";
|
|
46
75
|
child.stdout.on("data", (data) => {
|
|
47
76
|
try {
|
|
77
|
+
debug(data.toString());
|
|
48
78
|
onStdout && onStdout(data.toString());
|
|
49
79
|
} catch (e) {
|
|
50
80
|
reject(e);
|
|
@@ -54,6 +84,7 @@ var $ = async (bin, options = [], { cwd, onStdout } = {}) => {
|
|
|
54
84
|
error2 += data.toString();
|
|
55
85
|
});
|
|
56
86
|
child.on("close", function(code) {
|
|
87
|
+
error2 && debug(error2);
|
|
57
88
|
if (code) {
|
|
58
89
|
reject(error2);
|
|
59
90
|
} else {
|
|
@@ -76,10 +107,13 @@ var defaultShellOptions = {
|
|
|
76
107
|
onStdout: checkAuth
|
|
77
108
|
};
|
|
78
109
|
var clone = (repoUrl, options, shellOptions = {}) => {
|
|
79
|
-
return $("git", ["clone", repoUrl, options], {
|
|
110
|
+
return $("git", ["clone", "--progress", repoUrl, options], {
|
|
111
|
+
...defaultShellOptions,
|
|
112
|
+
...shellOptions
|
|
113
|
+
});
|
|
80
114
|
};
|
|
81
115
|
var update = (shellOptions = {}) => {
|
|
82
|
-
return $("git", ["pull"], { ...defaultShellOptions, ...shellOptions });
|
|
116
|
+
return $("git", ["pull", "--progress"], { ...defaultShellOptions, ...shellOptions });
|
|
83
117
|
};
|
|
84
118
|
var getLatestCommit = async (cwd) => {
|
|
85
119
|
let commit = "";
|
|
@@ -140,14 +174,24 @@ var readJsonFile = (path7, defaultValue = {}) => {
|
|
|
140
174
|
}
|
|
141
175
|
};
|
|
142
176
|
|
|
143
|
-
// src/shared/logger.ts
|
|
144
|
-
var import_prompts = require("@clack/prompts");
|
|
145
|
-
|
|
146
177
|
// src/shared/spinner.ts
|
|
147
|
-
var import_prompts2 = require("@clack/prompts");
|
|
148
178
|
var import_prompts3 = require("@clack/prompts");
|
|
179
|
+
var spinner = () => {
|
|
180
|
+
const s = (0, import_prompts3.spinner)();
|
|
181
|
+
return {
|
|
182
|
+
start: (msg) => {
|
|
183
|
+
isDebugMode ? import_prompts2.log.step(msg || "start") : s.start(msg);
|
|
184
|
+
},
|
|
185
|
+
stop: (msg, code) => {
|
|
186
|
+
isDebugMode ? code ? import_prompts2.log.error(msg || "error") : import_prompts2.log.step(msg || "success") : s.stop(msg, code);
|
|
187
|
+
},
|
|
188
|
+
message: (msg) => {
|
|
189
|
+
isDebugMode ? debug(msg) : s.message(msg);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
};
|
|
149
193
|
async function runTask(name, task) {
|
|
150
|
-
const taskSpinner =
|
|
194
|
+
const taskSpinner = spinner();
|
|
151
195
|
taskSpinner.start(name);
|
|
152
196
|
try {
|
|
153
197
|
await (typeof task === "function" ? task() : task);
|
|
@@ -196,7 +240,7 @@ var syncRegistries = async (logProgress = true) => {
|
|
|
196
240
|
const registriesStat = readJsonFile(registriesStatPath);
|
|
197
241
|
return Promise.all(
|
|
198
242
|
config.registries.map(async (registry) => {
|
|
199
|
-
const task =
|
|
243
|
+
const task = spinner();
|
|
200
244
|
try {
|
|
201
245
|
const repoName = registry.split("/").pop() || "";
|
|
202
246
|
logProgress && task.start(`Updating registry: ${registry}`);
|
|
@@ -214,7 +258,7 @@ var syncRegistries = async (logProgress = true) => {
|
|
|
214
258
|
await git.update({ cwd: repoDir });
|
|
215
259
|
registriesStat[repoName].lastUpdated = now.format();
|
|
216
260
|
} else {
|
|
217
|
-
logProgress &&
|
|
261
|
+
logProgress && import_prompts2.log.step(`Have recent version`);
|
|
218
262
|
}
|
|
219
263
|
import_fs_extra4.default.writeJSONSync(registriesStatPath, registriesStat);
|
|
220
264
|
logProgress && task.stop(`Updated registry: ${registry}`);
|
|
@@ -286,15 +330,17 @@ function updateBasedOnInfo(updates, cwd = ".") {
|
|
|
286
330
|
}
|
|
287
331
|
function getUsedBlocks() {
|
|
288
332
|
const blocks = [];
|
|
289
|
-
import_fs_extra5.default.
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
333
|
+
if (import_fs_extra5.default.existsSync(blocksDir)) {
|
|
334
|
+
import_fs_extra5.default.readdirSync(blocksDir, { withFileTypes: true }).forEach((file) => {
|
|
335
|
+
if (!file.isDirectory()) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
const templateInfo = getTemplateInfo(import_node_path4.default.join(blocksDir, file.name));
|
|
339
|
+
if (templateInfo) {
|
|
340
|
+
blocks.push(templateInfo);
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
}
|
|
298
344
|
return blocks;
|
|
299
345
|
}
|
|
300
346
|
|
|
@@ -355,7 +401,7 @@ var add = command("add").description("Add block to app").alias("a").argument("[b
|
|
|
355
401
|
if (!blocks[block]) {
|
|
356
402
|
error("Selected block not available, try to sync registries");
|
|
357
403
|
}
|
|
358
|
-
const task =
|
|
404
|
+
const task = spinner();
|
|
359
405
|
task.start(`Fetch block`);
|
|
360
406
|
const blockPath = `blocks/${block}`;
|
|
361
407
|
await git.clone(blocks[block]?.source || "", blockPath);
|
|
@@ -393,7 +439,7 @@ var conf = command("conf").description("Set blox global config").alias("c").opti
|
|
|
393
439
|
}
|
|
394
440
|
try {
|
|
395
441
|
updateLocalConfig({ registries, syncFrequency });
|
|
396
|
-
|
|
442
|
+
import_prompts2.log.success("local config updated successfully.");
|
|
397
443
|
} catch (e) {
|
|
398
444
|
error(e);
|
|
399
445
|
}
|
|
@@ -401,12 +447,15 @@ var conf = command("conf").description("Set blox global config").alias("c").opti
|
|
|
401
447
|
|
|
402
448
|
// src/commands/init/index.ts
|
|
403
449
|
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 }) => {
|
|
450
|
+
debug("Warning: in debug mode");
|
|
404
451
|
await syncRegistries(false);
|
|
405
452
|
try {
|
|
406
453
|
if (!name) {
|
|
407
454
|
name = await text({ message: "Select app name" });
|
|
408
455
|
}
|
|
456
|
+
debug("Get available templates");
|
|
409
457
|
const templates = await getAvailableTemplates();
|
|
458
|
+
debug(templates);
|
|
410
459
|
if (!template) {
|
|
411
460
|
template = await select({
|
|
412
461
|
message: "Select template to be used",
|
|
@@ -420,13 +469,18 @@ var init2 = command("init").description("Init new app").alias("i").option("-n, -
|
|
|
420
469
|
if (!templates[template]) {
|
|
421
470
|
error("Selected template not available, try to sync registries");
|
|
422
471
|
}
|
|
423
|
-
const task =
|
|
472
|
+
const task = spinner();
|
|
424
473
|
task.start(`Fetch template`);
|
|
425
474
|
await git.clone(templates[template]?.source || "", name);
|
|
475
|
+
debug("Get latest commit");
|
|
426
476
|
const commit = await git.getLatestCommit(name);
|
|
477
|
+
debug("UnInit");
|
|
427
478
|
await git.unInit(name);
|
|
479
|
+
debug("Replace placeholders");
|
|
428
480
|
await replacePlaceholders(name, { app: { name } });
|
|
481
|
+
debug("Save info");
|
|
429
482
|
saveBasedOnInfo({ commit }, name);
|
|
483
|
+
debug("Init");
|
|
430
484
|
await git.init(name);
|
|
431
485
|
task.stop(`App initialized in ${name}`);
|
|
432
486
|
} catch (e) {
|
|
@@ -438,7 +492,7 @@ var init2 = command("init").description("Init new app").alias("i").option("-n, -
|
|
|
438
492
|
var sync = command("sync").description("Sync local registry with remote updates").alias("s").action(async () => {
|
|
439
493
|
try {
|
|
440
494
|
await syncRegistries();
|
|
441
|
-
|
|
495
|
+
import_prompts2.log.success("Local registries synced successfully.");
|
|
442
496
|
} catch (e) {
|
|
443
497
|
error(e);
|
|
444
498
|
}
|
|
@@ -509,5 +563,11 @@ var commands = [init2, add, update2, sync, conf];
|
|
|
509
563
|
|
|
510
564
|
// bin/run.ts
|
|
511
565
|
import_extra_typings2.program.name("blox").version(version);
|
|
566
|
+
import_extra_typings2.program.option("-d, --debug", "work in debug mode");
|
|
512
567
|
commands.forEach((cmd) => import_extra_typings2.program.addCommand(cmd));
|
|
513
568
|
import_extra_typings2.program.parse();
|
|
569
|
+
var isDebugMode = import_extra_typings2.program.opts()?.debug;
|
|
570
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
571
|
+
0 && (module.exports = {
|
|
572
|
+
isDebugMode
|
|
573
|
+
});
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -29,8 +29,9 @@ Commands:
|
|
|
29
29
|
blox conf Set blox global config [alias: c]
|
|
30
30
|
|
|
31
31
|
Options:
|
|
32
|
-
--version Show version number [boolean]
|
|
33
|
-
--help Show help [boolean]
|
|
32
|
+
-V, --version Show version number [boolean]
|
|
33
|
+
-h, --help Show help [boolean]
|
|
34
|
+
-d, --debug Show debug messages [boolean]
|
|
34
35
|
```
|
|
35
36
|
|
|
36
37
|
### Available commands
|