@naseej/blox 1.5.3 → 1.6.2
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 -1
- package/dist/run.js +128 -42
- package/package.json +1 -1
- package/readme.md +31 -0
package/bin/run.ts
CHANGED
|
@@ -11,7 +11,7 @@ async function main() {
|
|
|
11
11
|
cli.option('-d, --debug', 'work in debug mode');
|
|
12
12
|
cli.option('-m, --minimal', 'work in minimal mode');
|
|
13
13
|
|
|
14
|
-
await checkForCliUpdate(version);
|
|
14
|
+
await checkForCliUpdate(version, process.argv.slice(2));
|
|
15
15
|
|
|
16
16
|
commands.forEach((cmd) => cli.addCommand(cmd));
|
|
17
17
|
cli.parse();
|
package/dist/run.js
CHANGED
|
@@ -164,7 +164,21 @@ var compareVersions = (a, b) => {
|
|
|
164
164
|
}
|
|
165
165
|
return 0;
|
|
166
166
|
};
|
|
167
|
-
var
|
|
167
|
+
var _getInvokedCommand = (argv) => {
|
|
168
|
+
for (const token of argv) {
|
|
169
|
+
if (token === "--") {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
if (!token.startsWith("-")) {
|
|
173
|
+
return token;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return null;
|
|
177
|
+
};
|
|
178
|
+
var checkForCliUpdate = async (currentVersion, argv = []) => {
|
|
179
|
+
if (_getInvokedCommand(argv) === "upgrade") {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
168
182
|
const cache = readCache();
|
|
169
183
|
const now = Date.now();
|
|
170
184
|
if (now - cache.lastChecked < checkIntervalMs) {
|
|
@@ -185,7 +199,7 @@ var checkForCliUpdate = async (currentVersion) => {
|
|
|
185
199
|
};
|
|
186
200
|
|
|
187
201
|
// package.json
|
|
188
|
-
var version = "1.
|
|
202
|
+
var version = "1.6.2";
|
|
189
203
|
|
|
190
204
|
// src/commands/add/index.ts
|
|
191
205
|
var import_fs_extra10 = __toESM(require("fs-extra"));
|
|
@@ -1159,6 +1173,9 @@ var import_fs_extra9 = __toESM(require("fs-extra"));
|
|
|
1159
1173
|
var import_merge = __toESM(require("lodash/merge"));
|
|
1160
1174
|
var registriesDataPath = import_node_path12.default.join(appPaths.data, "registries");
|
|
1161
1175
|
var upeToDate = false;
|
|
1176
|
+
var cacheDirNameForRegistry = (registry) => {
|
|
1177
|
+
return encodeURIComponent(registry).replace(/%/g, "_");
|
|
1178
|
+
};
|
|
1162
1179
|
var syncRegistries = async (branch) => {
|
|
1163
1180
|
if (upeToDate) return;
|
|
1164
1181
|
upeToDate = true;
|
|
@@ -1169,7 +1186,7 @@ var syncRegistries = async (branch) => {
|
|
|
1169
1186
|
await Promise.all(
|
|
1170
1187
|
config.registries.map(async (registry) => {
|
|
1171
1188
|
debug(`update registry: ${registry}`);
|
|
1172
|
-
const repoName = registry
|
|
1189
|
+
const repoName = cacheDirNameForRegistry(registry);
|
|
1173
1190
|
const repoDir = import_node_path12.default.join(registriesDataPath, repoName);
|
|
1174
1191
|
if (!import_fs_extra9.default.existsSync(repoDir)) {
|
|
1175
1192
|
await git.clone(registry, repoName, branch, {
|
|
@@ -1629,10 +1646,11 @@ var ContributionWorkflow = class {
|
|
|
1629
1646
|
branch,
|
|
1630
1647
|
onAttemptFailed: ({ attempt, error: error2 }) => this.logger.warn("push.failed", { attempt, error: error2 })
|
|
1631
1648
|
});
|
|
1632
|
-
this.logger.
|
|
1649
|
+
this.logger.debug("branch.pushed", {
|
|
1633
1650
|
branch,
|
|
1634
1651
|
remote: repoUrl
|
|
1635
1652
|
});
|
|
1653
|
+
this.logger.info("Branch pushed successfully.");
|
|
1636
1654
|
this.pullRequest.printPushSummary({
|
|
1637
1655
|
repoUrl,
|
|
1638
1656
|
sourceBranch: branch,
|
|
@@ -1762,10 +1780,17 @@ Expected remote ${remoteHead}, local checkpoint ${checkpoint.commit}.`
|
|
|
1762
1780
|
if (!title) {
|
|
1763
1781
|
throw new Error("New contribution requires a title.");
|
|
1764
1782
|
}
|
|
1765
|
-
await
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1783
|
+
await runTask(
|
|
1784
|
+
{
|
|
1785
|
+
start: `Create new branch ${branch} from ${checkpointCommit}`,
|
|
1786
|
+
end: `Created new branch ${branch}`
|
|
1787
|
+
},
|
|
1788
|
+
async () => {
|
|
1789
|
+
await git.checkout(checkpointCommit, tmpCwd);
|
|
1790
|
+
this.logger.debug("branch.create", { branch, from: checkpointCommit });
|
|
1791
|
+
await git.createBranch(branch, checkpointCommit, tmpCwd);
|
|
1792
|
+
}
|
|
1793
|
+
);
|
|
1769
1794
|
return;
|
|
1770
1795
|
}
|
|
1771
1796
|
await git.checkout(branch, tmpCwd);
|
|
@@ -1790,7 +1815,7 @@ var import_fs_extra12 = __toESM(require("fs-extra"));
|
|
|
1790
1815
|
|
|
1791
1816
|
// src/services/contribute/config/index.ts
|
|
1792
1817
|
var tempRepoName = "tmp";
|
|
1793
|
-
var bloxConfigControlledKeys = ["checkpoints"];
|
|
1818
|
+
var bloxConfigControlledKeys = ["checkpoints", "project"];
|
|
1794
1819
|
|
|
1795
1820
|
// src/services/contribute/utils/getExcludedPrefixesForTarget.ts
|
|
1796
1821
|
var import_node_path14 = __toESM(require("path"));
|
|
@@ -1834,22 +1859,35 @@ var CommitApplierService = class {
|
|
|
1834
1859
|
this.logger = logger;
|
|
1835
1860
|
}
|
|
1836
1861
|
async applyCommits(opts) {
|
|
1862
|
+
const prepareSpinner = spinner();
|
|
1863
|
+
prepareSpinner.start("Prepare for apply commits");
|
|
1837
1864
|
const subtreePath = getPathPrefixToStrip(opts.target).replace(/\/$/, "");
|
|
1838
1865
|
const exclusion = getExcludedPrefixesForTarget(opts.target, opts.appRepoCwd);
|
|
1866
|
+
const projectIgnore = getBloxFile(opts.appRepoCwd).project?.ignore || [];
|
|
1867
|
+
const projectIgnoreMatcher = createGitignoreMatcher(projectIgnore);
|
|
1839
1868
|
this.logger.debug("Prepare for apply commits", {
|
|
1840
1869
|
appRepo: opts.appRepoCwd,
|
|
1841
1870
|
tmpRepo: opts.tmpRepoCwd,
|
|
1842
1871
|
subtree: subtreePath || "(root)",
|
|
1843
|
-
exclusion
|
|
1872
|
+
exclusion,
|
|
1873
|
+
projectIgnore
|
|
1844
1874
|
});
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1875
|
+
prepareSpinner.stop("Prepared apply commits");
|
|
1876
|
+
const orderedCommits = [...opts.commits].reverse();
|
|
1877
|
+
for (const commit2 of orderedCommits) {
|
|
1878
|
+
await this.applySingleCommit(
|
|
1879
|
+
opts,
|
|
1880
|
+
subtreePath,
|
|
1881
|
+
exclusion,
|
|
1882
|
+
projectIgnoreMatcher,
|
|
1883
|
+
commit2
|
|
1884
|
+
);
|
|
1848
1885
|
}
|
|
1849
1886
|
}
|
|
1850
|
-
async applySingleCommit(opts, subtreePath, exclusion, commit2) {
|
|
1887
|
+
async applySingleCommit(opts, subtreePath, exclusion, projectIgnoreMatcher, commit2) {
|
|
1851
1888
|
this.logger.debug("apply.commit.start", { commit: commit2.slice(0, 7) });
|
|
1852
|
-
|
|
1889
|
+
const commitSpinner = spinner();
|
|
1890
|
+
commitSpinner.start(`Apply commit ${commit2.slice(0, 7)} start`);
|
|
1853
1891
|
try {
|
|
1854
1892
|
await git.fetchCommit(opts.appRepoCwd, commit2, opts.tmpRepoCwd);
|
|
1855
1893
|
try {
|
|
@@ -1860,7 +1898,13 @@ var CommitApplierService = class {
|
|
|
1860
1898
|
message: e instanceof Error ? e.message : String(e)
|
|
1861
1899
|
});
|
|
1862
1900
|
}
|
|
1863
|
-
await this.revertExcludedStagedFiles(
|
|
1901
|
+
await this.revertExcludedStagedFiles(
|
|
1902
|
+
opts.tmpRepoCwd,
|
|
1903
|
+
commit2,
|
|
1904
|
+
exclusion,
|
|
1905
|
+
projectIgnoreMatcher,
|
|
1906
|
+
opts.target
|
|
1907
|
+
);
|
|
1864
1908
|
const remainingConflicts = await git.getUnmergedFiles(opts.tmpRepoCwd);
|
|
1865
1909
|
if (remainingConflicts.length) {
|
|
1866
1910
|
this.logger.error("apply.commit.conflicts", {
|
|
@@ -1869,8 +1913,16 @@ var CommitApplierService = class {
|
|
|
1869
1913
|
});
|
|
1870
1914
|
await this.waitUntilUserResolvesConflicts(opts.tmpRepoCwd, commit2);
|
|
1871
1915
|
}
|
|
1872
|
-
await this.commitStagedIfAny(opts, commit2);
|
|
1916
|
+
const committed = await this.commitStagedIfAny(opts, commit2);
|
|
1917
|
+
if (committed) {
|
|
1918
|
+
commitSpinner.stop("Apply commit success");
|
|
1919
|
+
} else {
|
|
1920
|
+
commitSpinner.stop(
|
|
1921
|
+
`Apply commit (${commit2}) skipped: no changes left for this target after filtering.`
|
|
1922
|
+
);
|
|
1923
|
+
}
|
|
1873
1924
|
} catch (e) {
|
|
1925
|
+
commitSpinner.stop(`Failed to apply commit ${commit2.slice(0, 7)}`, 1);
|
|
1874
1926
|
const msg = `Failed to apply commit ${commit2.slice(0, 7)}.
|
|
1875
1927
|
Resolve manually in the temp repo:
|
|
1876
1928
|
cd ${opts.tmpRepoCwd}
|
|
@@ -1880,15 +1932,21 @@ Resolve manually in the temp repo:
|
|
|
1880
1932
|
${e instanceof Error ? e.message : String(e)}`);
|
|
1881
1933
|
}
|
|
1882
1934
|
}
|
|
1883
|
-
async revertExcludedStagedFiles(tmpRepoCwd, commit2, exclusion, target) {
|
|
1935
|
+
async revertExcludedStagedFiles(tmpRepoCwd, commit2, exclusion, projectIgnoreMatcher, target) {
|
|
1884
1936
|
const stagedFiles = await git.getStagedFiles(tmpRepoCwd);
|
|
1885
1937
|
const unmergedFiles = await git.getUnmergedFiles(tmpRepoCwd);
|
|
1886
1938
|
const allTouchedFiles = [.../* @__PURE__ */ new Set([...stagedFiles, ...unmergedFiles])];
|
|
1887
1939
|
for (const file of allTouchedFiles) {
|
|
1888
1940
|
const isBloxFile = isBloxConfigFile(file);
|
|
1889
1941
|
const isExcludedByTarget = shouldExcludeFile(file, exclusion);
|
|
1942
|
+
const isExcludedByProjectIgnore = projectIgnoreMatcher.ignores(toIgnorePath(file));
|
|
1890
1943
|
if (isExcludedByTarget) {
|
|
1891
|
-
this.logger.
|
|
1944
|
+
this.logger.debug("apply.commit.skip_file", { file });
|
|
1945
|
+
await git.revertPathToHead(file, tmpRepoCwd);
|
|
1946
|
+
continue;
|
|
1947
|
+
}
|
|
1948
|
+
if (isExcludedByProjectIgnore) {
|
|
1949
|
+
this.logger.debug("apply.commit.skip_file_project_ignore", { file });
|
|
1892
1950
|
await git.revertPathToHead(file, tmpRepoCwd);
|
|
1893
1951
|
continue;
|
|
1894
1952
|
}
|
|
@@ -1985,16 +2043,13 @@ ${opts.description}`;
|
|
|
1985
2043
|
}
|
|
1986
2044
|
await git.commitAll(commitMsg, opts.tmpRepoCwd);
|
|
1987
2045
|
this.logger.debug("apply.commit.success", { commit: commit2.slice(0, 7) });
|
|
1988
|
-
|
|
1989
|
-
return;
|
|
2046
|
+
return true;
|
|
1990
2047
|
}
|
|
1991
2048
|
this.logger.debug("apply.commit.skip_empty", {
|
|
1992
2049
|
commit: commit2.slice(0, 7),
|
|
1993
2050
|
message: "No changes left for this target after filtering."
|
|
1994
2051
|
});
|
|
1995
|
-
|
|
1996
|
-
"Apply commit skip empty : No changes left for this target after filtering."
|
|
1997
|
-
);
|
|
2052
|
+
return false;
|
|
1998
2053
|
}
|
|
1999
2054
|
};
|
|
2000
2055
|
|
|
@@ -2021,7 +2076,7 @@ var CommitSelectorService = class {
|
|
|
2021
2076
|
value: c.hash,
|
|
2022
2077
|
label: `${c.hash.slice(0, 7)} ${c.subject}`
|
|
2023
2078
|
})),
|
|
2024
|
-
required:
|
|
2079
|
+
required: true
|
|
2025
2080
|
});
|
|
2026
2081
|
for (const h of value) {
|
|
2027
2082
|
if (!selected.includes(h)) {
|
|
@@ -2140,7 +2195,10 @@ var ContributionTargetSelector = class {
|
|
|
2140
2195
|
if (!filtered.length) {
|
|
2141
2196
|
this.logger.warn(`No matches for search: "${query}"`);
|
|
2142
2197
|
const again = await confirm({ message: "Search again?" });
|
|
2143
|
-
if (again)
|
|
2198
|
+
if (again) {
|
|
2199
|
+
query = " ";
|
|
2200
|
+
continue;
|
|
2201
|
+
}
|
|
2144
2202
|
throw new Error("Aborted: no target selected.");
|
|
2145
2203
|
}
|
|
2146
2204
|
const pageSize = UI_PAGE_SIZE;
|
|
@@ -2164,6 +2222,7 @@ var ContributionTargetSelector = class {
|
|
|
2164
2222
|
continue;
|
|
2165
2223
|
}
|
|
2166
2224
|
if (value === TARGET_SELECT_PAGE.SEARCH_AGAIN) {
|
|
2225
|
+
query = " ";
|
|
2167
2226
|
break;
|
|
2168
2227
|
}
|
|
2169
2228
|
const [typeRaw, name, templateNameRaw] = value.split(":");
|
|
@@ -2344,7 +2403,6 @@ ${fmt.cyan("\u25E2")}${line}${fmt.cyan("\u25E3")}
|
|
|
2344
2403
|
this.logger.info("pr.skipped", { reason: "remote_not_azure_devops_git" });
|
|
2345
2404
|
return { prUrl: void 0 };
|
|
2346
2405
|
}
|
|
2347
|
-
this.logger.info("pr.prompt.shown");
|
|
2348
2406
|
const wantsPr = await confirm({
|
|
2349
2407
|
message: "Do you want to open a Pull Request?",
|
|
2350
2408
|
initialValue: true
|
|
@@ -2377,25 +2435,52 @@ var TmpRepoService = class {
|
|
|
2377
2435
|
constructor(logger) {
|
|
2378
2436
|
this.logger = logger;
|
|
2379
2437
|
}
|
|
2438
|
+
async refreshExistingTmpRepo(dir, branch) {
|
|
2439
|
+
await git.fetchRepo(dir);
|
|
2440
|
+
try {
|
|
2441
|
+
await git.checkout(branch, dir);
|
|
2442
|
+
} catch {
|
|
2443
|
+
await git.createBranch(branch, `origin/${branch}`, dir);
|
|
2444
|
+
}
|
|
2445
|
+
await git.reset(void 0, true, dir);
|
|
2446
|
+
await git.update({ cwd: dir });
|
|
2447
|
+
}
|
|
2380
2448
|
async getTmpDir(target) {
|
|
2381
2449
|
const slug = `${target.type}-${target.name}`.replace(/[^a-zA-Z0-9._-]+/g, "-");
|
|
2382
2450
|
return import_node_path17.default.join((0, import_node_os2.homedir)(), bloxFilePath, tempRepoName, slug);
|
|
2383
2451
|
}
|
|
2384
2452
|
async prepare(opts) {
|
|
2385
|
-
const
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
await import_fs_extra14.default.
|
|
2453
|
+
const taskSpinner = spinner();
|
|
2454
|
+
taskSpinner.start("Prepare for tmp repo");
|
|
2455
|
+
try {
|
|
2456
|
+
const dir = await this.getTmpDir(opts.target);
|
|
2457
|
+
this.logger.debug(`${tempRepoName}.prepare`, {
|
|
2458
|
+
dir,
|
|
2459
|
+
repoUrl: opts.repoUrl,
|
|
2460
|
+
branch: opts.branch
|
|
2461
|
+
});
|
|
2462
|
+
if (await import_fs_extra14.default.pathExists(dir)) {
|
|
2463
|
+
this.logger.debug(`${tempRepoName} reuse_tmp_local_repo`, { dir });
|
|
2464
|
+
try {
|
|
2465
|
+
await this.refreshExistingTmpRepo(dir, opts.branch);
|
|
2466
|
+
taskSpinner.stop("Prepared tmp repo");
|
|
2467
|
+
return dir;
|
|
2468
|
+
} catch (e) {
|
|
2469
|
+
this.logger.debug(`${tempRepoName} reuse_tmp_local_repo_failed_reclone`, {
|
|
2470
|
+
dir,
|
|
2471
|
+
message: e instanceof Error ? e.message : String(e)
|
|
2472
|
+
});
|
|
2473
|
+
await import_fs_extra14.default.remove(dir);
|
|
2474
|
+
}
|
|
2475
|
+
}
|
|
2476
|
+
await import_fs_extra14.default.ensureDir(import_node_path17.default.dirname(dir));
|
|
2477
|
+
await git.clone(opts.repoUrl, dir, opts.branch);
|
|
2478
|
+
taskSpinner.stop("Prepared tmp repo");
|
|
2479
|
+
return dir;
|
|
2480
|
+
} catch (e) {
|
|
2481
|
+
taskSpinner.stop("Failed: Prepare for tmp repo", 1);
|
|
2482
|
+
throw e;
|
|
2395
2483
|
}
|
|
2396
|
-
await import_fs_extra14.default.ensureDir(import_node_path17.default.dirname(dir));
|
|
2397
|
-
await git.clone(opts.repoUrl, dir, opts.branch);
|
|
2398
|
-
return dir;
|
|
2399
2484
|
}
|
|
2400
2485
|
};
|
|
2401
2486
|
|
|
@@ -2870,7 +2955,8 @@ async function updateFromRemote({
|
|
|
2870
2955
|
}
|
|
2871
2956
|
}
|
|
2872
2957
|
const remoteIgnore = remoteBloxFile.definition?.ignore || [];
|
|
2873
|
-
|
|
2958
|
+
const projectIgnore = bloxFile.project?.ignore || [];
|
|
2959
|
+
ignore3.push(...remoteIgnore, ...projectIgnore, bloxFilePath, `**/${bloxFilePath}`);
|
|
2874
2960
|
const gitIgnorePath = import_node_path21.default.join(dir, ".gitignore");
|
|
2875
2961
|
if (await import_fs_extra19.default.pathExists(gitIgnorePath)) {
|
|
2876
2962
|
const gitIgnoreContent = await import_fs_extra19.default.readFile(gitIgnorePath, "utf8");
|
|
@@ -3266,7 +3352,7 @@ async function main() {
|
|
|
3266
3352
|
import_extra_typings2.program.name("blox").version(version);
|
|
3267
3353
|
import_extra_typings2.program.option("-d, --debug", "work in debug mode");
|
|
3268
3354
|
import_extra_typings2.program.option("-m, --minimal", "work in minimal mode");
|
|
3269
|
-
await checkForCliUpdate(version);
|
|
3355
|
+
await checkForCliUpdate(version, process.argv.slice(2));
|
|
3270
3356
|
commands.forEach((cmd) => import_extra_typings2.program.addCommand(cmd));
|
|
3271
3357
|
import_extra_typings2.program.parse();
|
|
3272
3358
|
}
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -56,6 +56,37 @@ Options:
|
|
|
56
56
|
- [migrate](#migrate)
|
|
57
57
|
- [skills](#installing-blox-cli-skills)
|
|
58
58
|
|
|
59
|
+
## Ignore policy
|
|
60
|
+
|
|
61
|
+
Ignore rules tell BLOX which files or paths to skip.
|
|
62
|
+
|
|
63
|
+
Add project-level ignore rules in your root `.blox` file:
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
{
|
|
67
|
+
"project": {
|
|
68
|
+
"ignore": ["applet-core", "dist/**", "*.generated.ts"]
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
How it works in a simple way:
|
|
74
|
+
|
|
75
|
+
Quick difference:
|
|
76
|
+
|
|
77
|
+
- `definition.ignore`: comes from the remote template/block (maintainer controls it).
|
|
78
|
+
- `project.ignore`: local to your app (you control it).
|
|
79
|
+
|
|
80
|
+
- `blox update` combines ignore patterns from multiple places:
|
|
81
|
+
|
|
82
|
+
- remote template ignore (`definition.ignore`)
|
|
83
|
+
- local project ignore (`project.ignore` in your local `.blox`)
|
|
84
|
+
- local `.gitignore`
|
|
85
|
+
- command option `--ignore` (when provided)
|
|
86
|
+
|
|
87
|
+
- `blox contribute` also respects local `project.ignore`, so matching files are not included in contributed commits.
|
|
88
|
+
- Local `project.ignore` is project-owned and is not replaced by remote template ignore during update.
|
|
89
|
+
|
|
59
90
|
## Lifecycle hooks
|
|
60
91
|
|
|
61
92
|
Lifecycle hooks are **optional shell commands** defined in `.blox` files.
|