@zokugun/artifact 0.7.0 → 0.9.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/README.md +22 -2
- package/lib/cli.js +16 -11
- package/lib/commands/add.js +95 -22
- package/lib/commands/index.d.ts +1 -0
- package/lib/commands/index.js +3 -1
- package/lib/commands/list.js +25 -7
- package/lib/commands/outdated.d.ts +1 -0
- package/lib/commands/outdated.js +73 -0
- package/lib/commands/remove.js +39 -18
- package/lib/commands/update.js +36 -21
- package/lib/compositors/codec.d.ts +3 -0
- package/lib/compositors/codec.js +46 -0
- package/lib/compositors/compose.d.ts +1 -0
- package/lib/compositors/compose.js +4 -0
- package/lib/compositors/index.d.ts +1 -0
- package/lib/compositors/index.js +3 -1
- package/lib/compositors/json.js +3 -66
- package/lib/compositors/rc.js +3 -56
- package/lib/compositors/yaml.js +24 -3
- package/lib/configs/install/read-install-config.d.ts +2 -5
- package/lib/configs/install/read-install-config.js +20 -18
- package/lib/configs/install/write-install-config.d.ts +2 -2
- package/lib/configs/install/write-install-config.js +2 -1
- package/lib/configs/package/read-listing-config.d.ts +7 -0
- package/lib/configs/package/read-listing-config.js +71 -0
- package/lib/configs/package/read-package-config.d.ts +2 -1
- package/lib/configs/package/read-package-config.js +96 -10
- package/lib/configs/utils/constants.d.ts +2 -2
- package/lib/configs/utils/constants.js +2 -2
- package/lib/configs/utils/merge-upsert-property.js +0 -8
- package/lib/configs/utils/normalize-file-always.js +5 -0
- package/lib/configs/utils/normalize-file-upsert.d.ts +2 -1
- package/lib/configs/utils/normalize-file-upsert.js +12 -5
- package/lib/journeys/commitlint/index.d.ts +1 -1
- package/lib/journeys/config.ts/index.d.ts +1 -1
- package/lib/journeys/config.ts/index.js +2 -6
- package/lib/journeys/default/index.d.ts +1 -1
- package/lib/journeys/gitignore/index.d.ts +1 -1
- package/lib/journeys/ignore/index.d.ts +1 -1
- package/lib/journeys/index.d.ts +2 -2
- package/lib/journeys/index.js +9 -11
- package/lib/journeys/npmignore/index.d.ts +1 -1
- package/lib/journeys/package/index.d.ts +1 -1
- package/lib/journeys/rc/index.d.ts +1 -1
- package/lib/journeys/tsconfig/index.d.ts +1 -1
- package/lib/parsers/index.d.ts +4 -0
- package/lib/parsers/index.js +41 -0
- package/lib/parsers/json.d.ts +4 -2
- package/lib/parsers/json.js +7 -2
- package/lib/parsers/jsonc/parse.d.ts +2 -5
- package/lib/parsers/jsonc/parse.js +8 -6
- package/lib/parsers/to-format.d.ts +2 -0
- package/lib/parsers/to-format.js +50 -0
- package/lib/parsers/yaml.d.ts +4 -2
- package/lib/parsers/yaml.js +7 -2
- package/lib/routes/command.js +7 -0
- package/lib/routes/index.d.ts +4 -3
- package/lib/routes/index.js +9 -7
- package/lib/routes/{list-sort-concat.d.ts → list-concat-after.d.ts} +1 -1
- package/lib/routes/{list-sort-concat.js → list-concat-after.js} +2 -2
- package/lib/routes/merge-dot-js.d.ts +2 -0
- package/lib/routes/merge-dot-js.js +8 -0
- package/lib/steps/configure-install-file-actions.js +1 -20
- package/lib/steps/configure-update-file-actions.js +1 -20
- package/lib/steps/execute-first-block.js +1 -1
- package/lib/steps/index.d.ts +0 -2
- package/lib/steps/index.js +4 -3
- package/lib/steps/merge-text-files.d.ts +1 -1
- package/lib/steps/merge-text-files.js +6 -2
- package/lib/steps/read-files.d.ts +1 -1
- package/lib/steps/read-files.js +56 -42
- package/lib/steps/read-incoming-config.js +1 -1
- package/lib/steps/remove-files.d.ts +1 -1
- package/lib/steps/remove-files.js +3 -2
- package/lib/steps/rename-files.d.ts +1 -1
- package/lib/steps/rename-files.js +3 -2
- package/lib/steps/validate-newer-package.d.ts +1 -1
- package/lib/steps/validate-newer-package.js +13 -2
- package/lib/types/config.d.ts +11 -7
- package/lib/types/context.d.ts +23 -3
- package/lib/types/context.js +6 -0
- package/lib/types/travel.d.ts +1 -0
- package/lib/utils/build-journey-plan.d.ts +2 -2
- package/lib/utils/build-route.d.ts +1 -1
- package/lib/utils/build-route.js +50 -19
- package/lib/utils/build-travel-plan.js +1 -0
- package/lib/utils/command/merge-and-chains.js +1 -1
- package/lib/utils/command/merge-command-records.js +1 -1
- package/lib/utils/command/merge-parts-by-prefix.js +12 -1
- package/lib/utils/command/merge-semicolon-segments.js +161 -4
- package/lib/utils/fnmatch.d.ts +1 -0
- package/lib/utils/fnmatch.js +11 -0
- package/lib/utils/format-table.d.ts +1 -0
- package/lib/utils/format-table.js +58 -0
- package/lib/utils/get-format.js +2 -9
- package/lib/utils/load-package.d.ts +6 -0
- package/lib/utils/load-package.js +26 -0
- package/lib/utils/template.js +1 -3
- package/lib/utils/time-difference.d.ts +1 -0
- package/lib/utils/time-difference.js +28 -0
- package/package.json +128 -125
- package/lib/journeys/fixpack/index.d.ts +0 -2
- package/lib/journeys/fixpack/index.js +0 -16
- package/lib/steps/validate-not-present-package.d.ts +0 -3
- package/lib/steps/validate-not-present-package.js +0 -24
- package/lib/utils/try-json.d.ts +0 -1
- package/lib/utils/try-json.js +0 -11
package/lib/steps/read-files.js
CHANGED
|
@@ -9,63 +9,77 @@ const cli_utils_1 = require("@zokugun/cli-utils");
|
|
|
9
9
|
const async_1 = __importDefault(require("@zokugun/fs-extra-plus/async"));
|
|
10
10
|
const xtry_1 = require("@zokugun/xtry");
|
|
11
11
|
const istextorbinary_1 = require("istextorbinary");
|
|
12
|
+
const context_js_1 = require("../types/context.js");
|
|
12
13
|
const detect_indent_js_1 = require("../utils/detect-indent.js");
|
|
13
14
|
const has_final_new_line_js_1 = require("../utils/has-final-new-line.js");
|
|
14
15
|
const list_working_files_js_1 = require("../utils/list-working-files.js");
|
|
15
16
|
const read_buffer_js_1 = require("../utils/read-buffer.js");
|
|
16
|
-
async function readFiles({ incomingPath, textFiles, binaryFiles, options }) {
|
|
17
|
+
async function readFiles({ incomingPath, textFiles, binaryFiles, mode, global, options }) {
|
|
17
18
|
const cwd = path_1.default.join(incomingPath, 'configs');
|
|
18
19
|
const files = await (0, list_working_files_js_1.listWorkingFiles)(cwd);
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return (0, xtry_1.err)((0, xtry_1.stringifyError)(result.error));
|
|
26
|
-
}
|
|
27
|
-
const data = result.value;
|
|
28
|
-
const finalNewLine = (0, has_final_new_line_js_1.hasFinalNewLine)(data);
|
|
29
|
-
const indent = (0, detect_indent_js_1.detectIndent)(data);
|
|
30
|
-
if (data.startsWith('#!')) {
|
|
31
|
-
// the text file might be executable
|
|
32
|
-
const result = await async_1.default.stat(filePath);
|
|
33
|
-
if (result.fails) {
|
|
34
|
-
return (0, xtry_1.err)((0, xtry_1.stringifyError)(result.error));
|
|
35
|
-
}
|
|
36
|
-
const { mode } = result.value;
|
|
37
|
-
textFiles.push({
|
|
38
|
-
name: file,
|
|
39
|
-
data,
|
|
40
|
-
finalNewLine,
|
|
41
|
-
indent,
|
|
42
|
-
mode,
|
|
43
|
-
});
|
|
44
|
-
if (options.verbose) {
|
|
45
|
-
cli_utils_1.logger.debug(`${file} is a shebang file`);
|
|
46
|
-
}
|
|
20
|
+
if (mode === context_js_1.Mode.Default) {
|
|
21
|
+
for (const file of files) {
|
|
22
|
+
const filePath = path_1.default.join(cwd, file);
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
24
|
+
if ((0, istextorbinary_1.isText)(file) || (0, istextorbinary_1.getEncoding)(await (0, read_buffer_js_1.readBuffer)(filePath, 24)) === 'utf8') {
|
|
25
|
+
await readTextFile(file, filePath, textFiles, options);
|
|
47
26
|
}
|
|
48
27
|
else {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
finalNewLine,
|
|
53
|
-
indent,
|
|
28
|
+
binaryFiles.push({
|
|
29
|
+
source: file,
|
|
30
|
+
target: file,
|
|
54
31
|
});
|
|
55
32
|
if (options.verbose) {
|
|
56
|
-
cli_utils_1.logger.debug(`${file} is a
|
|
33
|
+
cli_utils_1.logger.debug(`${file} is a binary file`);
|
|
57
34
|
}
|
|
58
35
|
}
|
|
59
36
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
cli_utils_1.logger.debug(`${file} is a binary file`);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
for (const file of files) {
|
|
40
|
+
if (global.overwrittenTextFiles.includes(file)) {
|
|
41
|
+
const filePath = path_1.default.join(cwd, file);
|
|
42
|
+
await readTextFile(file, filePath, textFiles, options);
|
|
67
43
|
}
|
|
68
44
|
}
|
|
69
45
|
}
|
|
70
46
|
return xtry_1.OK;
|
|
71
47
|
}
|
|
48
|
+
async function readTextFile(file, filePath, textFiles, options) {
|
|
49
|
+
const result = await async_1.default.readFile(filePath, 'utf8');
|
|
50
|
+
if (result.fails) {
|
|
51
|
+
return (0, xtry_1.err)((0, xtry_1.stringifyError)(result.error));
|
|
52
|
+
}
|
|
53
|
+
const data = result.value;
|
|
54
|
+
const finalNewLine = (0, has_final_new_line_js_1.hasFinalNewLine)(data);
|
|
55
|
+
const indent = (0, detect_indent_js_1.detectIndent)(data);
|
|
56
|
+
if (data.startsWith('#!')) {
|
|
57
|
+
// the text file might be executable
|
|
58
|
+
const result = await async_1.default.stat(filePath);
|
|
59
|
+
if (result.fails) {
|
|
60
|
+
return (0, xtry_1.err)((0, xtry_1.stringifyError)(result.error));
|
|
61
|
+
}
|
|
62
|
+
const { mode } = result.value;
|
|
63
|
+
textFiles.push({
|
|
64
|
+
name: file,
|
|
65
|
+
data,
|
|
66
|
+
finalNewLine,
|
|
67
|
+
indent,
|
|
68
|
+
mode,
|
|
69
|
+
});
|
|
70
|
+
if (options.verbose) {
|
|
71
|
+
cli_utils_1.logger.debug(`${file} is a shebang file`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
textFiles.push({
|
|
76
|
+
name: file,
|
|
77
|
+
data,
|
|
78
|
+
finalNewLine,
|
|
79
|
+
indent,
|
|
80
|
+
});
|
|
81
|
+
if (options.verbose) {
|
|
82
|
+
cli_utils_1.logger.debug(`${file} is a text file`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
} // }}}
|
|
@@ -5,7 +5,7 @@ const xtry_1 = require("@zokugun/xtry");
|
|
|
5
5
|
const index_js_1 = require("../configs/index.js");
|
|
6
6
|
async function readIncomingConfig(context) {
|
|
7
7
|
if (!context.incomingConfig) {
|
|
8
|
-
const config = await (0, index_js_1.readPackageConfig)(context.incomingPath);
|
|
8
|
+
const config = await (0, index_js_1.readPackageConfig)(context.incomingPath, context.global.routes);
|
|
9
9
|
if (config.fails) {
|
|
10
10
|
return config;
|
|
11
11
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type AsyncDResult } from '@zokugun/xtry';
|
|
2
2
|
import { type Context } from '../types/context.js';
|
|
3
|
-
export declare function removeFiles({ removedPatterns, targetPath, options }: Context): AsyncDResult;
|
|
3
|
+
export declare function removeFiles({ removedPatterns, targetPath, mode, options }: Context): AsyncDResult;
|
|
@@ -9,9 +9,10 @@ const cli_utils_1 = require("@zokugun/cli-utils");
|
|
|
9
9
|
const async_1 = __importDefault(require("@zokugun/fs-extra-plus/async"));
|
|
10
10
|
const xtry_1 = require("@zokugun/xtry");
|
|
11
11
|
const micromatch_1 = require("micromatch");
|
|
12
|
+
const context_js_1 = require("../types/context.js");
|
|
12
13
|
const list_working_files_js_1 = require("../utils/list-working-files.js");
|
|
13
|
-
async function removeFiles({ removedPatterns, targetPath, options }) {
|
|
14
|
-
if (removedPatterns.length === 0) {
|
|
14
|
+
async function removeFiles({ removedPatterns, targetPath, mode, options }) {
|
|
15
|
+
if (removedPatterns.length === 0 || mode !== context_js_1.Mode.Default) {
|
|
15
16
|
return xtry_1.OK;
|
|
16
17
|
}
|
|
17
18
|
const cwd = path_1.default.join(targetPath);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type AsyncDResult } from '@zokugun/xtry';
|
|
2
2
|
import { type Context } from '../types/context.js';
|
|
3
|
-
export declare function renameFiles({ renamedPatterns, targetPath }: Context): AsyncDResult;
|
|
3
|
+
export declare function renameFiles({ renamedPatterns, targetPath, mode }: Context): AsyncDResult;
|
|
@@ -7,8 +7,9 @@ exports.renameFiles = renameFiles;
|
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const async_1 = __importDefault(require("@zokugun/fs-extra-plus/async"));
|
|
9
9
|
const xtry_1 = require("@zokugun/xtry");
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const context_js_1 = require("../types/context.js");
|
|
11
|
+
async function renameFiles({ renamedPatterns, targetPath, mode }) {
|
|
12
|
+
if (renamedPatterns.length === 0 || mode !== context_js_1.Mode.Default) {
|
|
12
13
|
return xtry_1.OK;
|
|
13
14
|
}
|
|
14
15
|
const cwd = path_1.default.join(targetPath);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type AsyncDResult } from '@zokugun/xtry';
|
|
2
2
|
import { type Context } from '../types/context.js';
|
|
3
|
-
export declare function validateNewerPackage(
|
|
3
|
+
export declare function validateNewerPackage(context: Context): AsyncDResult<boolean | void>;
|
|
@@ -3,13 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.validateNewerPackage = validateNewerPackage;
|
|
4
4
|
const xtry_1 = require("@zokugun/xtry");
|
|
5
5
|
const semver_1 = require("semver");
|
|
6
|
-
|
|
6
|
+
const context_js_1 = require("../types/context.js");
|
|
7
|
+
async function validateNewerPackage(context) {
|
|
8
|
+
const { incomingPackage, config, global, options } = context;
|
|
7
9
|
if (options.force) {
|
|
8
10
|
return xtry_1.OK;
|
|
9
11
|
}
|
|
10
12
|
const artifact = config.artifacts[incomingPackage.name];
|
|
11
13
|
if (artifact) {
|
|
12
|
-
|
|
14
|
+
const newer = (0, semver_1.gt)(incomingPackage.version, artifact.version);
|
|
15
|
+
if (newer) {
|
|
16
|
+
return xtry_1.OK_FALSE;
|
|
17
|
+
}
|
|
18
|
+
else if (global.overwrittenTextFiles.length > 0) {
|
|
19
|
+
context.mode = context_js_1.Mode.Overwritten;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
return xtry_1.OK_TRUE;
|
|
23
|
+
}
|
|
13
24
|
}
|
|
14
25
|
return xtry_1.OK;
|
|
15
26
|
}
|
package/lib/types/config.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type Primitive } from '@zokugun/is-it-type';
|
|
2
2
|
import { type Indent } from './format.js';
|
|
3
|
+
import { type JourneyPlan, type Route } from './travel.js';
|
|
3
4
|
export type Request = {
|
|
4
5
|
name: string;
|
|
5
6
|
variant?: string;
|
|
@@ -11,7 +12,9 @@ export type PackageManifest = {
|
|
|
11
12
|
export type PackageConfig = {
|
|
12
13
|
extends?: string;
|
|
13
14
|
install: InstallFileConfig[];
|
|
15
|
+
journeys: Record<string, JourneyPlan>;
|
|
14
16
|
orphan: boolean;
|
|
17
|
+
routes: Record<string, Route<any>>;
|
|
15
18
|
uninstall: UninstallFileConfig[];
|
|
16
19
|
update: false | UpdateFileConfig[];
|
|
17
20
|
variables: Record<string, Primitive>;
|
|
@@ -26,8 +29,16 @@ export type ArtifactResult = Artifact & {
|
|
|
26
29
|
name: string;
|
|
27
30
|
};
|
|
28
31
|
export type InstallConfig = {
|
|
32
|
+
file: {
|
|
33
|
+
name: string;
|
|
34
|
+
finalNewLine: boolean;
|
|
35
|
+
indent?: Indent;
|
|
36
|
+
type: string;
|
|
37
|
+
};
|
|
29
38
|
artifacts: Record<string, Artifact>;
|
|
30
39
|
install: Record<string, InstallFileConfig>;
|
|
40
|
+
journeys: Record<string, JourneyPlan>;
|
|
41
|
+
routes: Record<string, Route<any>>;
|
|
31
42
|
update: false | Record<string, UpdateFileConfig>;
|
|
32
43
|
variables: Record<string, Primitive>;
|
|
33
44
|
};
|
|
@@ -44,15 +55,8 @@ export type UpsertFileConfig = AlwaysFileConfig & {
|
|
|
44
55
|
filter?: string[];
|
|
45
56
|
ifMissing: 'merge' | 'skip';
|
|
46
57
|
rename?: string;
|
|
47
|
-
route?: Record<string, any>;
|
|
48
58
|
};
|
|
49
59
|
export type FileTransform = {
|
|
50
60
|
description?: string;
|
|
51
61
|
jq: string;
|
|
52
62
|
};
|
|
53
|
-
export type InstallConfigStats = {
|
|
54
|
-
name: string;
|
|
55
|
-
type: string;
|
|
56
|
-
finalNewLine: boolean;
|
|
57
|
-
indent?: Indent;
|
|
58
|
-
};
|
package/lib/types/context.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { type Primitive } from '@zokugun/is-it-type';
|
|
2
|
-
import { type AsyncDResult } from '@zokugun/xtry';
|
|
2
|
+
import { type DResult, type AsyncDResult } from '@zokugun/xtry';
|
|
3
|
+
import { type Transform } from '../parsers/jsonc/transform.js';
|
|
3
4
|
import { type BinaryFile } from './binary-file.js';
|
|
4
5
|
import { type Request, type InstallConfig, type PackageConfig, type ArtifactResult, type PackageManifest, type FileTransform } from './config.js';
|
|
5
6
|
import { type Indent, type Format } from './format.js';
|
|
6
|
-
import { type Journey } from './travel.js';
|
|
7
|
+
import { type JourneyPlan, type Route, type Journey } from './travel.js';
|
|
7
8
|
export type ExistingAction = 'merge' | 'overwrite' | 'skip';
|
|
8
9
|
export type MissingAction = 'continue' | 'skip';
|
|
9
10
|
export type RenameAction = {
|
|
@@ -17,6 +18,7 @@ export type Context = {
|
|
|
17
18
|
config: InstallConfig;
|
|
18
19
|
filters: (file: string) => string[] | undefined;
|
|
19
20
|
formats: Format[];
|
|
21
|
+
global: Global;
|
|
20
22
|
incomingName?: string;
|
|
21
23
|
incomingVersion?: string;
|
|
22
24
|
incomingVariant?: string;
|
|
@@ -25,6 +27,7 @@ export type Context = {
|
|
|
25
27
|
incomingPackage?: PackageManifest;
|
|
26
28
|
incomingPath: string;
|
|
27
29
|
mergedTextFiles: TextFile[];
|
|
30
|
+
mode: Mode;
|
|
28
31
|
onExisting: (file: string) => ExistingAction;
|
|
29
32
|
onMissing: (file: string) => MissingAction;
|
|
30
33
|
options: Options;
|
|
@@ -39,7 +42,16 @@ export type Context = {
|
|
|
39
42
|
transformedFiles: TextFile[];
|
|
40
43
|
transforms: (file: string) => FileTransform[] | undefined;
|
|
41
44
|
};
|
|
42
|
-
export
|
|
45
|
+
export declare enum Mode {
|
|
46
|
+
Default = 0,
|
|
47
|
+
Overwritten = 1
|
|
48
|
+
}
|
|
49
|
+
export type Global = {
|
|
50
|
+
journeys: Record<string, JourneyPlan>;
|
|
51
|
+
overwrittenTextFiles: string[];
|
|
52
|
+
routes: Record<string, Route<any>>;
|
|
53
|
+
};
|
|
54
|
+
export type MainFlow = (targetPath: string, incomingPath: string, request: Request, config: InstallConfig, global: Global, options: Options) => AsyncDResult<Context | undefined>;
|
|
43
55
|
export type CommonFlow = (name: string, version: string, variant: string | undefined, branch: string | undefined, incomingPath: string, commonContext: Context) => AsyncDResult<Context | undefined>;
|
|
44
56
|
export type Options = {
|
|
45
57
|
force: boolean;
|
|
@@ -62,3 +74,11 @@ export type TextFile = {
|
|
|
62
74
|
mode?: number;
|
|
63
75
|
name: string;
|
|
64
76
|
};
|
|
77
|
+
export type ParseResult = DResult<{
|
|
78
|
+
data: Record<string, unknown>;
|
|
79
|
+
transform?: Transform;
|
|
80
|
+
}>;
|
|
81
|
+
export type Codec = {
|
|
82
|
+
parse: (data: string) => ParseResult;
|
|
83
|
+
stringify: (data: Record<string, unknown>, transform?: Transform) => string;
|
|
84
|
+
};
|
package/lib/types/context.js
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Mode = void 0;
|
|
4
|
+
var Mode;
|
|
5
|
+
(function (Mode) {
|
|
6
|
+
Mode[Mode["Default"] = 0] = "Default";
|
|
7
|
+
Mode[Mode["Overwritten"] = 1] = "Overwritten";
|
|
8
|
+
})(Mode || (exports.Mode = Mode = {}));
|
package/lib/types/travel.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export declare function buildJourneyPlan(plan: TravelPlan, alias?: string):
|
|
1
|
+
import { type JourneyPlan, type TravelPlan } from '../types/travel.js';
|
|
2
|
+
export declare function buildJourneyPlan(plan: TravelPlan, alias?: string): JourneyPlan;
|
package/lib/utils/build-route.js
CHANGED
|
@@ -18,43 +18,54 @@ function buildRoute(route) {
|
|
|
18
18
|
result = (0, index_js_1.mapSort)(result);
|
|
19
19
|
}
|
|
20
20
|
else {
|
|
21
|
-
return (0, xtry_1.err)(
|
|
21
|
+
return (0, xtry_1.err)(`Cannot build route "${JSON.stringify(route)}"`);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
return (0, xtry_1.ok)(result);
|
|
25
25
|
}
|
|
26
26
|
else if ((0, is_it_type_1.isRecord)(route)) {
|
|
27
|
-
|
|
28
|
-
const { compose: rtCompose, fork: rtFork, mapSort: rtMapSort } = route;
|
|
29
|
-
if (rtCompose) {
|
|
27
|
+
if ((0, is_it_type_1.isRecord)(route.compose)) {
|
|
30
28
|
const map = {};
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (
|
|
34
|
-
|
|
29
|
+
const entries = Object.entries(route.compose);
|
|
30
|
+
for (const [name, route] of entries) {
|
|
31
|
+
if (name === '$$ignore' || name === '$$remove') {
|
|
32
|
+
map[name] = route;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
const result = buildRoute(route);
|
|
36
|
+
if (result.fails) {
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
map[name] = result.value;
|
|
35
40
|
}
|
|
36
|
-
map[name] = result.value;
|
|
37
41
|
}
|
|
38
42
|
return (0, xtry_1.ok)((0, index_js_1.compose)(map));
|
|
39
43
|
}
|
|
40
|
-
else if (
|
|
44
|
+
else if ((0, is_it_type_1.isRecord)(route.fork)) {
|
|
41
45
|
const map = [];
|
|
42
|
-
if (
|
|
43
|
-
const result = buildRoute(
|
|
46
|
+
if (route.fork.array) {
|
|
47
|
+
const result = buildRoute(route.fork.array);
|
|
44
48
|
if (result.fails) {
|
|
45
49
|
return result;
|
|
46
50
|
}
|
|
47
51
|
map.push([Array.isArray, result.value]);
|
|
48
52
|
}
|
|
49
|
-
if (
|
|
50
|
-
const result = buildRoute(
|
|
53
|
+
if (route.fork.object) {
|
|
54
|
+
const result = buildRoute(route.fork.object);
|
|
51
55
|
if (result.fails) {
|
|
52
56
|
return result;
|
|
53
57
|
}
|
|
54
58
|
map.push([is_it_type_1.isRecord, result.value]);
|
|
55
59
|
}
|
|
56
|
-
if (
|
|
57
|
-
const result = buildRoute(
|
|
60
|
+
if (route.fork.default) {
|
|
61
|
+
const result = buildRoute(route.fork.default);
|
|
62
|
+
if (result.fails) {
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
map.push(result.value);
|
|
66
|
+
}
|
|
67
|
+
else if (route.fork.$$default) {
|
|
68
|
+
const result = buildRoute(route.fork.$$default);
|
|
58
69
|
if (result.fails) {
|
|
59
70
|
return result;
|
|
60
71
|
}
|
|
@@ -62,13 +73,27 @@ function buildRoute(route) {
|
|
|
62
73
|
}
|
|
63
74
|
return (0, xtry_1.ok)((0, fork_js_1.fork)(...map));
|
|
64
75
|
}
|
|
65
|
-
else if (
|
|
66
|
-
const result = buildRoute(
|
|
76
|
+
else if (route.json) {
|
|
77
|
+
const result = buildRoute(route.json);
|
|
78
|
+
if (result.fails) {
|
|
79
|
+
return result;
|
|
80
|
+
}
|
|
81
|
+
return (0, xtry_1.ok)((0, index_js_1.json)(result.value));
|
|
82
|
+
}
|
|
83
|
+
else if (route.mapSort) {
|
|
84
|
+
const result = buildRoute(route.mapSort);
|
|
67
85
|
if (result.fails) {
|
|
68
86
|
return result;
|
|
69
87
|
}
|
|
70
88
|
return (0, xtry_1.ok)((0, index_js_1.mapSort)(result.value));
|
|
71
89
|
}
|
|
90
|
+
else if (route.yaml) {
|
|
91
|
+
const result = buildRoute(route.yaml);
|
|
92
|
+
if (result.fails) {
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
return (0, xtry_1.ok)((0, index_js_1.yaml)(result.value));
|
|
96
|
+
}
|
|
72
97
|
}
|
|
73
98
|
else if (route === 'command') {
|
|
74
99
|
return (0, xtry_1.ok)(index_js_2.command);
|
|
@@ -79,14 +104,20 @@ function buildRoute(route) {
|
|
|
79
104
|
else if (route === 'listConcat') {
|
|
80
105
|
return (0, xtry_1.ok)(index_js_2.listConcat);
|
|
81
106
|
}
|
|
107
|
+
else if (route === 'listConcatAfter') {
|
|
108
|
+
return (0, xtry_1.ok)(index_js_2.listConcatAfter);
|
|
109
|
+
}
|
|
82
110
|
else if (route === 'mapConcat') {
|
|
83
111
|
return (0, xtry_1.ok)(index_js_2.mapConcat);
|
|
84
112
|
}
|
|
113
|
+
else if (route === 'mergeDotJs') {
|
|
114
|
+
return (0, xtry_1.ok)(index_js_2.mergeDotJs);
|
|
115
|
+
}
|
|
85
116
|
else if (route === 'overwrite') {
|
|
86
117
|
return (0, xtry_1.ok)(index_js_2.overwrite);
|
|
87
118
|
}
|
|
88
119
|
else if (route === 'primitive') {
|
|
89
120
|
return (0, xtry_1.ok)(index_js_2.primitive);
|
|
90
121
|
}
|
|
91
|
-
return (0, xtry_1.err)(
|
|
122
|
+
return (0, xtry_1.err)(`Cannot build route "${JSON.stringify(route)}"`);
|
|
92
123
|
} // }}}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildTravelPlan = buildTravelPlan;
|
|
4
|
+
// import { fnmatch } from './fnmatch.js';
|
|
4
5
|
function buildTravelPlan(...mappers) {
|
|
5
6
|
return (basename) => {
|
|
6
7
|
const mapper = mappers.find((mapper) => {
|
|
@@ -23,7 +23,7 @@ function mergeAndChains(current, incoming) {
|
|
|
23
23
|
if (!positionalMatch) {
|
|
24
24
|
// Merge by matching prefixes across current segments, append unmatched incoming segments.
|
|
25
25
|
const merged = (0, merge_parts_by_prefix_js_1.mergePartsByPrefix)(currentAnd, incomingAnd);
|
|
26
|
-
return merged.join('
|
|
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;
|
|
@@ -25,7 +25,7 @@ async function mergeCommandRecords(currentCommand, incomingCommand, currentStrin
|
|
|
25
25
|
};
|
|
26
26
|
const currentPrefix = getPrefix(currentInstance.args);
|
|
27
27
|
const incomingPrefix = getPrefix(instance.args);
|
|
28
|
-
const shouldMerge = currentPrefix
|
|
28
|
+
const shouldMerge = (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
31
|
result[name][index] = {
|
|
@@ -5,6 +5,8 @@ const merge_flag_tokens_js_1 = require("./merge-flag-tokens.js");
|
|
|
5
5
|
const split_prefix_and_flags_js_1 = require("./split-prefix-and-flags.js");
|
|
6
6
|
function mergePartsByPrefix(currentParts, incomingParts) {
|
|
7
7
|
const result = [...currentParts];
|
|
8
|
+
// Track the index of the last position where we merged or inserted an incoming part
|
|
9
|
+
let lastIndex = null;
|
|
8
10
|
for (const incomingPart of incomingParts) {
|
|
9
11
|
const incomingPrefix = (0, split_prefix_and_flags_js_1.splitPrefixAndFlags)(incomingPart);
|
|
10
12
|
let merged = false;
|
|
@@ -14,11 +16,20 @@ function mergePartsByPrefix(currentParts, incomingParts) {
|
|
|
14
16
|
const mergedFlags = (0, merge_flag_tokens_js_1.mergeFlagTokens)(currentPrefix.flags, incomingPrefix.flags);
|
|
15
17
|
result[k] = currentPrefix.prefix + (mergedFlags.length > 0 ? ' ' + mergedFlags.join(' ') : '');
|
|
16
18
|
merged = true;
|
|
19
|
+
lastIndex = k;
|
|
17
20
|
break;
|
|
18
21
|
}
|
|
19
22
|
}
|
|
20
23
|
if (!merged) {
|
|
21
|
-
|
|
24
|
+
// If we previously merged or inserted, place the new incoming part immediately after that position
|
|
25
|
+
if (lastIndex === null) {
|
|
26
|
+
result.push(incomingPart);
|
|
27
|
+
lastIndex = result.length - 1;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
result.splice(lastIndex + 1, 0, incomingPart);
|
|
31
|
+
lastIndex += 1;
|
|
32
|
+
}
|
|
22
33
|
}
|
|
23
34
|
}
|
|
24
35
|
return result;
|