@naseej/blox 0.1.4 → 0.1.6
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 +43 -23
- 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"));
|
|
@@ -106,13 +106,35 @@ var clone = (repoUrl, options, shellOptions = {}) => {
|
|
|
106
106
|
...shellOptions
|
|
107
107
|
});
|
|
108
108
|
};
|
|
109
|
+
var updateRemote = async (name, source, shellOptions = {}) => {
|
|
110
|
+
debug("updateRemote");
|
|
111
|
+
debug({ name, source });
|
|
112
|
+
try {
|
|
113
|
+
await $("git", ["remote", "add", name, source], {
|
|
114
|
+
...defaultShellOptions,
|
|
115
|
+
...shellOptions
|
|
116
|
+
});
|
|
117
|
+
} catch {
|
|
118
|
+
}
|
|
119
|
+
await $("git", ["remote", "set-url", name, source], {
|
|
120
|
+
...defaultShellOptions,
|
|
121
|
+
...shellOptions
|
|
122
|
+
});
|
|
123
|
+
await $("git", ["fetch", name], { ...defaultShellOptions, ...shellOptions });
|
|
124
|
+
};
|
|
109
125
|
var update = (shellOptions = {}) => {
|
|
110
126
|
return $("git", ["pull", "--progress"], { ...defaultShellOptions, ...shellOptions });
|
|
111
127
|
};
|
|
112
|
-
var
|
|
113
|
-
|
|
128
|
+
var getLatestCommitFromRemote = async (remote) => {
|
|
129
|
+
return getLatestCommit(`${remote}/main`);
|
|
130
|
+
};
|
|
131
|
+
var getLatestCommitFromPath = async (path7) => {
|
|
132
|
+
return getLatestCommit("HEAD", path7);
|
|
133
|
+
};
|
|
134
|
+
var getLatestCommit = async (rev, cwd = ".") => {
|
|
135
|
+
debug(`Get latest commit for rev: ${rev} and cwd: ${cwd}`);
|
|
114
136
|
let commit = "";
|
|
115
|
-
await $("git", ["rev-parse",
|
|
137
|
+
await $("git", ["rev-parse", rev], {
|
|
116
138
|
cwd,
|
|
117
139
|
onStdout: (text2) => {
|
|
118
140
|
commit = text2;
|
|
@@ -120,17 +142,16 @@ var getLatestCommit = async (cwd) => {
|
|
|
120
142
|
});
|
|
121
143
|
return commit.replace(/\n/g, "");
|
|
122
144
|
};
|
|
123
|
-
var
|
|
124
|
-
|
|
125
|
-
return $("git", ["format-patch", "-o", patchesDir, `${fromCommit}..${toCommit}`], { cwd });
|
|
145
|
+
var createPatch = async (fromCommit, toCommit, outputPath) => {
|
|
146
|
+
return $("git", ["diff", fromCommit, toCommit, ">", outputPath]);
|
|
126
147
|
};
|
|
127
|
-
var applyPatch = (
|
|
148
|
+
var applyPatch = (patch, cwd = ".") => {
|
|
128
149
|
const args = ["apply", "-3"];
|
|
129
150
|
if (cwd != ".") {
|
|
130
151
|
args.push("--directory");
|
|
131
152
|
args.push(cwd);
|
|
132
153
|
}
|
|
133
|
-
args.push(
|
|
154
|
+
args.push(patch);
|
|
134
155
|
return $("git", args);
|
|
135
156
|
};
|
|
136
157
|
var unInit = (cwd) => {
|
|
@@ -149,9 +170,11 @@ var git = {
|
|
|
149
170
|
update,
|
|
150
171
|
unInit,
|
|
151
172
|
init,
|
|
152
|
-
|
|
173
|
+
getLatestCommitFromRemote,
|
|
174
|
+
getLatestCommitFromPath,
|
|
153
175
|
createPatch,
|
|
154
|
-
applyPatch
|
|
176
|
+
applyPatch,
|
|
177
|
+
updateRemote
|
|
155
178
|
};
|
|
156
179
|
|
|
157
180
|
// src/services/registry.ts
|
|
@@ -418,7 +441,7 @@ var add = command("add").description("Add block to app").alias("a").argument("[b
|
|
|
418
441
|
task.start(`Fetch block`);
|
|
419
442
|
const blockPath = `blocks/${block}`;
|
|
420
443
|
await git.clone(blocks[block]?.source || "", blockPath);
|
|
421
|
-
const commit = await git.
|
|
444
|
+
const commit = await git.getLatestCommitFromPath(blockPath);
|
|
422
445
|
await git.unInit(blockPath);
|
|
423
446
|
await replacePlaceholders(blockPath, {});
|
|
424
447
|
saveBasedOnInfo({ commit }, blockPath);
|
|
@@ -482,7 +505,7 @@ var init2 = command("init").description("Init new app").alias("i").option("-n, -
|
|
|
482
505
|
const task = spinner();
|
|
483
506
|
task.start(`Fetch template`);
|
|
484
507
|
await git.clone(templates[template]?.source || "", name);
|
|
485
|
-
const commit = await git.
|
|
508
|
+
const commit = await git.getLatestCommitFromPath(name);
|
|
486
509
|
await git.unInit(name);
|
|
487
510
|
await replacePlaceholders(name, { app: { name } });
|
|
488
511
|
saveBasedOnInfo({ commit }, name);
|
|
@@ -512,24 +535,21 @@ var import_fs_extra6 = __toESM(require("fs-extra"));
|
|
|
512
535
|
async function updateFromRemote(name, source = "", destPath = ".") {
|
|
513
536
|
debug("Updating from remote");
|
|
514
537
|
import_fs_extra6.default.ensureDirSync(appPaths.temp);
|
|
515
|
-
|
|
516
|
-
await import_fs_extra6.default.remove(tmpClone);
|
|
517
|
-
await git.clone(source, name, { cwd: appPaths.temp });
|
|
538
|
+
await git.updateRemote(name, source);
|
|
518
539
|
const fromCommit = getBasedOnInfo(destPath).commit;
|
|
519
|
-
const toCommit = await git.
|
|
540
|
+
const toCommit = await git.getLatestCommitFromRemote(name);
|
|
520
541
|
debug({ fromCommit, toCommit });
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
import_fs_extra6.default.moveSync(import_node_path5.default.join(tmpClone, patchesDir), patchDirPath);
|
|
542
|
+
const patchFilePath = import_node_path5.default.join(destPath, "diff.patch");
|
|
543
|
+
await git.createPatch(fromCommit, toCommit, patchFilePath);
|
|
524
544
|
try {
|
|
525
|
-
await git.applyPatch(
|
|
545
|
+
await git.applyPatch(patchFilePath, destPath);
|
|
526
546
|
} catch {
|
|
527
547
|
}
|
|
528
548
|
updateBasedOnInfo({ commit: toCommit }, destPath);
|
|
529
549
|
if (!isDebugMode()) {
|
|
530
|
-
await import_fs_extra6.default.
|
|
550
|
+
await import_fs_extra6.default.unlink(patchFilePath);
|
|
531
551
|
}
|
|
532
|
-
|
|
552
|
+
debug("make sure to delete the patch file after you're done with it.");
|
|
533
553
|
}
|
|
534
554
|
|
|
535
555
|
// src/commands/update/index.ts
|