@naseej/blox 0.1.5 → 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.
Files changed (2) hide show
  1. package/dist/run.js +20 -18
  2. 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.5";
34
+ var version = "0.1.6";
35
35
 
36
36
  // src/services/git.ts
37
37
  var import_node_path = __toESM(require("path"));
@@ -125,10 +125,16 @@ var updateRemote = async (name, source, shellOptions = {}) => {
125
125
  var update = (shellOptions = {}) => {
126
126
  return $("git", ["pull", "--progress"], { ...defaultShellOptions, ...shellOptions });
127
127
  };
128
- var getLatestCommit = async (cwd) => {
129
- debug("Get latest commit");
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}`);
130
136
  let commit = "";
131
- await $("git", ["rev-parse", "HEAD"], {
137
+ await $("git", ["rev-parse", rev], {
132
138
  cwd,
133
139
  onStdout: (text2) => {
134
140
  commit = text2;
@@ -136,9 +142,8 @@ var getLatestCommit = async (cwd) => {
136
142
  });
137
143
  return commit.replace(/\n/g, "");
138
144
  };
139
- var patchFileName = "diff.patch";
140
- var createPatch = async (cwd, fromCommit, toCommit) => {
141
- return $("git", ["diff", fromCommit, toCommit, ">", patchFileName], { cwd });
145
+ var createPatch = async (fromCommit, toCommit, outputPath) => {
146
+ return $("git", ["diff", fromCommit, toCommit, ">", outputPath]);
142
147
  };
143
148
  var applyPatch = (patch, cwd = ".") => {
144
149
  const args = ["apply", "-3"];
@@ -165,7 +170,8 @@ var git = {
165
170
  update,
166
171
  unInit,
167
172
  init,
168
- getLatestCommit,
173
+ getLatestCommitFromRemote,
174
+ getLatestCommitFromPath,
169
175
  createPatch,
170
176
  applyPatch,
171
177
  updateRemote
@@ -435,7 +441,7 @@ var add = command("add").description("Add block to app").alias("a").argument("[b
435
441
  task.start(`Fetch block`);
436
442
  const blockPath = `blocks/${block}`;
437
443
  await git.clone(blocks[block]?.source || "", blockPath);
438
- const commit = await git.getLatestCommit(blockPath);
444
+ const commit = await git.getLatestCommitFromPath(blockPath);
439
445
  await git.unInit(blockPath);
440
446
  await replacePlaceholders(blockPath, {});
441
447
  saveBasedOnInfo({ commit }, blockPath);
@@ -499,7 +505,7 @@ var init2 = command("init").description("Init new app").alias("i").option("-n, -
499
505
  const task = spinner();
500
506
  task.start(`Fetch template`);
501
507
  await git.clone(templates[template]?.source || "", name);
502
- const commit = await git.getLatestCommit(name);
508
+ const commit = await git.getLatestCommitFromPath(name);
503
509
  await git.unInit(name);
504
510
  await replacePlaceholders(name, { app: { name } });
505
511
  saveBasedOnInfo({ commit }, name);
@@ -529,16 +535,12 @@ var import_fs_extra6 = __toESM(require("fs-extra"));
529
535
  async function updateFromRemote(name, source = "", destPath = ".") {
530
536
  debug("Updating from remote");
531
537
  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
538
  await git.updateRemote(name, source);
535
- await git.clone(source, name, { cwd: appPaths.temp });
536
539
  const fromCommit = getBasedOnInfo(destPath).commit;
537
- const toCommit = await git.getLatestCommit(tmpClone);
540
+ const toCommit = await git.getLatestCommitFromRemote(name);
538
541
  debug({ fromCommit, toCommit });
539
- await git.createPatch(tmpClone, fromCommit, toCommit);
540
- const patchFilePath = import_node_path5.default.join(destPath, patchFileName);
541
- import_fs_extra6.default.moveSync(import_node_path5.default.join(tmpClone, patchFileName), patchFilePath);
542
+ const patchFilePath = import_node_path5.default.join(destPath, "diff.patch");
543
+ await git.createPatch(fromCommit, toCommit, patchFilePath);
542
544
  try {
543
545
  await git.applyPatch(patchFilePath, destPath);
544
546
  } catch {
@@ -547,7 +549,7 @@ async function updateFromRemote(name, source = "", destPath = ".") {
547
549
  if (!isDebugMode()) {
548
550
  await import_fs_extra6.default.unlink(patchFilePath);
549
551
  }
550
- await import_fs_extra6.default.remove(tmpClone);
552
+ debug("make sure to delete the patch file after you're done with it.");
551
553
  }
552
554
 
553
555
  // src/commands/update/index.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naseej/blox",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "blox cli",
5
5
  "bin": {
6
6
  "blox": "./bin/run"