@zokugun/artifact 0.5.1 → 0.6.0
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/artifact +1 -1
- package/lib/cli.d.ts +1 -0
- package/lib/cli.js +12 -4
- package/lib/commands/add.d.ts +6 -0
- package/lib/commands/add.js +47 -36
- package/lib/commands/index.d.ts +4 -0
- package/lib/commands/index.js +9 -7
- package/lib/commands/list.d.ts +1 -0
- package/lib/commands/list.js +13 -8
- package/lib/commands/remove.d.ts +6 -0
- package/lib/commands/remove.js +79 -0
- package/lib/commands/update.d.ts +5 -0
- package/lib/commands/update.js +43 -39
- package/lib/compositors/compose.d.ts +7 -0
- package/lib/compositors/compose.js +13 -13
- package/lib/compositors/fork.d.ts +3 -0
- package/lib/compositors/fork.js +4 -4
- package/lib/compositors/index.d.ts +6 -0
- package/lib/compositors/index.js +12 -12
- package/lib/compositors/json.d.ts +2 -0
- package/lib/compositors/json.js +14 -12
- package/lib/compositors/map-sort.d.ts +2 -0
- package/lib/compositors/map-sort.js +2 -2
- package/lib/compositors/rc.d.ts +2 -0
- package/lib/compositors/rc.js +13 -10
- package/lib/compositors/yaml.d.ts +2 -0
- package/lib/compositors/yaml.js +8 -11
- package/lib/configs/index.d.ts +3 -0
- package/lib/configs/index.js +3 -2
- package/lib/configs/install/index.d.ts +3 -0
- package/lib/configs/install/index.js +6 -6
- package/lib/configs/install/read-install-config.d.ts +6 -0
- package/lib/configs/install/read-install-config.js +123 -80
- package/lib/configs/install/update-install-config.d.ts +2 -0
- package/lib/configs/install/write-install-config.d.ts +5 -0
- package/lib/configs/install/write-install-config.js +17 -9
- package/lib/configs/package/index.d.ts +1 -0
- package/lib/configs/package/index.js +2 -2
- package/lib/configs/package/read-package-config.d.ts +3 -0
- package/lib/configs/package/read-package-config.js +159 -40
- package/lib/configs/uninstall/index.d.ts +1 -0
- package/lib/configs/uninstall/index.js +5 -0
- package/lib/configs/uninstall/update-uninstall-config.d.ts +2 -0
- package/lib/configs/uninstall/update-uninstall-config.js +6 -0
- package/lib/configs/utils/constants.d.ts +11 -0
- package/lib/configs/utils/constants.js +24 -0
- package/lib/configs/utils/is-transform.d.ts +2 -0
- package/lib/configs/utils/is-transform.js +16 -0
- package/lib/configs/utils/merge-upsert-property.d.ts +3 -0
- package/lib/configs/utils/merge-upsert-property.js +68 -0
- package/lib/configs/utils/normalize-file-always.d.ts +3 -0
- package/lib/configs/utils/normalize-file-always.js +28 -0
- package/lib/configs/utils/normalize-file-uninstall.d.ts +3 -0
- package/lib/configs/utils/normalize-file-uninstall.js +31 -0
- package/lib/configs/utils/normalize-file-upsert.d.ts +3 -0
- package/lib/configs/utils/normalize-file-upsert.js +54 -0
- package/lib/journeys/commitlint/index.d.ts +2 -0
- package/lib/journeys/commitlint/index.js +15 -15
- package/lib/journeys/config.ts/index.d.ts +2 -0
- package/lib/journeys/config.ts/index.js +5 -5
- package/lib/journeys/default/index.d.ts +2 -0
- package/lib/journeys/default/index.js +11 -14
- package/lib/journeys/fixpack/index.d.ts +2 -0
- package/lib/journeys/fixpack/index.js +13 -13
- package/lib/journeys/gitignore/index.d.ts +2 -0
- package/lib/journeys/gitignore/index.js +5 -5
- package/lib/journeys/ignore/index.d.ts +2 -0
- package/lib/journeys/ignore/index.js +5 -5
- package/lib/journeys/index.d.ts +2 -0
- package/lib/journeys/index.js +20 -20
- package/lib/journeys/npmignore/index.d.ts +2 -0
- package/lib/journeys/npmignore/index.js +5 -5
- package/lib/journeys/package/index.d.ts +2 -0
- package/lib/journeys/package/index.js +27 -30
- package/lib/journeys/rc/index.d.ts +2 -0
- package/lib/journeys/rc/index.js +12 -12
- package/lib/journeys/tsconfig/index.d.ts +2 -0
- package/lib/journeys/tsconfig/index.js +13 -16
- package/lib/parsers/json.d.ts +2 -0
- package/lib/parsers/jsonc/index.d.ts +2 -0
- package/lib/parsers/jsonc/index.js +4 -4
- package/lib/parsers/jsonc/parse.d.ts +5 -0
- package/lib/parsers/jsonc/parse.js +1 -13
- package/lib/parsers/jsonc/stringify.d.ts +2 -0
- package/lib/parsers/jsonc/stringify.js +2 -2
- package/lib/parsers/jsonc/transform.d.ts +10 -0
- package/lib/parsers/yaml.d.ts +2 -0
- package/lib/routes/command.d.ts +4 -0
- package/lib/routes/command.js +10 -10
- package/lib/routes/index.d.ts +8 -0
- package/lib/routes/index.js +17 -15
- package/lib/routes/lines-concat.d.ts +4 -0
- package/lib/routes/lines-concat.js +7 -7
- package/lib/routes/list-concat.d.ts +4 -0
- package/lib/routes/list-concat.js +3 -7
- package/lib/routes/list-sort-concat.d.ts +4 -0
- package/lib/routes/list-sort-concat.js +1 -1
- package/lib/routes/map-concat.d.ts +4 -0
- package/lib/routes/map-concat.js +1 -1
- package/lib/routes/map-delete.d.ts +4 -0
- package/lib/routes/map-delete.js +32 -0
- package/lib/routes/overwrite.d.ts +4 -0
- package/lib/routes/overwrite.js +2 -2
- package/lib/routes/primitive.d.ts +4 -0
- package/lib/routes/primitive.js +3 -3
- package/lib/steps/apply-formatting.d.ts +8 -0
- package/lib/steps/apply-formatting.js +19 -15
- package/lib/steps/configure-branches.d.ts +3 -0
- package/lib/steps/configure-branches.js +8 -5
- package/lib/steps/configure-install-file-actions.d.ts +3 -0
- package/lib/steps/configure-install-file-actions.js +41 -86
- package/lib/steps/configure-uninstall-file-actions.d.ts +3 -0
- package/lib/steps/configure-uninstall-file-actions.js +53 -0
- package/lib/steps/configure-update-file-actions.d.ts +3 -0
- package/lib/steps/configure-update-file-actions.js +64 -97
- package/lib/steps/copy-binary-files.d.ts +3 -0
- package/lib/steps/copy-binary-files.js +24 -11
- package/lib/steps/execute-first-block.d.ts +3 -0
- package/lib/steps/execute-first-block.js +35 -14
- package/lib/steps/execute-next-block.d.ts +3 -0
- package/lib/steps/execute-next-block.js +8 -3
- package/lib/steps/index.d.ts +54 -0
- package/lib/steps/index.js +76 -54
- package/lib/steps/insert-final-new-line.d.ts +6 -0
- package/lib/steps/insert-final-new-line.js +13 -1
- package/lib/steps/merge-text-files.d.ts +3 -0
- package/lib/steps/merge-text-files.js +41 -27
- package/lib/steps/read-editor-config.d.ts +3 -0
- package/lib/steps/read-editor-config.js +21 -26
- package/lib/steps/read-files.d.ts +3 -0
- package/lib/steps/read-files.js +19 -8
- package/lib/steps/read-incoming-config.d.ts +3 -0
- package/lib/steps/read-incoming-config.js +7 -5
- package/lib/steps/read-incoming-package.d.ts +3 -0
- package/lib/steps/read-incoming-package.js +12 -7
- package/lib/steps/remove-files.d.ts +3 -0
- package/lib/steps/remove-files.js +10 -4
- package/lib/steps/rename-files.d.ts +3 -0
- package/lib/steps/rename-files.js +25 -0
- package/lib/steps/replace-templates.d.ts +3 -0
- package/lib/steps/replace-templates.js +19 -5
- package/lib/steps/transform-untouched-files.d.ts +3 -0
- package/lib/steps/transform-untouched-files.js +73 -0
- package/lib/steps/unmerge-text-files.d.ts +3 -0
- package/lib/steps/unmerge-text-files.js +63 -0
- package/lib/steps/validate-newer-package.d.ts +3 -0
- package/lib/steps/validate-newer-package.js +4 -2
- package/lib/steps/validate-not-present-package.d.ts +3 -0
- package/lib/steps/validate-not-present-package.js +7 -4
- package/lib/steps/validate-present-package.d.ts +3 -0
- package/lib/steps/validate-present-package.js +24 -0
- package/lib/steps/write-text-files.d.ts +3 -0
- package/lib/steps/write-text-files.js +16 -7
- package/lib/types/binary-file.d.ts +4 -0
- package/lib/types/command.d.ts +5 -0
- package/lib/types/config.d.ts +58 -0
- package/lib/types/context.d.ts +56 -0
- package/lib/types/format.d.ts +10 -0
- package/lib/types/step.d.ts +3 -0
- package/lib/types/text-file.d.ts +7 -0
- package/lib/types/travel.d.ts +14 -0
- package/lib/utils/apply-transforms.d.ts +2 -0
- package/lib/utils/apply-transforms.js +48 -0
- package/lib/utils/build-journey-plan.d.ts +2 -0
- package/lib/utils/build-route.d.ts +3 -0
- package/lib/utils/build-route.js +92 -0
- package/lib/utils/build-travel-plan.d.ts +2 -0
- package/lib/utils/build-travel.d.ts +3 -0
- package/lib/utils/build-travel.js +32 -0
- package/lib/utils/command/dedupe-strings.d.ts +1 -0
- package/lib/utils/command/index.d.ts +8 -0
- package/lib/utils/command/index.js +14 -14
- package/lib/utils/command/join-command.d.ts +2 -0
- package/lib/utils/command/merge-and-chains.d.ts +1 -0
- package/lib/utils/command/merge-and-chains.js +34 -25
- package/lib/utils/command/merge-command-records.d.ts +2 -0
- package/lib/utils/command/merge-command-records.js +43 -22
- package/lib/utils/command/merge-flag-tokens.d.ts +1 -0
- package/lib/utils/command/merge-flag-tokens.js +1 -1
- package/lib/utils/command/merge-flags-as-string.d.ts +4 -0
- package/lib/utils/command/merge-flags-as-string.js +4 -4
- package/lib/utils/command/merge-or-segments.d.ts +1 -0
- package/lib/utils/command/merge-or-segments.js +28 -28
- package/lib/utils/command/merge-parts-by-prefix.d.ts +1 -0
- package/lib/utils/command/merge-parts-by-prefix.js +6 -6
- package/lib/utils/command/merge-semicolon-segments.d.ts +1 -0
- package/lib/utils/command/merge-semicolon-segments.js +35 -35
- package/lib/utils/command/merge-with-semicolon-mix.d.ts +1 -0
- package/lib/utils/command/merge-with-semicolon-mix.js +12 -12
- package/lib/utils/command/prefix-of-command.d.ts +1 -0
- package/lib/utils/command/prefix-of-command.js +2 -2
- package/lib/utils/command/split-chain.d.ts +1 -0
- package/lib/utils/command/split-command.d.ts +2 -0
- package/lib/utils/command/split-command.js +8 -8
- package/lib/utils/command/split-prefix-and-flags.d.ts +4 -0
- package/lib/utils/command/split-prefix-and-flags.js +5 -5
- package/lib/utils/command/split-segments.d.ts +1 -0
- package/lib/utils/detect-indent.d.ts +5 -0
- package/lib/utils/detect-indent.js +60 -0
- package/lib/utils/flow.d.ts +3 -0
- package/lib/utils/flow.js +12 -0
- package/lib/utils/get-format.d.ts +2 -0
- package/lib/utils/get-format.js +19 -0
- package/lib/utils/has-final-new-line.d.ts +1 -0
- package/lib/utils/has-final-new-line.js +7 -0
- package/lib/utils/read-buffer.d.ts +2 -0
- package/lib/utils/resolve-request.d.ts +3 -0
- package/lib/utils/resolve-request.js +4 -3
- package/lib/utils/template.d.ts +17 -0
- package/lib/utils/template.js +79 -57
- package/lib/utils/to-lines.d.ts +1 -0
- package/lib/utils/trim-final-newline.d.ts +1 -0
- package/lib/utils/try-json.d.ts +1 -0
- package/lib/utils/try-json.js +2 -2
- package/package.json +123 -101
- package/lib/utils/dev-null.js +0 -7
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export type Request = {
|
|
2
|
+
name: string;
|
|
3
|
+
variant?: string;
|
|
4
|
+
};
|
|
5
|
+
export type PackageManifest = {
|
|
6
|
+
name: string;
|
|
7
|
+
version: string;
|
|
8
|
+
};
|
|
9
|
+
export type PackageConfig = {
|
|
10
|
+
constants: Record<string, string>;
|
|
11
|
+
extends?: string;
|
|
12
|
+
install: Record<string, FileInstall>;
|
|
13
|
+
orphan: boolean;
|
|
14
|
+
uninstall: Record<string, FileUninstall>;
|
|
15
|
+
update: false | Record<string, FileUpdate>;
|
|
16
|
+
variables: Record<string, string>;
|
|
17
|
+
variants: Record<string, string>;
|
|
18
|
+
};
|
|
19
|
+
export type Artifact = {
|
|
20
|
+
version: string;
|
|
21
|
+
provides?: string[];
|
|
22
|
+
requires?: string[];
|
|
23
|
+
};
|
|
24
|
+
export type ArtifactResult = Artifact & {
|
|
25
|
+
name: string;
|
|
26
|
+
};
|
|
27
|
+
export type InstallConfig = {
|
|
28
|
+
artifacts: Record<string, Artifact>;
|
|
29
|
+
constants: Record<string, string>;
|
|
30
|
+
install: Record<string, FileInstall>;
|
|
31
|
+
update: false | Record<string, FileUpdate>;
|
|
32
|
+
variables: Record<string, string>;
|
|
33
|
+
};
|
|
34
|
+
export type FileAlways = {
|
|
35
|
+
ifExists: 'force-merge' | 'merge' | 'overwrite' | 'remove' | 'skip';
|
|
36
|
+
transforms: FileTransform[];
|
|
37
|
+
};
|
|
38
|
+
export type FileUpsert = FileAlways & {
|
|
39
|
+
filter?: string[];
|
|
40
|
+
ifMissing: 'merge' | 'skip';
|
|
41
|
+
rename?: string;
|
|
42
|
+
route?: Record<string, any>;
|
|
43
|
+
};
|
|
44
|
+
export type FileInstall = FileUpsert & {};
|
|
45
|
+
export type FileUninstall = {
|
|
46
|
+
ifExists: 'remove' | 'skip' | 'unmerge';
|
|
47
|
+
transforms: FileTransform[];
|
|
48
|
+
};
|
|
49
|
+
export type FileUpdate = FileUpsert & {};
|
|
50
|
+
export type FileTransform = {
|
|
51
|
+
description?: string;
|
|
52
|
+
jq: string;
|
|
53
|
+
};
|
|
54
|
+
export type InstallConfigStats = {
|
|
55
|
+
name: string;
|
|
56
|
+
type: string;
|
|
57
|
+
finalNewLine: boolean;
|
|
58
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type AsyncDResult } from '@zokugun/xtry';
|
|
2
|
+
import { type BinaryFile } from './binary-file.js';
|
|
3
|
+
import { type Request, type InstallConfig, type PackageConfig, type ArtifactResult, type PackageManifest, type FileTransform } from './config.js';
|
|
4
|
+
import { type Format } from './format.js';
|
|
5
|
+
import { type TextFile } from './text-file.js';
|
|
6
|
+
import { type Journey } from './travel.js';
|
|
7
|
+
export type ExistingAction = 'merge' | 'overwrite' | 'skip';
|
|
8
|
+
export type MissingAction = 'continue' | 'skip';
|
|
9
|
+
export type RenameAction = {
|
|
10
|
+
from: string;
|
|
11
|
+
to: string;
|
|
12
|
+
};
|
|
13
|
+
export type Context = {
|
|
14
|
+
binaryFiles: BinaryFile[];
|
|
15
|
+
blocks: Block[];
|
|
16
|
+
commonFlow: CommonFlow;
|
|
17
|
+
config: InstallConfig;
|
|
18
|
+
filters: (file: string) => string[] | undefined;
|
|
19
|
+
formats: Format[];
|
|
20
|
+
incomingName?: string;
|
|
21
|
+
incomingVersion?: string;
|
|
22
|
+
incomingVariant?: string;
|
|
23
|
+
incomingBranch?: string;
|
|
24
|
+
incomingConfig?: PackageConfig;
|
|
25
|
+
incomingPackage?: PackageManifest;
|
|
26
|
+
incomingPath: string;
|
|
27
|
+
mergedTextFiles: TextFile[];
|
|
28
|
+
onExisting: (file: string) => ExistingAction;
|
|
29
|
+
onMissing: (file: string) => MissingAction;
|
|
30
|
+
options: Options;
|
|
31
|
+
packagePath: string;
|
|
32
|
+
removedPatterns: string[];
|
|
33
|
+
renamedPatterns: RenameAction[];
|
|
34
|
+
request: Request;
|
|
35
|
+
result?: ArtifactResult;
|
|
36
|
+
routes: (file: string) => Journey | undefined;
|
|
37
|
+
targetPath: string;
|
|
38
|
+
textFiles: TextFile[];
|
|
39
|
+
transformedFiles: TextFile[];
|
|
40
|
+
transforms: (file: string) => FileTransform[] | undefined;
|
|
41
|
+
};
|
|
42
|
+
export type MainFlow = (targetPath: string, incomingPath: string, request: Request, config: InstallConfig, options: Options) => AsyncDResult<Context | undefined>;
|
|
43
|
+
export type CommonFlow = (name: string, version: string, variant: string | undefined, branch: string | undefined, incomingPath: string, commonContext: Context) => AsyncDResult<Context | undefined>;
|
|
44
|
+
export type Options = {
|
|
45
|
+
force: boolean;
|
|
46
|
+
skip: boolean;
|
|
47
|
+
verbose: boolean;
|
|
48
|
+
dryRun: boolean;
|
|
49
|
+
};
|
|
50
|
+
export type Block = {
|
|
51
|
+
name: string;
|
|
52
|
+
version: string;
|
|
53
|
+
variant?: string;
|
|
54
|
+
branch?: string;
|
|
55
|
+
incomingPath: string;
|
|
56
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type FileTransform } from './config.js';
|
|
2
|
+
export type Args<T> = {
|
|
3
|
+
current: T | undefined;
|
|
4
|
+
incoming: T | undefined;
|
|
5
|
+
filters?: string[];
|
|
6
|
+
ignores?: string[];
|
|
7
|
+
transforms?: FileTransform[];
|
|
8
|
+
};
|
|
9
|
+
export type Route<T> = (args: Args<T>) => Promise<T>;
|
|
10
|
+
export type TravelPlan = (basename: string) => Route<string> | undefined;
|
|
11
|
+
export type Journey = {
|
|
12
|
+
alias?: string;
|
|
13
|
+
travel: Route<string>;
|
|
14
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.applyTransforms = applyTransforms;
|
|
37
|
+
const jq = __importStar(require("jq-wasm"));
|
|
38
|
+
function applyTransforms(transforms) {
|
|
39
|
+
if (!transforms) {
|
|
40
|
+
return async (data) => data;
|
|
41
|
+
}
|
|
42
|
+
return async (data) => {
|
|
43
|
+
for (const transform of transforms) {
|
|
44
|
+
data = await jq.json(data, transform.jq);
|
|
45
|
+
}
|
|
46
|
+
return data;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildRoute = buildRoute;
|
|
4
|
+
const is_it_type_1 = require("@zokugun/is-it-type");
|
|
5
|
+
const xtry_1 = require("@zokugun/xtry");
|
|
6
|
+
const fork_js_1 = require("../compositors/fork.js");
|
|
7
|
+
const index_js_1 = require("../compositors/index.js");
|
|
8
|
+
const index_js_2 = require("../routes/index.js");
|
|
9
|
+
function buildRoute(route) {
|
|
10
|
+
if (Array.isArray(route) && route.length > 0) {
|
|
11
|
+
const buildResult = buildRoute(route[0]);
|
|
12
|
+
if (buildResult.fails) {
|
|
13
|
+
return buildResult;
|
|
14
|
+
}
|
|
15
|
+
let result = buildResult.value;
|
|
16
|
+
for (let i = 1; i < route.length; i++) {
|
|
17
|
+
if (route[i] === 'mapSort') {
|
|
18
|
+
result = (0, index_js_1.mapSort)(result);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
return (0, xtry_1.err)('Can\'t build route');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return (0, xtry_1.ok)(result);
|
|
25
|
+
}
|
|
26
|
+
else if ((0, is_it_type_1.isRecord)(route)) {
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
28
|
+
const { compose: rtCompose, fork: rtFork, mapSort: rtMapSort } = route;
|
|
29
|
+
if (rtCompose) {
|
|
30
|
+
const map = {};
|
|
31
|
+
for (const [name, route] of Object.entries(rtCompose)) {
|
|
32
|
+
const result = buildRoute(route);
|
|
33
|
+
if (result.fails) {
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
map[name] = result.value;
|
|
37
|
+
}
|
|
38
|
+
return (0, xtry_1.ok)((0, index_js_1.compose)(map));
|
|
39
|
+
}
|
|
40
|
+
else if (rtFork) {
|
|
41
|
+
const map = [];
|
|
42
|
+
if (rtFork.array) {
|
|
43
|
+
const result = buildRoute(rtFork.array);
|
|
44
|
+
if (result.fails) {
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
map.push([Array.isArray, result.value]);
|
|
48
|
+
}
|
|
49
|
+
if (rtFork.object) {
|
|
50
|
+
const result = buildRoute(rtFork.object);
|
|
51
|
+
if (result.fails) {
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
map.push([is_it_type_1.isRecord, result.value]);
|
|
55
|
+
}
|
|
56
|
+
if (rtFork.default) {
|
|
57
|
+
const result = buildRoute(rtFork.default);
|
|
58
|
+
if (result.fails) {
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
map.push(result.value);
|
|
62
|
+
}
|
|
63
|
+
return (0, xtry_1.ok)((0, fork_js_1.fork)(...map));
|
|
64
|
+
}
|
|
65
|
+
else if (rtMapSort) {
|
|
66
|
+
const result = buildRoute(rtMapSort);
|
|
67
|
+
if (result.fails) {
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
return (0, xtry_1.ok)((0, index_js_1.mapSort)(result.value));
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else if (route === 'command') {
|
|
74
|
+
return (0, xtry_1.ok)(index_js_2.command);
|
|
75
|
+
}
|
|
76
|
+
else if (route === 'linesConcat') {
|
|
77
|
+
return (0, xtry_1.ok)(index_js_2.linesConcat);
|
|
78
|
+
}
|
|
79
|
+
else if (route === 'listConcat') {
|
|
80
|
+
return (0, xtry_1.ok)(index_js_2.listConcat);
|
|
81
|
+
}
|
|
82
|
+
else if (route === 'mapConcat') {
|
|
83
|
+
return (0, xtry_1.ok)(index_js_2.mapConcat);
|
|
84
|
+
}
|
|
85
|
+
else if (route === 'overwrite') {
|
|
86
|
+
return (0, xtry_1.ok)(index_js_2.overwrite);
|
|
87
|
+
}
|
|
88
|
+
else if (route === 'primitive') {
|
|
89
|
+
return (0, xtry_1.ok)(index_js_2.primitive);
|
|
90
|
+
}
|
|
91
|
+
return (0, xtry_1.err)('Can\'t build route');
|
|
92
|
+
} // }}}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildTravel = buildTravel;
|
|
4
|
+
const xtry_1 = require("@zokugun/xtry");
|
|
5
|
+
const index_js_1 = require("../compositors/index.js");
|
|
6
|
+
const build_route_js_1 = require("./build-route.js");
|
|
7
|
+
function buildTravel(route) {
|
|
8
|
+
if (route.json) {
|
|
9
|
+
const result = (0, build_route_js_1.buildRoute)(route.json);
|
|
10
|
+
if (result.fails) {
|
|
11
|
+
return result;
|
|
12
|
+
}
|
|
13
|
+
return (0, xtry_1.ok)((0, index_js_1.json)(result.value));
|
|
14
|
+
}
|
|
15
|
+
else if (route.rc) {
|
|
16
|
+
const result = (0, build_route_js_1.buildRoute)(route.rc);
|
|
17
|
+
if (result.fails) {
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
return (0, xtry_1.ok)((0, index_js_1.rc)(result.value));
|
|
21
|
+
}
|
|
22
|
+
else if (route.yaml) {
|
|
23
|
+
const result = (0, build_route_js_1.buildRoute)(route.yaml);
|
|
24
|
+
if (result.fails) {
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
return (0, xtry_1.ok)((0, index_js_1.yaml)(result.value));
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return (0, xtry_1.err)('Can\'t build route');
|
|
31
|
+
}
|
|
32
|
+
} // }}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function dedupeStrings(items: string[]): string[];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { Command } from '../../types/command.js';
|
|
2
|
+
export { joinCommand } from './join-command.js';
|
|
3
|
+
export { mergeAndChains } from './merge-and-chains.js';
|
|
4
|
+
export { mergeCommandRecords } from './merge-command-records.js';
|
|
5
|
+
export { mergeOrSegments } from './merge-or-segments.js';
|
|
6
|
+
export { mergeSemicolonSegments } from './merge-semicolon-segments.js';
|
|
7
|
+
export { mergeWithSemicolonMix } from './merge-with-semicolon-mix.js';
|
|
8
|
+
export { splitCommand } from './split-command.js';
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.splitCommand = exports.mergeWithSemicolonMix = exports.mergeSemicolonSegments = exports.mergeOrSegments = exports.mergeCommandRecords = exports.mergeAndChains = exports.joinCommand = void 0;
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "joinCommand", { enumerable: true, get: function () { return
|
|
6
|
-
var
|
|
7
|
-
Object.defineProperty(exports, "mergeAndChains", { enumerable: true, get: function () { return
|
|
8
|
-
var
|
|
9
|
-
Object.defineProperty(exports, "mergeCommandRecords", { enumerable: true, get: function () { return
|
|
10
|
-
var
|
|
11
|
-
Object.defineProperty(exports, "mergeOrSegments", { enumerable: true, get: function () { return
|
|
12
|
-
var
|
|
13
|
-
Object.defineProperty(exports, "mergeSemicolonSegments", { enumerable: true, get: function () { return
|
|
14
|
-
var
|
|
15
|
-
Object.defineProperty(exports, "mergeWithSemicolonMix", { enumerable: true, get: function () { return
|
|
16
|
-
var
|
|
17
|
-
Object.defineProperty(exports, "splitCommand", { enumerable: true, get: function () { return
|
|
4
|
+
var join_command_js_1 = require("./join-command.js");
|
|
5
|
+
Object.defineProperty(exports, "joinCommand", { enumerable: true, get: function () { return join_command_js_1.joinCommand; } });
|
|
6
|
+
var merge_and_chains_js_1 = require("./merge-and-chains.js");
|
|
7
|
+
Object.defineProperty(exports, "mergeAndChains", { enumerable: true, get: function () { return merge_and_chains_js_1.mergeAndChains; } });
|
|
8
|
+
var merge_command_records_js_1 = require("./merge-command-records.js");
|
|
9
|
+
Object.defineProperty(exports, "mergeCommandRecords", { enumerable: true, get: function () { return merge_command_records_js_1.mergeCommandRecords; } });
|
|
10
|
+
var merge_or_segments_js_1 = require("./merge-or-segments.js");
|
|
11
|
+
Object.defineProperty(exports, "mergeOrSegments", { enumerable: true, get: function () { return merge_or_segments_js_1.mergeOrSegments; } });
|
|
12
|
+
var merge_semicolon_segments_js_1 = require("./merge-semicolon-segments.js");
|
|
13
|
+
Object.defineProperty(exports, "mergeSemicolonSegments", { enumerable: true, get: function () { return merge_semicolon_segments_js_1.mergeSemicolonSegments; } });
|
|
14
|
+
var merge_with_semicolon_mix_js_1 = require("./merge-with-semicolon-mix.js");
|
|
15
|
+
Object.defineProperty(exports, "mergeWithSemicolonMix", { enumerable: true, get: function () { return merge_with_semicolon_mix_js_1.mergeWithSemicolonMix; } });
|
|
16
|
+
var split_command_js_1 = require("./split-command.js");
|
|
17
|
+
Object.defineProperty(exports, "splitCommand", { enumerable: true, get: function () { return split_command_js_1.splitCommand; } });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function mergeAndChains(current: string, incoming: string): string | undefined;
|
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.mergeAndChains = mergeAndChains;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
4
|
+
const dedupe_strings_js_1 = require("./dedupe-strings.js");
|
|
5
|
+
const merge_flags_as_string_js_1 = require("./merge-flags-as-string.js");
|
|
6
|
+
const merge_parts_by_prefix_js_1 = require("./merge-parts-by-prefix.js");
|
|
7
|
+
const prefix_of_command_js_1 = require("./prefix-of-command.js");
|
|
8
|
+
const split_chain_js_1 = require("./split-chain.js");
|
|
9
|
+
const split_prefix_and_flags_js_1 = require("./split-prefix-and-flags.js");
|
|
10
|
+
const split_segments_js_1 = require("./split-segments.js");
|
|
11
11
|
function mergeAndChains(current, incoming) {
|
|
12
12
|
if (!(incoming.includes('&&') && current.includes('&&'))) {
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
15
|
const currentMain = (current.split(';')[0] || '').trim();
|
|
16
16
|
const incomingMain = (incoming.split(';')[0] || '').trim();
|
|
17
|
-
const currentAnd = (0,
|
|
18
|
-
const incomingAnd = (0,
|
|
17
|
+
const currentAnd = (0, split_chain_js_1.splitChain)(currentMain, '&&');
|
|
18
|
+
const incomingAnd = (0, split_chain_js_1.splitChain)(incomingMain, '&&');
|
|
19
19
|
// Consider positional match primarily by the first segment's prefix
|
|
20
20
|
const firstCurrent = currentAnd[0] || '';
|
|
21
21
|
const firstIncoming = incomingAnd[0] || '';
|
|
22
|
-
const positionalMatch = (0,
|
|
22
|
+
const positionalMatch = (0, prefix_of_command_js_1.prefixOfCommand)(firstCurrent) === (0, prefix_of_command_js_1.prefixOfCommand)(firstIncoming);
|
|
23
23
|
if (!positionalMatch) {
|
|
24
24
|
// Merge by matching prefixes across current segments, append unmatched incoming segments.
|
|
25
|
-
const merged = (0,
|
|
25
|
+
const merged = (0, merge_parts_by_prefix_js_1.mergePartsByPrefix)(currentAnd, incomingAnd);
|
|
26
26
|
return merged.join('; ');
|
|
27
27
|
}
|
|
28
28
|
// Positional merge: iterate positions, merge flags when prefixes equal, otherwise
|
|
29
29
|
// decide ordering: if incoming's semicolon tail contains current segment, prefer incoming in chain and move current to tail;
|
|
30
30
|
// else keep current in chain then append incoming segment after it.
|
|
31
|
-
const incomingTail = (0,
|
|
32
|
-
const currentTail = (0,
|
|
31
|
+
const incomingTail = (0, split_segments_js_1.splitSegments)(incoming).slice(1);
|
|
32
|
+
const currentTail = (0, split_segments_js_1.splitSegments)(current).slice(1);
|
|
33
33
|
const maxLength = Math.max(currentAnd.length, incomingAnd.length);
|
|
34
34
|
const chainResult = [];
|
|
35
35
|
const tailResult = [];
|
|
@@ -37,14 +37,14 @@ function mergeAndChains(current, incoming) {
|
|
|
37
37
|
const currentPart = currentAnd[i];
|
|
38
38
|
const incomingPart = incomingAnd[i];
|
|
39
39
|
if (currentPart && incomingPart) {
|
|
40
|
-
const cPref = (0,
|
|
41
|
-
const nPref = (0,
|
|
40
|
+
const cPref = (0, prefix_of_command_js_1.prefixOfCommand)(currentPart);
|
|
41
|
+
const nPref = (0, prefix_of_command_js_1.prefixOfCommand)(incomingPart);
|
|
42
42
|
if (cPref && nPref && cPref === nPref) {
|
|
43
43
|
if (incomingTail.length > 0) {
|
|
44
|
-
chainResult.push((0,
|
|
44
|
+
chainResult.push((0, merge_flags_as_string_js_1.mergeFlagsAsString)(incomingPart, (0, split_prefix_and_flags_js_1.splitPrefixAndFlags)(currentPart)));
|
|
45
45
|
}
|
|
46
46
|
else {
|
|
47
|
-
chainResult.push((0,
|
|
47
|
+
chainResult.push((0, merge_flags_as_string_js_1.mergeFlagsAsString)(currentPart, (0, split_prefix_and_flags_js_1.splitPrefixAndFlags)(incomingPart)));
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
else {
|
|
@@ -55,11 +55,20 @@ function mergeAndChains(current, incoming) {
|
|
|
55
55
|
tailResult.push(currentPart);
|
|
56
56
|
}
|
|
57
57
|
else {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (
|
|
62
|
-
|
|
58
|
+
const currentAppearsLaterInIncoming = incomingAnd
|
|
59
|
+
.slice(i + 1)
|
|
60
|
+
.some((later) => (0, prefix_of_command_js_1.prefixOfCommand)(later) === cPref);
|
|
61
|
+
if (currentAppearsLaterInIncoming) {
|
|
62
|
+
// Incoming inserted a step before current and shifted current to the right.
|
|
63
|
+
chainResult.push(incomingPart, currentPart);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
// keep current in chain, then include incoming after
|
|
67
|
+
chainResult.push(currentPart);
|
|
68
|
+
const coveredByCurrentTail = currentTail.some((t) => t.startsWith(`${incomingPart} `));
|
|
69
|
+
if (!coveredByCurrentTail) {
|
|
70
|
+
chainResult.push(incomingPart);
|
|
71
|
+
}
|
|
63
72
|
}
|
|
64
73
|
}
|
|
65
74
|
}
|
|
@@ -71,12 +80,12 @@ function mergeAndChains(current, incoming) {
|
|
|
71
80
|
chainResult.push(incomingPart);
|
|
72
81
|
}
|
|
73
82
|
}
|
|
74
|
-
const dedupedChain = (0,
|
|
83
|
+
const dedupedChain = (0, dedupe_strings_js_1.dedupeStrings)(chainResult);
|
|
75
84
|
// Append any remaining semicolon tails from current and incoming (preserve incoming tail order)
|
|
76
85
|
// remove any tail entries that are already present in the chainResult (by prefix)
|
|
77
|
-
const chainPrefixes = new Set(dedupedChain.map(
|
|
86
|
+
const chainPrefixes = new Set(dedupedChain.map(prefix_of_command_js_1.prefixOfCommand).filter(Boolean));
|
|
78
87
|
const combined = [...tailResult, ...currentTail, ...incomingTail].filter((t) => {
|
|
79
|
-
const tp = (0,
|
|
88
|
+
const tp = (0, prefix_of_command_js_1.prefixOfCommand)(t) || t;
|
|
80
89
|
return !chainPrefixes.has(tp);
|
|
81
90
|
});
|
|
82
91
|
const seen = new Set();
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.mergeCommandRecords = mergeCommandRecords;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
function mergeCommandRecords(currentCommand, incomingCommand, currentString) {
|
|
4
|
+
const lodash_es_1 = require("lodash-es");
|
|
5
|
+
const list_concat_js_1 = require("../../routes/list-concat.js");
|
|
6
|
+
async function mergeCommandRecords(currentCommand, incomingCommand, currentString) {
|
|
7
7
|
const result = {};
|
|
8
8
|
// Start with current commands to preserve ordering
|
|
9
9
|
for (const [name, instances] of Object.entries(currentCommand)) {
|
|
10
|
-
result[name] = instances
|
|
10
|
+
result[name] = [...instances];
|
|
11
11
|
}
|
|
12
12
|
// Merge incoming into existing result, preserving order
|
|
13
13
|
for (const [name, instances] of Object.entries(incomingCommand)) {
|
|
14
14
|
if (result[name]) {
|
|
15
|
-
for (const [
|
|
16
|
-
if (result[name][
|
|
17
|
-
const currentInstance = result[name][
|
|
15
|
+
for (const [index, instance] of instances.entries()) {
|
|
16
|
+
if (result[name][index]) {
|
|
17
|
+
const currentInstance = result[name][index];
|
|
18
18
|
const hasFlags = (array) => array.some((a) => a.startsWith('-') || a.includes('='));
|
|
19
19
|
const getPrefix = (array) => {
|
|
20
20
|
const ii = array.findIndex((a) => a.startsWith('-'));
|
|
@@ -28,9 +28,9 @@ function mergeCommandRecords(currentCommand, incomingCommand, currentString) {
|
|
|
28
28
|
const shouldMerge = currentPrefix && incomingPrefix && currentPrefix === incomingPrefix && (hasFlags(currentInstance.args) || hasFlags(instance.args) || (currentInstance.env.length > 0) || (instance.env.length > 0));
|
|
29
29
|
if (shouldMerge) {
|
|
30
30
|
// replace with merged instance
|
|
31
|
-
result[name][
|
|
32
|
-
args: (0,
|
|
33
|
-
env: (0,
|
|
31
|
+
result[name][index] = {
|
|
32
|
+
args: await (0, list_concat_js_1.listConcat)({ current: currentInstance.args, incoming: instance.args }),
|
|
33
|
+
env: await (0, list_concat_js_1.listConcat)({ current: currentInstance.env, incoming: instance.env }),
|
|
34
34
|
separator: instance.separator ?? currentInstance.separator,
|
|
35
35
|
};
|
|
36
36
|
}
|
|
@@ -38,26 +38,39 @@ function mergeCommandRecords(currentCommand, incomingCommand, currentString) {
|
|
|
38
38
|
// If incoming instance is empty (no args/env), skip it to avoid duplicates
|
|
39
39
|
if ((instance.args.length === 0) && (instance.env.length === 0)) {
|
|
40
40
|
// keep current as-is
|
|
41
|
-
result[name][
|
|
41
|
+
result[name][index] = currentInstance;
|
|
42
42
|
}
|
|
43
|
-
else if ((0,
|
|
43
|
+
else if ((0, lodash_es_1.isEqual)(currentInstance.env, instance.env)
|
|
44
44
|
&& instance.args.length > 0
|
|
45
45
|
&& instance.args.every((arg) => currentInstance.args.includes(arg))) {
|
|
46
46
|
// Incoming is a strict subset of current args for the same command/env.
|
|
47
|
-
result[name][
|
|
47
|
+
result[name][index] = currentInstance;
|
|
48
48
|
}
|
|
49
49
|
else {
|
|
50
50
|
// avoid inserting exact duplicate instances
|
|
51
|
-
const duplicateExists = result[name].some((r) => (0,
|
|
51
|
+
const duplicateExists = result[name].some((r) => (0, lodash_es_1.isEqual)(r.args, instance.args) && (0, lodash_es_1.isEqual)(r.env, instance.env));
|
|
52
52
|
if (duplicateExists) {
|
|
53
53
|
// nothing to do, keep current ordering
|
|
54
|
-
result[name][
|
|
54
|
+
result[name][index] = currentInstance;
|
|
55
|
+
}
|
|
56
|
+
else if (!hasFlags(currentInstance.args)
|
|
57
|
+
&& !hasFlags(instance.args)
|
|
58
|
+
&& currentInstance.env.length === 0
|
|
59
|
+
&& instance.env.length === 0
|
|
60
|
+
&& currentPrefix !== incomingPrefix) {
|
|
61
|
+
// Different singleton-like invocations of the same command should not be interleaved.
|
|
62
|
+
const lastIndex = result[name].length - 1;
|
|
63
|
+
const last = result[name][lastIndex];
|
|
64
|
+
if (last && !last.separator) {
|
|
65
|
+
last.separator = currentString.includes('&&') ? '&&' : ';';
|
|
66
|
+
}
|
|
67
|
+
result[name].push(instance);
|
|
55
68
|
}
|
|
56
69
|
else {
|
|
57
70
|
// insert incoming as separate after current
|
|
58
|
-
const
|
|
59
|
-
result[name][
|
|
60
|
-
result[name].splice(
|
|
71
|
+
const currentWithSeparator = { ...currentInstance, separator: currentInstance.separator ?? (currentString.includes('&&') ? '&&' : ';') };
|
|
72
|
+
result[name][index] = currentWithSeparator;
|
|
73
|
+
result[name].splice(index + 1, 0, instance);
|
|
61
74
|
}
|
|
62
75
|
}
|
|
63
76
|
}
|
|
@@ -69,14 +82,22 @@ function mergeCommandRecords(currentCommand, incomingCommand, currentString) {
|
|
|
69
82
|
}
|
|
70
83
|
else {
|
|
71
84
|
// incoming-only: append
|
|
72
|
-
|
|
85
|
+
const previousNames = Object.keys(result);
|
|
86
|
+
const previousName = previousNames.at(-1);
|
|
87
|
+
const isPlainSequence = !currentString.includes('&&') && !currentString.includes('||') && !currentString.includes(';');
|
|
88
|
+
if (isPlainSequence && previousName) {
|
|
89
|
+
const previousInstances = result[previousName];
|
|
90
|
+
const lastPrevious = previousInstances.at(-1);
|
|
91
|
+
if (lastPrevious && !lastPrevious.separator) {
|
|
92
|
+
lastPrevious.separator = ';';
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
result[name] = [...instances];
|
|
73
96
|
}
|
|
74
97
|
}
|
|
75
98
|
// Include current-only entries that weren't present in incoming
|
|
76
99
|
for (const [name, instances] of Object.entries(currentCommand)) {
|
|
77
|
-
|
|
78
|
-
result[name] = instances;
|
|
79
|
-
}
|
|
100
|
+
result[name] ||= instances;
|
|
80
101
|
}
|
|
81
102
|
return result;
|
|
82
103
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function mergeFlagTokens(currentFlags: string[], incomingFlags: string[]): string[];
|