@naseej/blox 0.1.2 → 0.1.4
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 +1 -3
- package/dist/run.js +45 -40
- package/package.json +1 -1
- package/readme.md +12 -2
package/bin/run.ts
CHANGED
|
@@ -5,9 +5,7 @@ import { commands } from '../src';
|
|
|
5
5
|
|
|
6
6
|
cli.name('blox').version(version);
|
|
7
7
|
cli.option('-d, --debug', 'work in debug mode');
|
|
8
|
+
cli.option('-m, --minimal', 'work in minimal mode');
|
|
8
9
|
|
|
9
10
|
commands.forEach((cmd) => cli.addCommand(cmd));
|
|
10
|
-
|
|
11
11
|
cli.parse();
|
|
12
|
-
|
|
13
|
-
export const isDebugMode = (cli.opts() as any)?.debug;
|
package/dist/run.js
CHANGED
|
@@ -5,10 +5,6 @@ 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
|
-
};
|
|
12
8
|
var __copyProps = (to, from, except, desc) => {
|
|
13
9
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
10
|
for (let key of __getOwnPropNames(from))
|
|
@@ -25,14 +21,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
25
21
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
22
|
mod
|
|
27
23
|
));
|
|
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);
|
|
36
24
|
|
|
37
25
|
// src/shared/command/index.ts
|
|
38
26
|
var import_extra_typings = require("@commander-js/extra-typings");
|
|
@@ -43,7 +31,7 @@ var option = (flags, description) => {
|
|
|
43
31
|
};
|
|
44
32
|
|
|
45
33
|
// package.json
|
|
46
|
-
var version = "0.1.
|
|
34
|
+
var version = "0.1.4";
|
|
47
35
|
|
|
48
36
|
// src/services/git.ts
|
|
49
37
|
var import_node_path = __toESM(require("path"));
|
|
@@ -55,9 +43,15 @@ var import_node_child_process = require("child_process");
|
|
|
55
43
|
// src/shared/logger.ts
|
|
56
44
|
var console = __toESM(require("console"));
|
|
57
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
|
|
58
52
|
var import_prompts2 = require("@clack/prompts");
|
|
59
53
|
var debug = (message) => {
|
|
60
|
-
if (!isDebugMode) {
|
|
54
|
+
if (!isDebugMode()) {
|
|
61
55
|
return;
|
|
62
56
|
}
|
|
63
57
|
if (typeof message === "string") {
|
|
@@ -116,6 +110,7 @@ var update = (shellOptions = {}) => {
|
|
|
116
110
|
return $("git", ["pull", "--progress"], { ...defaultShellOptions, ...shellOptions });
|
|
117
111
|
};
|
|
118
112
|
var getLatestCommit = async (cwd) => {
|
|
113
|
+
debug("Get latest commit");
|
|
119
114
|
let commit = "";
|
|
120
115
|
await $("git", ["rev-parse", "HEAD"], {
|
|
121
116
|
cwd,
|
|
@@ -125,23 +120,25 @@ var getLatestCommit = async (cwd) => {
|
|
|
125
120
|
});
|
|
126
121
|
return commit.replace(/\n/g, "");
|
|
127
122
|
};
|
|
128
|
-
var
|
|
123
|
+
var patchesDir = ".update_patches";
|
|
129
124
|
var createPatch = async (cwd, fromCommit, toCommit) => {
|
|
130
|
-
return $("git", ["
|
|
125
|
+
return $("git", ["format-patch", "-o", patchesDir, `${fromCommit}..${toCommit}`], { cwd });
|
|
131
126
|
};
|
|
132
|
-
var applyPatch = (
|
|
127
|
+
var applyPatch = (patchs, cwd = ".") => {
|
|
133
128
|
const args = ["apply", "-3"];
|
|
134
129
|
if (cwd != ".") {
|
|
135
130
|
args.push("--directory");
|
|
136
131
|
args.push(cwd);
|
|
137
132
|
}
|
|
138
|
-
args.push(patch);
|
|
133
|
+
args.push(`${patchs}/*.patch`);
|
|
139
134
|
return $("git", args);
|
|
140
135
|
};
|
|
141
136
|
var unInit = (cwd) => {
|
|
137
|
+
debug("UnInit");
|
|
142
138
|
return import_fs_extra.default.remove(import_node_path.default.join(cwd, ".git"));
|
|
143
139
|
};
|
|
144
140
|
var init = async (cwd) => {
|
|
141
|
+
debug("Init");
|
|
145
142
|
await $("git", ["init"], { cwd });
|
|
146
143
|
await $("git", ["branch", "-m", "main"], { cwd });
|
|
147
144
|
await $("git", ["add", "."], { cwd });
|
|
@@ -178,15 +175,16 @@ var readJsonFile = (path7, defaultValue = {}) => {
|
|
|
178
175
|
var import_prompts3 = require("@clack/prompts");
|
|
179
176
|
var spinner = () => {
|
|
180
177
|
const s = (0, import_prompts3.spinner)();
|
|
178
|
+
const minimal = isMinimalMode() || isDebugMode();
|
|
181
179
|
return {
|
|
182
180
|
start: (msg) => {
|
|
183
|
-
|
|
181
|
+
minimal ? import_prompts2.log.step(`${msg || "start"}...`) : s.start(msg);
|
|
184
182
|
},
|
|
185
183
|
stop: (msg, code) => {
|
|
186
|
-
|
|
184
|
+
minimal ? code ? import_prompts2.log.error(msg || "error") : import_prompts2.log.step(msg || "success") : s.stop(msg, code);
|
|
187
185
|
},
|
|
188
186
|
message: (msg) => {
|
|
189
|
-
|
|
187
|
+
minimal ? import_prompts2.log.message(msg) : s.message(msg);
|
|
190
188
|
}
|
|
191
189
|
};
|
|
192
190
|
};
|
|
@@ -226,6 +224,7 @@ var getLocalConfig = () => {
|
|
|
226
224
|
}
|
|
227
225
|
};
|
|
228
226
|
var updateLocalConfig = (config) => {
|
|
227
|
+
debug("Update local config");
|
|
229
228
|
import_fs_extra3.default.ensureFileSync(configFilePath);
|
|
230
229
|
const current = getLocalConfig();
|
|
231
230
|
import_fs_extra3.default.writeJsonSync(configFilePath, { ...current, ...config });
|
|
@@ -235,6 +234,8 @@ var updateLocalConfig = (config) => {
|
|
|
235
234
|
var registriesDataPath = import_node_path3.default.join(appPaths.data, "registries");
|
|
236
235
|
var registriesStatPath = import_node_path3.default.join(registriesDataPath, "stats.json");
|
|
237
236
|
var syncRegistries = async (logProgress = true) => {
|
|
237
|
+
debug("Sync registries");
|
|
238
|
+
logProgress = logProgress || isDebugMode();
|
|
238
239
|
import_fs_extra4.default.ensureDirSync(registriesDataPath);
|
|
239
240
|
const config = getLocalConfig();
|
|
240
241
|
const registriesStat = readJsonFile(registriesStatPath);
|
|
@@ -270,6 +271,7 @@ var syncRegistries = async (logProgress = true) => {
|
|
|
270
271
|
);
|
|
271
272
|
};
|
|
272
273
|
var getAvailableTemplates = async () => {
|
|
274
|
+
debug("Get available templates");
|
|
273
275
|
const templates = {};
|
|
274
276
|
for await (const file of (0, import_klaw.default)(registriesDataPath, {
|
|
275
277
|
filter: (item) => !item.includes(".git")
|
|
@@ -290,12 +292,16 @@ var getAvailableTemplates = async () => {
|
|
|
290
292
|
});
|
|
291
293
|
}
|
|
292
294
|
}
|
|
295
|
+
debug(templates);
|
|
293
296
|
return templates;
|
|
294
297
|
};
|
|
295
298
|
var getAvailableBlocks = async (templateName) => {
|
|
299
|
+
debug("Get available blocks");
|
|
296
300
|
const templates = await getAvailableTemplates();
|
|
297
301
|
const template = templates[templateName];
|
|
298
|
-
|
|
302
|
+
const blocks = template?.blocks || {};
|
|
303
|
+
debug(blocks);
|
|
304
|
+
return blocks;
|
|
299
305
|
};
|
|
300
306
|
|
|
301
307
|
// src/services/template.ts
|
|
@@ -304,6 +310,7 @@ var import_ejs = __toESM(require("ejs"));
|
|
|
304
310
|
var import_fs_extra5 = __toESM(require("fs-extra"));
|
|
305
311
|
var import_klaw2 = __toESM(require("klaw"));
|
|
306
312
|
async function replacePlaceholders(dir, context) {
|
|
313
|
+
debug("Replace placeholders");
|
|
307
314
|
for await (const file of (0, import_klaw2.default)(dir)) {
|
|
308
315
|
if (file.stats.isFile()) {
|
|
309
316
|
const template = import_fs_extra5.default.readFileSync(file.path, "utf-8");
|
|
@@ -316,12 +323,16 @@ function getPackage(cwd) {
|
|
|
316
323
|
return import_fs_extra5.default.readJSONSync(import_node_path4.default.join(cwd, "package.json"));
|
|
317
324
|
}
|
|
318
325
|
function getTemplateInfo(cwd = ".") {
|
|
319
|
-
|
|
326
|
+
debug("Get template info");
|
|
327
|
+
const templateInfo = getPackage(cwd).blox;
|
|
328
|
+
debug(templateInfo);
|
|
329
|
+
return templateInfo;
|
|
320
330
|
}
|
|
321
331
|
function getBasedOnInfo(cwd = ".") {
|
|
322
332
|
return import_fs_extra5.default.readJSONSync(import_node_path4.default.join(cwd, basedOnFile));
|
|
323
333
|
}
|
|
324
334
|
function saveBasedOnInfo(info, cwd = ".") {
|
|
335
|
+
debug("Save info");
|
|
325
336
|
import_fs_extra5.default.writeJSONSync(import_node_path4.default.join(cwd, basedOnFile), info);
|
|
326
337
|
}
|
|
327
338
|
function updateBasedOnInfo(updates, cwd = ".") {
|
|
@@ -329,6 +340,7 @@ function updateBasedOnInfo(updates, cwd = ".") {
|
|
|
329
340
|
saveBasedOnInfo({ ...info, ...updates }, cwd);
|
|
330
341
|
}
|
|
331
342
|
function getUsedBlocks() {
|
|
343
|
+
debug("Get used blocks");
|
|
332
344
|
const blocks = [];
|
|
333
345
|
if (import_fs_extra5.default.existsSync(blocksDir)) {
|
|
334
346
|
import_fs_extra5.default.readdirSync(blocksDir, { withFileTypes: true }).forEach((file) => {
|
|
@@ -341,6 +353,7 @@ function getUsedBlocks() {
|
|
|
341
353
|
}
|
|
342
354
|
});
|
|
343
355
|
}
|
|
356
|
+
debug(blocks);
|
|
344
357
|
return blocks;
|
|
345
358
|
}
|
|
346
359
|
|
|
@@ -447,15 +460,12 @@ var conf = command("conf").description("Set blox global config").alias("c").opti
|
|
|
447
460
|
|
|
448
461
|
// src/commands/init/index.ts
|
|
449
462
|
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");
|
|
451
463
|
await syncRegistries(false);
|
|
452
464
|
try {
|
|
453
465
|
if (!name) {
|
|
454
466
|
name = await text({ message: "Select app name" });
|
|
455
467
|
}
|
|
456
|
-
debug("Get available templates");
|
|
457
468
|
const templates = await getAvailableTemplates();
|
|
458
|
-
debug(templates);
|
|
459
469
|
if (!template) {
|
|
460
470
|
template = await select({
|
|
461
471
|
message: "Select template to be used",
|
|
@@ -472,15 +482,10 @@ var init2 = command("init").description("Init new app").alias("i").option("-n, -
|
|
|
472
482
|
const task = spinner();
|
|
473
483
|
task.start(`Fetch template`);
|
|
474
484
|
await git.clone(templates[template]?.source || "", name);
|
|
475
|
-
debug("Get latest commit");
|
|
476
485
|
const commit = await git.getLatestCommit(name);
|
|
477
|
-
debug("UnInit");
|
|
478
486
|
await git.unInit(name);
|
|
479
|
-
debug("Replace placeholders");
|
|
480
487
|
await replacePlaceholders(name, { app: { name } });
|
|
481
|
-
debug("Save info");
|
|
482
488
|
saveBasedOnInfo({ commit }, name);
|
|
483
|
-
debug("Init");
|
|
484
489
|
await git.init(name);
|
|
485
490
|
task.stop(`App initialized in ${name}`);
|
|
486
491
|
} catch (e) {
|
|
@@ -505,21 +510,25 @@ var import_node_path6 = __toESM(require("path"));
|
|
|
505
510
|
var import_node_path5 = __toESM(require("path"));
|
|
506
511
|
var import_fs_extra6 = __toESM(require("fs-extra"));
|
|
507
512
|
async function updateFromRemote(name, source = "", destPath = ".") {
|
|
513
|
+
debug("Updating from remote");
|
|
508
514
|
import_fs_extra6.default.ensureDirSync(appPaths.temp);
|
|
509
515
|
const tmpClone = import_node_path5.default.join(appPaths.temp, name);
|
|
510
516
|
await import_fs_extra6.default.remove(tmpClone);
|
|
511
517
|
await git.clone(source, name, { cwd: appPaths.temp });
|
|
512
518
|
const fromCommit = getBasedOnInfo(destPath).commit;
|
|
513
519
|
const toCommit = await git.getLatestCommit(tmpClone);
|
|
520
|
+
debug({ fromCommit, toCommit });
|
|
514
521
|
await git.createPatch(tmpClone, fromCommit, toCommit);
|
|
515
|
-
const
|
|
516
|
-
import_fs_extra6.default.moveSync(import_node_path5.default.join(tmpClone,
|
|
522
|
+
const patchDirPath = import_node_path5.default.join(destPath, patchesDir);
|
|
523
|
+
import_fs_extra6.default.moveSync(import_node_path5.default.join(tmpClone, patchesDir), patchDirPath);
|
|
517
524
|
try {
|
|
518
|
-
await git.applyPatch(
|
|
525
|
+
await git.applyPatch(patchDirPath, destPath);
|
|
519
526
|
} catch {
|
|
520
527
|
}
|
|
521
528
|
updateBasedOnInfo({ commit: toCommit }, destPath);
|
|
522
|
-
|
|
529
|
+
if (!isDebugMode()) {
|
|
530
|
+
await import_fs_extra6.default.remove(patchDirPath);
|
|
531
|
+
}
|
|
523
532
|
await import_fs_extra6.default.remove(tmpClone);
|
|
524
533
|
}
|
|
525
534
|
|
|
@@ -564,10 +573,6 @@ var commands = [init2, add, update2, sync, conf];
|
|
|
564
573
|
// bin/run.ts
|
|
565
574
|
import_extra_typings2.program.name("blox").version(version);
|
|
566
575
|
import_extra_typings2.program.option("-d, --debug", "work in debug mode");
|
|
576
|
+
import_extra_typings2.program.option("-m, --minimal", "work in minimal mode");
|
|
567
577
|
commands.forEach((cmd) => import_extra_typings2.program.addCommand(cmd));
|
|
568
578
|
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
|
@@ -5,13 +5,20 @@
|
|
|
5
5
|
|
|
6
6
|
BLOX is started kit built to speed Medad Product development by providing prebuild blocks of code that can be added with all its provided functionalities in one cli command.
|
|
7
7
|
|
|
8
|
+
### Prerequisites
|
|
9
|
+
|
|
10
|
+
- Install [yarn](https://classic.yarnpkg.com/lang/en/docs/install/)
|
|
11
|
+
|
|
8
12
|
### Install
|
|
13
|
+
|
|
9
14
|
It can have many way to be installed, mainly as global npm package
|
|
10
15
|
|
|
11
16
|
```shell
|
|
12
|
-
|
|
17
|
+
npm install -g patch-package @naseej/blox
|
|
13
18
|
```
|
|
14
19
|
|
|
20
|
+
* make sure npm is already in you $Path to be able to use blox globally
|
|
21
|
+
|
|
15
22
|
### Usage
|
|
16
23
|
|
|
17
24
|
```sh
|
|
@@ -31,9 +38,12 @@ Commands:
|
|
|
31
38
|
Options:
|
|
32
39
|
-V, --version Show version number [boolean]
|
|
33
40
|
-h, --help Show help [boolean]
|
|
34
|
-
-d, --debug
|
|
41
|
+
-d, --debug Works in debug mode [boolean]
|
|
42
|
+
-m, --minimal Works in minimal mode [boolean]
|
|
35
43
|
```
|
|
36
44
|
|
|
45
|
+
* Use minimal mode if spinners are getting in the way of needed input for example.
|
|
46
|
+
|
|
37
47
|
### Available commands
|
|
38
48
|
|
|
39
49
|
* [init](#init)
|