@naseej/blox 0.1.5 → 0.1.7
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/dist/run.js +48 -24
- package/package.json +1 -1
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.6";
|
|
35
35
|
|
|
36
36
|
// src/services/git.ts
|
|
37
37
|
var import_node_path = __toESM(require("path"));
|
|
@@ -48,6 +48,10 @@ var import_prompts = require("@clack/prompts");
|
|
|
48
48
|
var isDebugMode = () => !!import_extra_typings2.program.opts()?.debug;
|
|
49
49
|
var isMinimalMode = () => !!import_extra_typings2.program.opts()?.minimal;
|
|
50
50
|
|
|
51
|
+
// src/shared/terminal/index.ts
|
|
52
|
+
var import_ansis = __toESM(require("ansis"));
|
|
53
|
+
var fmt = import_ansis.default;
|
|
54
|
+
|
|
51
55
|
// src/shared/logger.ts
|
|
52
56
|
var import_prompts2 = require("@clack/prompts");
|
|
53
57
|
var debug = (message) => {
|
|
@@ -60,6 +64,13 @@ var debug = (message) => {
|
|
|
60
64
|
console.log(JSON.stringify(message));
|
|
61
65
|
}
|
|
62
66
|
};
|
|
67
|
+
var logWarningSection = (title, content) => {
|
|
68
|
+
const line = fmt.yellow("=".repeat(82));
|
|
69
|
+
console.log("\n" + line);
|
|
70
|
+
console.log(fmt.bold(fmt.yellow("\u25B2 " + title)));
|
|
71
|
+
content && console.log(content);
|
|
72
|
+
console.log(line + "\n");
|
|
73
|
+
};
|
|
63
74
|
|
|
64
75
|
// src/services/shell.ts
|
|
65
76
|
var $ = async (bin, options = [], { cwd, onStdout } = {}) => {
|
|
@@ -125,10 +136,16 @@ var updateRemote = async (name, source, shellOptions = {}) => {
|
|
|
125
136
|
var update = (shellOptions = {}) => {
|
|
126
137
|
return $("git", ["pull", "--progress"], { ...defaultShellOptions, ...shellOptions });
|
|
127
138
|
};
|
|
128
|
-
var
|
|
129
|
-
|
|
139
|
+
var getLatestCommitFromRemote = async (remote) => {
|
|
140
|
+
return getLatestCommit(`${remote}/main`);
|
|
141
|
+
};
|
|
142
|
+
var getLatestCommitFromPath = async (path7) => {
|
|
143
|
+
return getLatestCommit("HEAD", path7);
|
|
144
|
+
};
|
|
145
|
+
var getLatestCommit = async (rev, cwd = ".") => {
|
|
146
|
+
debug(`Get latest commit for rev: ${rev} and cwd: ${cwd}`);
|
|
130
147
|
let commit = "";
|
|
131
|
-
await $("git", ["rev-parse",
|
|
148
|
+
await $("git", ["rev-parse", rev], {
|
|
132
149
|
cwd,
|
|
133
150
|
onStdout: (text2) => {
|
|
134
151
|
commit = text2;
|
|
@@ -136,9 +153,17 @@ var getLatestCommit = async (cwd) => {
|
|
|
136
153
|
});
|
|
137
154
|
return commit.replace(/\n/g, "");
|
|
138
155
|
};
|
|
139
|
-
var
|
|
140
|
-
|
|
141
|
-
|
|
156
|
+
var createPatch = async (fromCommit, toCommit, outputPath) => {
|
|
157
|
+
return $("git", ["diff", fromCommit, toCommit, ">", outputPath]);
|
|
158
|
+
};
|
|
159
|
+
var getChangesLog = async (fromCommit, toCommit) => {
|
|
160
|
+
let changes = "";
|
|
161
|
+
await $("git", ["log", `${fromCommit}..${toCommit}`, '--pretty=format:"%s"'], {
|
|
162
|
+
onStdout: (text2) => {
|
|
163
|
+
changes = text2;
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
return changes;
|
|
142
167
|
};
|
|
143
168
|
var applyPatch = (patch, cwd = ".") => {
|
|
144
169
|
const args = ["apply", "-3"];
|
|
@@ -165,8 +190,10 @@ var git = {
|
|
|
165
190
|
update,
|
|
166
191
|
unInit,
|
|
167
192
|
init,
|
|
168
|
-
|
|
193
|
+
getLatestCommitFromRemote,
|
|
194
|
+
getLatestCommitFromPath,
|
|
169
195
|
createPatch,
|
|
196
|
+
getChangesLog,
|
|
170
197
|
applyPatch,
|
|
171
198
|
updateRemote
|
|
172
199
|
};
|
|
@@ -376,12 +403,6 @@ function getUsedBlocks() {
|
|
|
376
403
|
|
|
377
404
|
// src/shared/prompts/index.ts
|
|
378
405
|
var import_prompts4 = require("@clack/prompts");
|
|
379
|
-
|
|
380
|
-
// src/shared/terminal/index.ts
|
|
381
|
-
var import_ansis = __toESM(require("ansis"));
|
|
382
|
-
var fmt = import_ansis.default;
|
|
383
|
-
|
|
384
|
-
// src/shared/prompts/index.ts
|
|
385
406
|
var checkIfCanceled = (value) => {
|
|
386
407
|
if ((0, import_prompts4.isCancel)(value)) {
|
|
387
408
|
(0, import_prompts4.cancel)();
|
|
@@ -435,7 +456,7 @@ var add = command("add").description("Add block to app").alias("a").argument("[b
|
|
|
435
456
|
task.start(`Fetch block`);
|
|
436
457
|
const blockPath = `blocks/${block}`;
|
|
437
458
|
await git.clone(blocks[block]?.source || "", blockPath);
|
|
438
|
-
const commit = await git.
|
|
459
|
+
const commit = await git.getLatestCommitFromPath(blockPath);
|
|
439
460
|
await git.unInit(blockPath);
|
|
440
461
|
await replacePlaceholders(blockPath, {});
|
|
441
462
|
saveBasedOnInfo({ commit }, blockPath);
|
|
@@ -499,7 +520,7 @@ var init2 = command("init").description("Init new app").alias("i").option("-n, -
|
|
|
499
520
|
const task = spinner();
|
|
500
521
|
task.start(`Fetch template`);
|
|
501
522
|
await git.clone(templates[template]?.source || "", name);
|
|
502
|
-
const commit = await git.
|
|
523
|
+
const commit = await git.getLatestCommitFromPath(name);
|
|
503
524
|
await git.unInit(name);
|
|
504
525
|
await replacePlaceholders(name, { app: { name } });
|
|
505
526
|
saveBasedOnInfo({ commit }, name);
|
|
@@ -529,16 +550,19 @@ var import_fs_extra6 = __toESM(require("fs-extra"));
|
|
|
529
550
|
async function updateFromRemote(name, source = "", destPath = ".") {
|
|
530
551
|
debug("Updating from remote");
|
|
531
552
|
import_fs_extra6.default.ensureDirSync(appPaths.temp);
|
|
532
|
-
const tmpClone = import_node_path5.default.join(appPaths.temp, name);
|
|
533
|
-
await import_fs_extra6.default.remove(tmpClone);
|
|
534
553
|
await git.updateRemote(name, source);
|
|
535
|
-
await git.clone(source, name, { cwd: appPaths.temp });
|
|
536
554
|
const fromCommit = getBasedOnInfo(destPath).commit;
|
|
537
|
-
const toCommit = await git.
|
|
555
|
+
const toCommit = await git.getLatestCommitFromRemote(name);
|
|
538
556
|
debug({ fromCommit, toCommit });
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
557
|
+
const patchFilePath = import_node_path5.default.join(destPath, "diff.patch");
|
|
558
|
+
await git.createPatch(fromCommit, toCommit, patchFilePath);
|
|
559
|
+
const changes = await git.getChangesLog(fromCommit, toCommit);
|
|
560
|
+
if (changes.trim() !== "") {
|
|
561
|
+
logWarningSection(
|
|
562
|
+
"These is the changes from last update, make sure to review for breaking changes",
|
|
563
|
+
changes
|
|
564
|
+
);
|
|
565
|
+
}
|
|
542
566
|
try {
|
|
543
567
|
await git.applyPatch(patchFilePath, destPath);
|
|
544
568
|
} catch {
|
|
@@ -547,7 +571,7 @@ async function updateFromRemote(name, source = "", destPath = ".") {
|
|
|
547
571
|
if (!isDebugMode()) {
|
|
548
572
|
await import_fs_extra6.default.unlink(patchFilePath);
|
|
549
573
|
}
|
|
550
|
-
|
|
574
|
+
debug("make sure to delete the patch file after you're done with it.");
|
|
551
575
|
}
|
|
552
576
|
|
|
553
577
|
// src/commands/update/index.ts
|