@naseej/blox 0.1.1 → 0.1.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 +2 -1
- package/dist/run.js +76 -16
- package/package.json +1 -1
- package/readme.md +8 -2
package/bin/run.ts
CHANGED
|
@@ -4,7 +4,8 @@ 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');
|
|
8
|
+
cli.option('-m, --minimal', 'work in minimal mode');
|
|
7
9
|
|
|
8
10
|
commands.forEach((cmd) => cli.addCommand(cmd));
|
|
9
|
-
|
|
10
11
|
cli.parse();
|
package/dist/run.js
CHANGED
|
@@ -31,7 +31,7 @@ var option = (flags, description) => {
|
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
// package.json
|
|
34
|
-
var version = "0.1.
|
|
34
|
+
var version = "0.1.3";
|
|
35
35
|
|
|
36
36
|
// src/services/git.ts
|
|
37
37
|
var import_node_path = __toESM(require("path"));
|
|
@@ -39,12 +39,36 @@ var import_fs_extra = __toESM(require("fs-extra"));
|
|
|
39
39
|
|
|
40
40
|
// src/services/shell.ts
|
|
41
41
|
var import_node_child_process = require("child_process");
|
|
42
|
+
|
|
43
|
+
// src/shared/logger.ts
|
|
44
|
+
var console = __toESM(require("console"));
|
|
45
|
+
var import_prompts = require("@clack/prompts");
|
|
46
|
+
|
|
47
|
+
// src/config/runtime.ts
|
|
48
|
+
var isDebugMode = () => !!import_extra_typings2.program.opts()?.debug;
|
|
49
|
+
var isMinimalMode = () => !!import_extra_typings2.program.opts()?.minimal;
|
|
50
|
+
|
|
51
|
+
// src/shared/logger.ts
|
|
52
|
+
var import_prompts2 = require("@clack/prompts");
|
|
53
|
+
var debug = (message) => {
|
|
54
|
+
if (!isDebugMode()) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (typeof message === "string") {
|
|
58
|
+
import_prompts.log.warn(message.trim());
|
|
59
|
+
} else {
|
|
60
|
+
console.log(JSON.stringify(message));
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// src/services/shell.ts
|
|
42
65
|
var $ = async (bin, options = [], { cwd, onStdout } = {}) => {
|
|
43
66
|
return new Promise(function(resolve, reject) {
|
|
44
67
|
const child = (0, import_node_child_process.spawn)(bin, options, { cwd, shell: true, stdio: ["pipe", "pipe", "pipe"] });
|
|
45
68
|
let error2 = "";
|
|
46
69
|
child.stdout.on("data", (data) => {
|
|
47
70
|
try {
|
|
71
|
+
debug(data.toString());
|
|
48
72
|
onStdout && onStdout(data.toString());
|
|
49
73
|
} catch (e) {
|
|
50
74
|
reject(e);
|
|
@@ -54,6 +78,7 @@ var $ = async (bin, options = [], { cwd, onStdout } = {}) => {
|
|
|
54
78
|
error2 += data.toString();
|
|
55
79
|
});
|
|
56
80
|
child.on("close", function(code) {
|
|
81
|
+
error2 && debug(error2);
|
|
57
82
|
if (code) {
|
|
58
83
|
reject(error2);
|
|
59
84
|
} else {
|
|
@@ -76,12 +101,16 @@ var defaultShellOptions = {
|
|
|
76
101
|
onStdout: checkAuth
|
|
77
102
|
};
|
|
78
103
|
var clone = (repoUrl, options, shellOptions = {}) => {
|
|
79
|
-
return $("git", ["clone", repoUrl, options], {
|
|
104
|
+
return $("git", ["clone", "--progress", repoUrl, options], {
|
|
105
|
+
...defaultShellOptions,
|
|
106
|
+
...shellOptions
|
|
107
|
+
});
|
|
80
108
|
};
|
|
81
109
|
var update = (shellOptions = {}) => {
|
|
82
|
-
return $("git", ["pull"], { ...defaultShellOptions, ...shellOptions });
|
|
110
|
+
return $("git", ["pull", "--progress"], { ...defaultShellOptions, ...shellOptions });
|
|
83
111
|
};
|
|
84
112
|
var getLatestCommit = async (cwd) => {
|
|
113
|
+
debug("Get latest commit");
|
|
85
114
|
let commit = "";
|
|
86
115
|
await $("git", ["rev-parse", "HEAD"], {
|
|
87
116
|
cwd,
|
|
@@ -105,9 +134,11 @@ var applyPatch = (patch, cwd = ".") => {
|
|
|
105
134
|
return $("git", args);
|
|
106
135
|
};
|
|
107
136
|
var unInit = (cwd) => {
|
|
137
|
+
debug("UnInit");
|
|
108
138
|
return import_fs_extra.default.remove(import_node_path.default.join(cwd, ".git"));
|
|
109
139
|
};
|
|
110
140
|
var init = async (cwd) => {
|
|
141
|
+
debug("Init");
|
|
111
142
|
await $("git", ["init"], { cwd });
|
|
112
143
|
await $("git", ["branch", "-m", "main"], { cwd });
|
|
113
144
|
await $("git", ["add", "."], { cwd });
|
|
@@ -140,14 +171,25 @@ var readJsonFile = (path7, defaultValue = {}) => {
|
|
|
140
171
|
}
|
|
141
172
|
};
|
|
142
173
|
|
|
143
|
-
// src/shared/logger.ts
|
|
144
|
-
var import_prompts = require("@clack/prompts");
|
|
145
|
-
|
|
146
174
|
// src/shared/spinner.ts
|
|
147
|
-
var import_prompts2 = require("@clack/prompts");
|
|
148
175
|
var import_prompts3 = require("@clack/prompts");
|
|
176
|
+
var spinner = () => {
|
|
177
|
+
const s = (0, import_prompts3.spinner)();
|
|
178
|
+
const minimal = isMinimalMode() || isDebugMode();
|
|
179
|
+
return {
|
|
180
|
+
start: (msg) => {
|
|
181
|
+
minimal ? import_prompts2.log.step(`${msg || "start"}...`) : s.start(msg);
|
|
182
|
+
},
|
|
183
|
+
stop: (msg, code) => {
|
|
184
|
+
minimal ? code ? import_prompts2.log.error(msg || "error") : import_prompts2.log.step(msg || "success") : s.stop(msg, code);
|
|
185
|
+
},
|
|
186
|
+
message: (msg) => {
|
|
187
|
+
minimal ? import_prompts2.log.message(msg) : s.message(msg);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
};
|
|
149
191
|
async function runTask(name, task) {
|
|
150
|
-
const taskSpinner =
|
|
192
|
+
const taskSpinner = spinner();
|
|
151
193
|
taskSpinner.start(name);
|
|
152
194
|
try {
|
|
153
195
|
await (typeof task === "function" ? task() : task);
|
|
@@ -182,6 +224,7 @@ var getLocalConfig = () => {
|
|
|
182
224
|
}
|
|
183
225
|
};
|
|
184
226
|
var updateLocalConfig = (config) => {
|
|
227
|
+
debug("Update local config");
|
|
185
228
|
import_fs_extra3.default.ensureFileSync(configFilePath);
|
|
186
229
|
const current = getLocalConfig();
|
|
187
230
|
import_fs_extra3.default.writeJsonSync(configFilePath, { ...current, ...config });
|
|
@@ -191,12 +234,14 @@ var updateLocalConfig = (config) => {
|
|
|
191
234
|
var registriesDataPath = import_node_path3.default.join(appPaths.data, "registries");
|
|
192
235
|
var registriesStatPath = import_node_path3.default.join(registriesDataPath, "stats.json");
|
|
193
236
|
var syncRegistries = async (logProgress = true) => {
|
|
237
|
+
debug("Sync registries");
|
|
238
|
+
logProgress = logProgress || isDebugMode();
|
|
194
239
|
import_fs_extra4.default.ensureDirSync(registriesDataPath);
|
|
195
240
|
const config = getLocalConfig();
|
|
196
241
|
const registriesStat = readJsonFile(registriesStatPath);
|
|
197
242
|
return Promise.all(
|
|
198
243
|
config.registries.map(async (registry) => {
|
|
199
|
-
const task =
|
|
244
|
+
const task = spinner();
|
|
200
245
|
try {
|
|
201
246
|
const repoName = registry.split("/").pop() || "";
|
|
202
247
|
logProgress && task.start(`Updating registry: ${registry}`);
|
|
@@ -214,7 +259,7 @@ var syncRegistries = async (logProgress = true) => {
|
|
|
214
259
|
await git.update({ cwd: repoDir });
|
|
215
260
|
registriesStat[repoName].lastUpdated = now.format();
|
|
216
261
|
} else {
|
|
217
|
-
logProgress &&
|
|
262
|
+
logProgress && import_prompts2.log.step(`Have recent version`);
|
|
218
263
|
}
|
|
219
264
|
import_fs_extra4.default.writeJSONSync(registriesStatPath, registriesStat);
|
|
220
265
|
logProgress && task.stop(`Updated registry: ${registry}`);
|
|
@@ -226,6 +271,7 @@ var syncRegistries = async (logProgress = true) => {
|
|
|
226
271
|
);
|
|
227
272
|
};
|
|
228
273
|
var getAvailableTemplates = async () => {
|
|
274
|
+
debug("Get available templates");
|
|
229
275
|
const templates = {};
|
|
230
276
|
for await (const file of (0, import_klaw.default)(registriesDataPath, {
|
|
231
277
|
filter: (item) => !item.includes(".git")
|
|
@@ -246,12 +292,16 @@ var getAvailableTemplates = async () => {
|
|
|
246
292
|
});
|
|
247
293
|
}
|
|
248
294
|
}
|
|
295
|
+
debug(templates);
|
|
249
296
|
return templates;
|
|
250
297
|
};
|
|
251
298
|
var getAvailableBlocks = async (templateName) => {
|
|
299
|
+
debug("Get available blocks");
|
|
252
300
|
const templates = await getAvailableTemplates();
|
|
253
301
|
const template = templates[templateName];
|
|
254
|
-
|
|
302
|
+
const blocks = template?.blocks || {};
|
|
303
|
+
debug(blocks);
|
|
304
|
+
return blocks;
|
|
255
305
|
};
|
|
256
306
|
|
|
257
307
|
// src/services/template.ts
|
|
@@ -260,6 +310,7 @@ var import_ejs = __toESM(require("ejs"));
|
|
|
260
310
|
var import_fs_extra5 = __toESM(require("fs-extra"));
|
|
261
311
|
var import_klaw2 = __toESM(require("klaw"));
|
|
262
312
|
async function replacePlaceholders(dir, context) {
|
|
313
|
+
debug("Replace placeholders");
|
|
263
314
|
for await (const file of (0, import_klaw2.default)(dir)) {
|
|
264
315
|
if (file.stats.isFile()) {
|
|
265
316
|
const template = import_fs_extra5.default.readFileSync(file.path, "utf-8");
|
|
@@ -272,12 +323,16 @@ function getPackage(cwd) {
|
|
|
272
323
|
return import_fs_extra5.default.readJSONSync(import_node_path4.default.join(cwd, "package.json"));
|
|
273
324
|
}
|
|
274
325
|
function getTemplateInfo(cwd = ".") {
|
|
275
|
-
|
|
326
|
+
debug("Get template info");
|
|
327
|
+
const templateInfo = getPackage(cwd).blox;
|
|
328
|
+
debug(templateInfo);
|
|
329
|
+
return templateInfo;
|
|
276
330
|
}
|
|
277
331
|
function getBasedOnInfo(cwd = ".") {
|
|
278
332
|
return import_fs_extra5.default.readJSONSync(import_node_path4.default.join(cwd, basedOnFile));
|
|
279
333
|
}
|
|
280
334
|
function saveBasedOnInfo(info, cwd = ".") {
|
|
335
|
+
debug("Save info");
|
|
281
336
|
import_fs_extra5.default.writeJSONSync(import_node_path4.default.join(cwd, basedOnFile), info);
|
|
282
337
|
}
|
|
283
338
|
function updateBasedOnInfo(updates, cwd = ".") {
|
|
@@ -285,6 +340,7 @@ function updateBasedOnInfo(updates, cwd = ".") {
|
|
|
285
340
|
saveBasedOnInfo({ ...info, ...updates }, cwd);
|
|
286
341
|
}
|
|
287
342
|
function getUsedBlocks() {
|
|
343
|
+
debug("Get used blocks");
|
|
288
344
|
const blocks = [];
|
|
289
345
|
if (import_fs_extra5.default.existsSync(blocksDir)) {
|
|
290
346
|
import_fs_extra5.default.readdirSync(blocksDir, { withFileTypes: true }).forEach((file) => {
|
|
@@ -297,6 +353,7 @@ function getUsedBlocks() {
|
|
|
297
353
|
}
|
|
298
354
|
});
|
|
299
355
|
}
|
|
356
|
+
debug(blocks);
|
|
300
357
|
return blocks;
|
|
301
358
|
}
|
|
302
359
|
|
|
@@ -357,7 +414,7 @@ var add = command("add").description("Add block to app").alias("a").argument("[b
|
|
|
357
414
|
if (!blocks[block]) {
|
|
358
415
|
error("Selected block not available, try to sync registries");
|
|
359
416
|
}
|
|
360
|
-
const task =
|
|
417
|
+
const task = spinner();
|
|
361
418
|
task.start(`Fetch block`);
|
|
362
419
|
const blockPath = `blocks/${block}`;
|
|
363
420
|
await git.clone(blocks[block]?.source || "", blockPath);
|
|
@@ -395,7 +452,7 @@ var conf = command("conf").description("Set blox global config").alias("c").opti
|
|
|
395
452
|
}
|
|
396
453
|
try {
|
|
397
454
|
updateLocalConfig({ registries, syncFrequency });
|
|
398
|
-
|
|
455
|
+
import_prompts2.log.success("local config updated successfully.");
|
|
399
456
|
} catch (e) {
|
|
400
457
|
error(e);
|
|
401
458
|
}
|
|
@@ -422,7 +479,7 @@ var init2 = command("init").description("Init new app").alias("i").option("-n, -
|
|
|
422
479
|
if (!templates[template]) {
|
|
423
480
|
error("Selected template not available, try to sync registries");
|
|
424
481
|
}
|
|
425
|
-
const task =
|
|
482
|
+
const task = spinner();
|
|
426
483
|
task.start(`Fetch template`);
|
|
427
484
|
await git.clone(templates[template]?.source || "", name);
|
|
428
485
|
const commit = await git.getLatestCommit(name);
|
|
@@ -440,7 +497,7 @@ var init2 = command("init").description("Init new app").alias("i").option("-n, -
|
|
|
440
497
|
var sync = command("sync").description("Sync local registry with remote updates").alias("s").action(async () => {
|
|
441
498
|
try {
|
|
442
499
|
await syncRegistries();
|
|
443
|
-
|
|
500
|
+
import_prompts2.log.success("Local registries synced successfully.");
|
|
444
501
|
} catch (e) {
|
|
445
502
|
error(e);
|
|
446
503
|
}
|
|
@@ -453,6 +510,7 @@ var import_node_path6 = __toESM(require("path"));
|
|
|
453
510
|
var import_node_path5 = __toESM(require("path"));
|
|
454
511
|
var import_fs_extra6 = __toESM(require("fs-extra"));
|
|
455
512
|
async function updateFromRemote(name, source = "", destPath = ".") {
|
|
513
|
+
debug("Updating from remote");
|
|
456
514
|
import_fs_extra6.default.ensureDirSync(appPaths.temp);
|
|
457
515
|
const tmpClone = import_node_path5.default.join(appPaths.temp, name);
|
|
458
516
|
await import_fs_extra6.default.remove(tmpClone);
|
|
@@ -511,5 +569,7 @@ var commands = [init2, add, update2, sync, conf];
|
|
|
511
569
|
|
|
512
570
|
// bin/run.ts
|
|
513
571
|
import_extra_typings2.program.name("blox").version(version);
|
|
572
|
+
import_extra_typings2.program.option("-d, --debug", "work in debug mode");
|
|
573
|
+
import_extra_typings2.program.option("-m, --minimal", "work in minimal mode");
|
|
514
574
|
commands.forEach((cmd) => import_extra_typings2.program.addCommand(cmd));
|
|
515
575
|
import_extra_typings2.program.parse();
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -12,6 +12,8 @@ It can have many way to be installed, mainly as global npm package
|
|
|
12
12
|
yarn global add @naseej/blox
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
+
* make sure npm is already in you $Path to be able to use blox globally
|
|
16
|
+
|
|
15
17
|
### Usage
|
|
16
18
|
|
|
17
19
|
```sh
|
|
@@ -29,10 +31,14 @@ Commands:
|
|
|
29
31
|
blox conf Set blox global config [alias: c]
|
|
30
32
|
|
|
31
33
|
Options:
|
|
32
|
-
--version Show version number [boolean]
|
|
33
|
-
--help Show help [boolean]
|
|
34
|
+
-V, --version Show version number [boolean]
|
|
35
|
+
-h, --help Show help [boolean]
|
|
36
|
+
-d, --debug Works in debug mode [boolean]
|
|
37
|
+
-m, --minimal Works in minimal mode [boolean]
|
|
34
38
|
```
|
|
35
39
|
|
|
40
|
+
* Use minimal mode if spinners are getting in the way of needed input for example.
|
|
41
|
+
|
|
36
42
|
### Available commands
|
|
37
43
|
|
|
38
44
|
* [init](#init)
|