rhachet-roles-ehmpathy 1.3.0 → 1.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/dist/contract/sdk/index.d.ts +1 -0
- package/dist/contract/sdk/index.js +3 -1
- package/dist/contract/sdk/index.js.map +1 -1
- package/dist/logic/artifact/genStepArtDel.d.ts +17 -0
- package/dist/logic/artifact/genStepArtDel.js +29 -0
- package/dist/logic/artifact/genStepArtDel.js.map +1 -0
- package/dist/logic/artifact/setSkillOutputSrc.d.ts +32 -0
- package/dist/logic/artifact/setSkillOutputSrc.js +99 -0
- package/dist/logic/artifact/setSkillOutputSrc.js.map +1 -0
- package/dist/logic/hooks/decodeDocOutputPath.d.ts +21 -0
- package/dist/logic/hooks/decodeDocOutputPath.js +57 -0
- package/dist/logic/hooks/decodeDocOutputPath.js.map +1 -0
- package/dist/logic/hooks/decodeDocOutputPath.test.d.ts +1 -0
- package/dist/logic/hooks/decodeDocOutputPath.test.js +146 -0
- package/dist/logic/hooks/decodeDocOutputPath.test.js.map +1 -0
- package/dist/logic/hooks/execTranslateDocOutputPath.d.ts +20 -0
- package/dist/logic/hooks/execTranslateDocOutputPath.js +80 -0
- package/dist/logic/hooks/execTranslateDocOutputPath.js.map +1 -0
- package/dist/logic/hooks/execTranslateDocOutputPath.test.d.ts +1 -0
- package/dist/logic/hooks/execTranslateDocOutputPath.test.js +409 -0
- package/dist/logic/hooks/execTranslateDocOutputPath.test.js.map +1 -0
- package/dist/logic/hooks/getInvokeHooks.d.ts +2 -0
- package/dist/logic/hooks/getInvokeHooks.js +15 -0
- package/dist/logic/hooks/getInvokeHooks.js.map +1 -0
- package/dist/logic/hooks/relateDocOutputPath.d.ts +10 -0
- package/dist/logic/hooks/relateDocOutputPath.js +45 -0
- package/dist/logic/hooks/relateDocOutputPath.js.map +1 -0
- package/dist/logic/hooks/relateDocOutputPath.test.d.ts +1 -0
- package/dist/logic/hooks/relateDocOutputPath.test.js +111 -0
- package/dist/logic/hooks/relateDocOutputPath.test.js.map +1 -0
- package/dist/logic/roles/bhrain/.briefs/knowledge/kno501.doc.enbrief.catalog.structure1.[lesson].template.md +3 -3
- package/dist/logic/roles/bhrain/brief.articulate/stepArticulate.skill.js +3 -0
- package/dist/logic/roles/bhrain/brief.articulate/stepArticulate.skill.js.map +1 -1
- package/dist/logic/roles/bhrain/brief.catalogize/stepCatalogize.skill.js +8 -2
- package/dist/logic/roles/bhrain/brief.catalogize/stepCatalogize.skill.js.map +1 -1
- package/dist/logic/roles/bhrain/getBhrainBrief.Options.codegen.d.ts +1 -1
- package/dist/logic/roles/bhrain/getBhrainBrief.Options.codegen.js +58 -36
- package/dist/logic/roles/bhrain/getBhrainBrief.Options.codegen.js.map +1 -1
- package/dist/logic/roles/bhrain/getBhrainRole.js +6 -0
- package/dist/logic/roles/bhrain/getBhrainRole.js.map +1 -1
- package/dist/logic/roles/bhrain/khue.instantiate/stepInstantiate.skill.js +22 -2
- package/dist/logic/roles/bhrain/khue.instantiate/stepInstantiate.skill.js.map +1 -1
- package/dist/logic/roles/ecologist/getEcologistBrief.Options.codegen.d.ts +1 -1
- package/dist/logic/roles/ecologist/getEcologistBrief.Options.codegen.js +14 -14
- package/dist/logic/roles/ecologist/getEcologistBrief.Options.codegen.js.map +1 -1
- package/dist/logic/roles/getRoleRegistry.js +2 -0
- package/dist/logic/roles/getRoleRegistry.js.map +1 -1
- package/dist/logic/roles/mechanic/.briefs/terms/plan.exec_vs_apply.md +45 -0
- package/dist/logic/roles/mechanic/getMechanicBrief.Options.codegen.d.ts +1 -1
- package/dist/logic/roles/mechanic/getMechanicBrief.Options.codegen.js +1 -0
- package/dist/logic/roles/mechanic/getMechanicBrief.Options.codegen.js.map +1 -1
- package/dist/logic/roles/terminal.commander/command.exec/stepExecCommand.d.ts +42 -0
- package/dist/logic/roles/terminal.commander/command.exec/stepExecCommand.integration.test.d.ts +1 -0
- package/dist/logic/roles/terminal.commander/command.exec/stepExecCommand.integration.test.js +76 -0
- package/dist/logic/roles/terminal.commander/command.exec/stepExecCommand.integration.test.js.map +1 -0
- package/dist/logic/roles/terminal.commander/command.exec/stepExecCommand.js +126 -0
- package/dist/logic/roles/terminal.commander/command.exec/stepExecCommand.js.map +1 -0
- package/dist/logic/roles/terminal.commander/command.exec/stepExecCommand.skill.d.ts +12 -0
- package/dist/logic/roles/terminal.commander/command.exec/stepExecCommand.skill.js +69 -0
- package/dist/logic/roles/terminal.commander/command.exec/stepExecCommand.skill.js.map +1 -0
- package/dist/logic/roles/terminal.commander/command.plan/stepPlanCommand.d.ts +54 -0
- package/dist/logic/roles/terminal.commander/command.plan/stepPlanCommand.integration.test.d.ts +1 -0
- package/dist/logic/roles/terminal.commander/command.plan/stepPlanCommand.integration.test.js +97 -0
- package/dist/logic/roles/terminal.commander/command.plan/stepPlanCommand.integration.test.js.map +1 -0
- package/dist/logic/roles/terminal.commander/command.plan/stepPlanCommand.js +68 -0
- package/dist/logic/roles/terminal.commander/command.plan/stepPlanCommand.js.map +1 -0
- package/dist/logic/roles/terminal.commander/command.plan/stepPlanCommand.skill.d.ts +28 -0
- package/dist/logic/roles/terminal.commander/command.plan/stepPlanCommand.skill.js +124 -0
- package/dist/logic/roles/terminal.commander/command.plan/stepPlanCommand.skill.js.map +1 -0
- package/dist/logic/roles/terminal.commander/getCommanderRole.d.ts +2 -0
- package/dist/logic/roles/terminal.commander/getCommanderRole.js +35 -0
- package/dist/logic/roles/terminal.commander/getCommanderRole.js.map +1 -0
- package/package.json +2 -2
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getRoleRegistry = void 0;
|
|
3
|
+
exports.getInvokeHooks = exports.getRoleRegistry = void 0;
|
|
4
4
|
var getRoleRegistry_1 = require("../../logic/roles/getRoleRegistry");
|
|
5
5
|
Object.defineProperty(exports, "getRoleRegistry", { enumerable: true, get: function () { return getRoleRegistry_1.getRoleRegistry; } });
|
|
6
|
+
var getInvokeHooks_1 = require("../../logic/hooks/getInvokeHooks");
|
|
7
|
+
Object.defineProperty(exports, "getInvokeHooks", { enumerable: true, get: function () { return getInvokeHooks_1.getInvokeHooks; } });
|
|
6
8
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/contract/sdk/index.ts"],"names":[],"mappings":";;;AAAA,qEAAoE;AAA3D,kHAAA,eAAe,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/contract/sdk/index.ts"],"names":[],"mappings":";;;AAAA,qEAAoE;AAA3D,kHAAA,eAAe,OAAA;AACxB,mEAAkE;AAAzD,gHAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { GStitcher, StitchStepCompute, Threads, RoleContext } from 'rhachet';
|
|
2
|
+
import { Artifact } from 'rhachet-artifact';
|
|
3
|
+
import { GitFile } from 'rhachet-artifact-git';
|
|
4
|
+
/**
|
|
5
|
+
* .what = creates a compute step that deletes the contents of an artifact
|
|
6
|
+
* .why = allows composer routes to purge the state of any artifact
|
|
7
|
+
*/
|
|
8
|
+
export declare const genStepArtDel: <TStitchee extends string, TArtee extends string, TThreads extends Threads<{ [K in TStitchee]: RoleContext<K, {
|
|
9
|
+
art: { [P in TArtee]: Artifact<typeof GitFile, string>; };
|
|
10
|
+
}>; }>>({ stitchee, artee, mode, ...input }: {
|
|
11
|
+
stitchee: TStitchee;
|
|
12
|
+
artee: TArtee;
|
|
13
|
+
mode?: 'delete';
|
|
14
|
+
condition?: ({ threads }: {
|
|
15
|
+
threads: TThreads;
|
|
16
|
+
}) => 'SKIP' | 'EXEC';
|
|
17
|
+
}) => StitchStepCompute<GStitcher<TThreads, import("simple-log-methods").ContextLogTrail & import("rhachet").ContextStitchTrail, "SKIP" | "EXEC">>;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.genStepArtDel = void 0;
|
|
4
|
+
const rhachet_1 = require("rhachet");
|
|
5
|
+
const rhachet_artifact_git_1 = require("rhachet-artifact-git");
|
|
6
|
+
/**
|
|
7
|
+
* .what = creates a compute step that deletes the contents of an artifact
|
|
8
|
+
* .why = allows composer routes to purge the state of any artifact
|
|
9
|
+
*/
|
|
10
|
+
const genStepArtDel = ({ stitchee, artee, mode = 'delete', ...input }) => new rhachet_1.StitchStepCompute({
|
|
11
|
+
form: 'COMPUTE',
|
|
12
|
+
readme: null,
|
|
13
|
+
slug: `[${stitchee}]<artifact:del>[${artee}]`,
|
|
14
|
+
stitchee,
|
|
15
|
+
invoke: async ({ threads }) => {
|
|
16
|
+
const thread = threads[stitchee];
|
|
17
|
+
const artifact = thread.context.stash.art[artee];
|
|
18
|
+
// evaluate the condition, if one exists
|
|
19
|
+
const decision = input.condition?.({ threads }) ?? 'EXEC';
|
|
20
|
+
if (decision === 'SKIP')
|
|
21
|
+
return { input: { mode, artifact }, output: 'SKIP' };
|
|
22
|
+
// otherwise, execute the delete
|
|
23
|
+
await artifact.del();
|
|
24
|
+
console.log(`🎨️ art.${mode}ed, impacted ${artifact.ref.uri.replace(await (0, rhachet_artifact_git_1.getGitRepoRoot)({ from: process.cwd() }), '')}\n`);
|
|
25
|
+
return { input: { mode, artifact }, output: 'EXEC' };
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
exports.genStepArtDel = genStepArtDel;
|
|
29
|
+
//# sourceMappingURL=genStepArtDel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"genStepArtDel.js","sourceRoot":"","sources":["../../../src/logic/artifact/genStepArtDel.ts"],"names":[],"mappings":";;;AAAA,qCAMiB;AAEjB,+DAA+D;AAE/D;;;GAGG;AACI,MAAM,aAAa,GAAG,CAa3B,EACA,QAAQ,EACR,KAAK,EACL,IAAI,GAAG,QAAQ,EACf,GAAG,KAAK,EAMT,EAAE,EAAE,CACH,IAAI,2BAAiB,CAEnB;IACA,IAAI,EAAE,SAAS;IACf,MAAM,EAAE,IAAI;IACZ,IAAI,EAAE,IAAI,QAAQ,mBAAmB,KAAK,GAAG;IAC7C,QAAQ;IACR,MAAM,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;QAC5B,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAS9B,CAAC;QACF,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAEjD,wCAAwC;QACxC,MAAM,QAAQ,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,IAAI,MAAM,CAAC;QAC1D,IAAI,QAAQ,KAAK,MAAM;YACrB,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;QAEvD,gCAAgC;QAChC,MAAM,QAAQ,CAAC,GAAG,EAAE,CAAC;QACrB,OAAO,CAAC,GAAG,CACT,YAAY,IAAI,gBAAgB,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,OAAO,CACtD,MAAM,IAAA,qCAAc,EAAC,EAAE,IAAI,EAAE,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,EAC7C,EAAE,CACH,IAAI,CACN,CAAC;QACF,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IACvD,CAAC;CACF,CAAC,CAAC;AA3DQ,QAAA,aAAa,iBA2DrB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { InvokeOpts } from 'rhachet';
|
|
2
|
+
/**
|
|
3
|
+
* .what = saves an artifact of the .src that created an output file
|
|
4
|
+
* .why =
|
|
5
|
+
* - a .src file helps callers trace the sequence that lead to some output. it makes outputs easier to repeat, since you always have the exact input at hand, for record
|
|
6
|
+
*/
|
|
7
|
+
export declare const setSkillOutputSrc: (input: {
|
|
8
|
+
skillUri: string;
|
|
9
|
+
opts: InvokeOpts<{
|
|
10
|
+
ask: string;
|
|
11
|
+
output: string;
|
|
12
|
+
}>;
|
|
13
|
+
}) => Promise<import("rhachet-artifact-git").GitFile>;
|
|
14
|
+
/**
|
|
15
|
+
* detect the trailing extension (with the dot), or null if none
|
|
16
|
+
*/
|
|
17
|
+
export declare const detectOutputExtension: (output: string) => string | null;
|
|
18
|
+
/**
|
|
19
|
+
* .what = removes the attempt value, regardless of extension
|
|
20
|
+
* - if there's a real extension: strip ".iN" before it
|
|
21
|
+
* - if no real extension but ends with ".iN": strip it
|
|
22
|
+
*/
|
|
23
|
+
export declare const asOutputWithoutAttempts: (output: string) => string;
|
|
24
|
+
/**
|
|
25
|
+
* .what = replaces the extension of an output file
|
|
26
|
+
* - if extension is real: replace it
|
|
27
|
+
* - if extension is ".iN": append new extension instead of replacing
|
|
28
|
+
*/
|
|
29
|
+
export declare const asOutputWithExtension: ({ output, extension, }: {
|
|
30
|
+
output: string;
|
|
31
|
+
extension: `.${string}`;
|
|
32
|
+
}) => string;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.asOutputWithExtension = exports.asOutputWithoutAttempts = exports.detectOutputExtension = exports.setSkillOutputSrc = void 0;
|
|
4
|
+
const node_path_1 = require("node:path");
|
|
5
|
+
const rhachet_artifact_git_1 = require("rhachet-artifact-git");
|
|
6
|
+
const type_fns_1 = require("type-fns");
|
|
7
|
+
/**
|
|
8
|
+
* .what = saves an artifact of the .src that created an output file
|
|
9
|
+
* .why =
|
|
10
|
+
* - a .src file helps callers trace the sequence that lead to some output. it makes outputs easier to repeat, since you always have the exact input at hand, for record
|
|
11
|
+
*/
|
|
12
|
+
const setSkillOutputSrc = async (input) => await (0, rhachet_artifact_git_1.genArtifactGitFile)({
|
|
13
|
+
uri: (0, exports.asOutputWithExtension)({
|
|
14
|
+
output: (0, exports.asOutputWithoutAttempts)(input.opts.output),
|
|
15
|
+
extension: '.src',
|
|
16
|
+
}),
|
|
17
|
+
}, { versions: true }).set({
|
|
18
|
+
content: castInvokeOptsToSrcFileContents(input),
|
|
19
|
+
});
|
|
20
|
+
exports.setSkillOutputSrc = setSkillOutputSrc;
|
|
21
|
+
/**
|
|
22
|
+
* .what = a procedure to cast from invoke opts into .src file contents
|
|
23
|
+
*/
|
|
24
|
+
const castInvokeOptsToSrcFileContents = (input) => {
|
|
25
|
+
// detect the attempt number
|
|
26
|
+
const attempts = process.env.RHACHET_ATTEMPTS ?? null;
|
|
27
|
+
const output = (0, exports.asOutputWithoutAttempts)(input.opts.output);
|
|
28
|
+
// rebuild the request
|
|
29
|
+
const sections = [
|
|
30
|
+
`
|
|
31
|
+
ASK=$(cat <<'ASK_EOF'
|
|
32
|
+
|
|
33
|
+
${input.opts.ask}
|
|
34
|
+
|
|
35
|
+
ASK_EOF
|
|
36
|
+
)
|
|
37
|
+
`.trim(),
|
|
38
|
+
`
|
|
39
|
+
npx rhachet act -s ${input.skillUri} \\
|
|
40
|
+
`.trim(),
|
|
41
|
+
attempts
|
|
42
|
+
? `
|
|
43
|
+
--attempts ${attempts} \\
|
|
44
|
+
`.trim()
|
|
45
|
+
: null,
|
|
46
|
+
`
|
|
47
|
+
--output '${output}' \\
|
|
48
|
+
`.trim(),
|
|
49
|
+
input.opts.references
|
|
50
|
+
? `
|
|
51
|
+
--references '${input.opts.references}' \\
|
|
52
|
+
`.trim()
|
|
53
|
+
: null,
|
|
54
|
+
...Object.entries((0, type_fns_1.omit)(input.opts, ['attempts', 'ask', 'output', 'references'])).map(([key, value]) => `
|
|
55
|
+
--${key} '${value}' \\
|
|
56
|
+
`.trim()),
|
|
57
|
+
`
|
|
58
|
+
--ask "$ASK";
|
|
59
|
+
`.trim(),
|
|
60
|
+
].filter(type_fns_1.isPresent);
|
|
61
|
+
return sections.join('\n');
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* detect the trailing extension (with the dot), or null if none
|
|
65
|
+
*/
|
|
66
|
+
const detectOutputExtension = (output) => {
|
|
67
|
+
const ext = (0, node_path_1.extname)(output);
|
|
68
|
+
return ext || null;
|
|
69
|
+
};
|
|
70
|
+
exports.detectOutputExtension = detectOutputExtension;
|
|
71
|
+
/**
|
|
72
|
+
* .what = removes the attempt value, regardless of extension
|
|
73
|
+
* - if there's a real extension: strip ".iN" before it
|
|
74
|
+
* - if no real extension but ends with ".iN": strip it
|
|
75
|
+
*/
|
|
76
|
+
const asOutputWithoutAttempts = (output) => {
|
|
77
|
+
const ext = (0, exports.detectOutputExtension)(output);
|
|
78
|
+
// case: has real extension (like .md, .json, etc.)
|
|
79
|
+
if (ext && !/\.i\d+$/.test(ext))
|
|
80
|
+
return output.replace(new RegExp(`\\.i\\d+${ext}$`), ext);
|
|
81
|
+
// case: no extension, or extension is itself ".iN"
|
|
82
|
+
return output.replace(/\.i\d+$/, '');
|
|
83
|
+
};
|
|
84
|
+
exports.asOutputWithoutAttempts = asOutputWithoutAttempts;
|
|
85
|
+
/**
|
|
86
|
+
* .what = replaces the extension of an output file
|
|
87
|
+
* - if extension is real: replace it
|
|
88
|
+
* - if extension is ".iN": append new extension instead of replacing
|
|
89
|
+
*/
|
|
90
|
+
const asOutputWithExtension = ({ output, extension, }) => {
|
|
91
|
+
const ext = (0, exports.detectOutputExtension)(output);
|
|
92
|
+
// if no original extension, just append this new one
|
|
93
|
+
if (!ext)
|
|
94
|
+
return output + extension;
|
|
95
|
+
// otherwise, replace the extension
|
|
96
|
+
return output.slice(0, -ext.length) + extension;
|
|
97
|
+
};
|
|
98
|
+
exports.asOutputWithExtension = asOutputWithExtension;
|
|
99
|
+
//# sourceMappingURL=setSkillOutputSrc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setSkillOutputSrc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,GAAG,SAAS,CAAC;IAEpC,mCAAmC;IACnC,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;AAClD,CAAC,CAAC;AAdW,QAAA,qBAAqB,yBAchC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
type DocVersions = {
|
|
2
|
+
variant: number | null;
|
|
3
|
+
instance: number | null;
|
|
4
|
+
};
|
|
5
|
+
type Decoded = {
|
|
6
|
+
prefix: string;
|
|
7
|
+
doctype: string;
|
|
8
|
+
versions: DocVersions;
|
|
9
|
+
extension: string | null;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* parses a doc output path like:
|
|
13
|
+
* ...persp_pro.v1i2.[stories].v1.i3.md
|
|
14
|
+
* into:
|
|
15
|
+
* - doctype: "stories"
|
|
16
|
+
* - prefix: "...persp_pro.v1i2."
|
|
17
|
+
* - versions: { variant: 1, instance: 3 }
|
|
18
|
+
* - extension: "md"
|
|
19
|
+
*/
|
|
20
|
+
export declare const decodeDocOutputPath: (inputPath: string) => Decoded;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decodeDocOutputPath = void 0;
|
|
4
|
+
const helpful_errors_1 = require("helpful-errors");
|
|
5
|
+
/**
|
|
6
|
+
* parses a doc output path like:
|
|
7
|
+
* ...persp_pro.v1i2.[stories].v1.i3.md
|
|
8
|
+
* into:
|
|
9
|
+
* - doctype: "stories"
|
|
10
|
+
* - prefix: "...persp_pro.v1i2."
|
|
11
|
+
* - versions: { variant: 1, instance: 3 }
|
|
12
|
+
* - extension: "md"
|
|
13
|
+
*/
|
|
14
|
+
const decodeDocOutputPath = (inputPath) => {
|
|
15
|
+
// find the LAST [doctype], where [doctype] cant be before a `/`
|
|
16
|
+
const lastDoctypeMatch = inputPath.match(/^(.*)\[(\w+)\]([^/]*)$/i);
|
|
17
|
+
if (!lastDoctypeMatch) {
|
|
18
|
+
throw new helpful_errors_1.BadRequestError('could not find any [doctype] in referenced path', { path: inputPath });
|
|
19
|
+
}
|
|
20
|
+
const beforeAndDot = lastDoctypeMatch[1]; // should end with the dot before [doctype], e.g., "...v1i2."
|
|
21
|
+
const doctype = lastDoctypeMatch[2]; // inside the brackets
|
|
22
|
+
const after = lastDoctypeMatch[3] || ''; // tail after the closing ]
|
|
23
|
+
// ensure prefix ends exactly before the bracket (without dot suffix, if any)
|
|
24
|
+
const prefix = beforeAndDot.endsWith('.')
|
|
25
|
+
? beforeAndDot.slice(0, -1)
|
|
26
|
+
: beforeAndDot;
|
|
27
|
+
// parse tail tokens after the closing bracket, e.g. ".v1.i3.md", "._.md", ".md", etc.
|
|
28
|
+
// we’ll split on '.' and ignore empties so ".v1.i3.md" -> ["v1","i3","md"]
|
|
29
|
+
const tokens = after.split('.').filter(Boolean);
|
|
30
|
+
let variant = null;
|
|
31
|
+
let instance = null;
|
|
32
|
+
let extension = null;
|
|
33
|
+
for (const t of tokens) {
|
|
34
|
+
if (/^v\d+$/i.test(t)) {
|
|
35
|
+
variant = parseInt(t.slice(1), 10);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (/^i\d+$/i.test(t)) {
|
|
39
|
+
instance = parseInt(t.slice(1), 10);
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (t === '_') {
|
|
43
|
+
// explicit “no attempt” marker – ignore for versions; not an extension
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
// anything else we treat as the extension; if multiple remain, the last wins
|
|
47
|
+
extension = t;
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
prefix,
|
|
51
|
+
doctype,
|
|
52
|
+
versions: { variant, instance },
|
|
53
|
+
extension,
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
exports.decodeDocOutputPath = decodeDocOutputPath;
|
|
57
|
+
//# sourceMappingURL=decodeDocOutputPath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decodeDocOutputPath.js","sourceRoot":"","sources":["../../../src/logic/hooks/decodeDocOutputPath.ts"],"names":[],"mappings":";;;AAAA,mDAAiD;AAUjD;;;;;;;;GAQG;AACI,MAAM,mBAAmB,GAAG,CAAC,SAAiB,EAAW,EAAE;IAChE,gEAAgE;IAChE,MAAM,gBAAgB,GAAG,SAAS,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;IACpE,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,MAAM,IAAI,gCAAe,CACvB,iDAAiD,EACjD,EAAE,IAAI,EAAE,SAAS,EAAE,CACpB,CAAC;IACJ,CAAC;IAED,MAAM,YAAY,GAAG,gBAAgB,CAAC,CAAC,CAAE,CAAC,CAAC,6DAA6D;IACxG,MAAM,OAAO,GAAG,gBAAgB,CAAC,CAAC,CAAE,CAAC,CAAC,sBAAsB;IAC5D,MAAM,KAAK,GAAG,gBAAgB,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,2BAA2B;IAEpE,6EAA6E;IAC7E,MAAM,MAAM,GAAG,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC;QACvC,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC3B,CAAC,CAAC,YAAY,CAAC;IAEjB,sFAAsF;IACtF,2EAA2E;IAC3E,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAEhD,IAAI,OAAO,GAAkB,IAAI,CAAC;IAClC,IAAI,QAAQ,GAAkB,IAAI,CAAC;IACnC,IAAI,SAAS,GAAkB,IAAI,CAAC;IAEpC,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;QACvB,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;YACtB,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACnC,SAAS;QACX,CAAC;QACD,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;YACtB,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACpC,SAAS;QACX,CAAC;QACD,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;YACd,uEAAuE;YACvE,SAAS;QACX,CAAC;QACD,6EAA6E;QAC7E,SAAS,GAAG,CAAC,CAAC;IAChB,CAAC;IAED,OAAO;QACL,MAAM;QACN,OAAO;QACP,QAAQ,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE;QAC/B,SAAS;KACV,CAAC;AACJ,CAAC,CAAC;AAlDW,QAAA,mBAAmB,uBAkD9B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const helpful_errors_1 = require("helpful-errors");
|
|
4
|
+
const test_fns_1 = require("test-fns");
|
|
5
|
+
const decodeDocOutputPath_1 = require("./decodeDocOutputPath");
|
|
6
|
+
describe('decodeDocOutputPath (only considers [doctype]s after the last "/")', () => {
|
|
7
|
+
(0, test_fns_1.given)('a typical path with [doctype] after the last slash', () => {
|
|
8
|
+
const input = 'src/product/protools/tool.routecal/step_5.stories/step_1.translate/' +
|
|
9
|
+
'provider.plumber_pete.customer_needs.scene_6.loyalty_build.persp_pro.v1i2.[stories].v1.i3.md';
|
|
10
|
+
(0, test_fns_1.when)('decoding the path', () => {
|
|
11
|
+
const result = (0, decodeDocOutputPath_1.decodeDocOutputPath)(input);
|
|
12
|
+
(0, test_fns_1.then)('it returns the expected fields', () => {
|
|
13
|
+
expect(result).toEqual({
|
|
14
|
+
doctype: 'stories',
|
|
15
|
+
prefix: 'src/product/protools/tool.routecal/step_5.stories/step_1.translate/' +
|
|
16
|
+
'provider.plumber_pete.customer_needs.scene_6.loyalty_build.persp_pro.v1i2',
|
|
17
|
+
versions: { variant: 1, instance: 3 },
|
|
18
|
+
extension: 'md',
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
(0, test_fns_1.given)('multiple [doctype] segments exists, but only those after the last slash count', () => {
|
|
24
|
+
// two doctypes before the last slash, one after it
|
|
25
|
+
const input = 'root/alpha.[draft].beta/gamma.[notes].delta/' + // ignored doctypes (before last slash)
|
|
26
|
+
'omega.v2.[stories].i7.md'; // the only considered doctype
|
|
27
|
+
(0, test_fns_1.when)('decoding the path', () => {
|
|
28
|
+
const result = (0, decodeDocOutputPath_1.decodeDocOutputPath)(input);
|
|
29
|
+
(0, test_fns_1.then)('it uses the [doctype] after the last slash', () => {
|
|
30
|
+
expect(result.doctype).toBe('stories');
|
|
31
|
+
expect(result.prefix).toBe('root/alpha.[draft].beta/gamma.[notes].delta/omega.v2');
|
|
32
|
+
expect(result.versions).toEqual({ variant: null, instance: 7 });
|
|
33
|
+
expect(result.extension).toBe('md');
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
(0, test_fns_1.given)('no [doctype] appears after the last slash', () => {
|
|
38
|
+
const input = 'a/b/c/topic.[stories]/omega.v2.i7.md'; // [stories] is before the last slash
|
|
39
|
+
(0, test_fns_1.when)('decoding the path', () => {
|
|
40
|
+
const err = (0, test_fns_1.getError)(() => (0, decodeDocOutputPath_1.decodeDocOutputPath)(input));
|
|
41
|
+
(0, test_fns_1.then)('it throws a BadRequestError', () => {
|
|
42
|
+
expect(err).toBeInstanceOf(helpful_errors_1.BadRequestError);
|
|
43
|
+
expect(err.message).toMatch(/could not find any \[doctype]/i);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
(0, test_fns_1.given)('multiple [doctype]s appear after the last slash (take the last one)', () => {
|
|
48
|
+
const input = 'a/b/c/topic.[draft].x.[stories].v1.md'; // both doctypes after last slash
|
|
49
|
+
(0, test_fns_1.when)('decoding the path', () => {
|
|
50
|
+
const result = (0, decodeDocOutputPath_1.decodeDocOutputPath)(input);
|
|
51
|
+
(0, test_fns_1.then)('it picks the last [doctype] after the last slash', () => {
|
|
52
|
+
expect(result).toEqual({
|
|
53
|
+
doctype: 'stories',
|
|
54
|
+
prefix: 'a/b/c/topic.[draft].x',
|
|
55
|
+
versions: { variant: 1, instance: null },
|
|
56
|
+
extension: 'md',
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
(0, test_fns_1.given)('a path with only variant after the doctype (post-last-slash)', () => {
|
|
62
|
+
const input = 'x/y/z/foo.[story].v12.md';
|
|
63
|
+
(0, test_fns_1.when)('decoding the path', () => {
|
|
64
|
+
const result = (0, decodeDocOutputPath_1.decodeDocOutputPath)(input);
|
|
65
|
+
(0, test_fns_1.then)('it parses variant and leaves instance null', () => {
|
|
66
|
+
expect(result).toEqual({
|
|
67
|
+
doctype: 'story',
|
|
68
|
+
prefix: 'x/y/z/foo',
|
|
69
|
+
versions: { variant: 12, instance: null },
|
|
70
|
+
extension: 'md',
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
(0, test_fns_1.given)('a path with only instance after the doctype (post-last-slash)', () => {
|
|
76
|
+
const input = 'x/y/z/foo.[story].i9.md';
|
|
77
|
+
(0, test_fns_1.when)('decoding the path', () => {
|
|
78
|
+
const result = (0, decodeDocOutputPath_1.decodeDocOutputPath)(input);
|
|
79
|
+
(0, test_fns_1.then)('it parses instance and leaves variant null', () => {
|
|
80
|
+
expect(result).toEqual({
|
|
81
|
+
doctype: 'story',
|
|
82
|
+
prefix: 'x/y/z/foo',
|
|
83
|
+
versions: { variant: null, instance: 9 },
|
|
84
|
+
extension: 'md',
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
(0, test_fns_1.given)('a path with explicit no-attempt marker "._" and an extension (post-last-slash)', () => {
|
|
90
|
+
const input = 'a/b/c/topic.[stories]._.md';
|
|
91
|
+
(0, test_fns_1.when)('decoding the path', () => {
|
|
92
|
+
const result = (0, decodeDocOutputPath_1.decodeDocOutputPath)(input);
|
|
93
|
+
(0, test_fns_1.then)('it ignores "_" for versions and still captures the extension', () => {
|
|
94
|
+
expect(result).toEqual({
|
|
95
|
+
doctype: 'stories',
|
|
96
|
+
prefix: 'a/b/c/topic',
|
|
97
|
+
versions: { variant: null, instance: null },
|
|
98
|
+
extension: 'md',
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
(0, test_fns_1.given)('a path with no extension after the doctype and versions (post-last-slash)', () => {
|
|
104
|
+
const input = 'a/b/c/topic.[stories].v3.i2';
|
|
105
|
+
(0, test_fns_1.when)('decoding the path', () => {
|
|
106
|
+
const result = (0, decodeDocOutputPath_1.decodeDocOutputPath)(input);
|
|
107
|
+
(0, test_fns_1.then)('it sets extension to null', () => {
|
|
108
|
+
expect(result).toEqual({
|
|
109
|
+
doctype: 'stories',
|
|
110
|
+
prefix: 'a/b/c/topic',
|
|
111
|
+
versions: { variant: 3, instance: 2 },
|
|
112
|
+
extension: null,
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
(0, test_fns_1.given)('a path with only an extension immediately after the doctype (post-last-slash)', () => {
|
|
118
|
+
const input = 'a/b/c/topic.[stories].md';
|
|
119
|
+
(0, test_fns_1.when)('decoding the path', () => {
|
|
120
|
+
const result = (0, decodeDocOutputPath_1.decodeDocOutputPath)(input);
|
|
121
|
+
(0, test_fns_1.then)('it returns no versions and the extension', () => {
|
|
122
|
+
expect(result).toEqual({
|
|
123
|
+
doctype: 'stories',
|
|
124
|
+
prefix: 'a/b/c/topic',
|
|
125
|
+
versions: { variant: null, instance: null },
|
|
126
|
+
extension: 'md',
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
(0, test_fns_1.given)('case-insensitive markers still parse (post-last-slash)', () => {
|
|
132
|
+
const input = 'a/b/c/topic.[STORIES].V10.I4.MD';
|
|
133
|
+
(0, test_fns_1.when)('decoding the path', () => {
|
|
134
|
+
const result = (0, decodeDocOutputPath_1.decodeDocOutputPath)(input);
|
|
135
|
+
(0, test_fns_1.then)('it parses regardless of case', () => {
|
|
136
|
+
expect(result).toEqual({
|
|
137
|
+
doctype: 'STORIES',
|
|
138
|
+
prefix: 'a/b/c/topic',
|
|
139
|
+
versions: { variant: 10, instance: 4 },
|
|
140
|
+
extension: 'MD',
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
//# sourceMappingURL=decodeDocOutputPath.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decodeDocOutputPath.test.js","sourceRoot":"","sources":["../../../src/logic/hooks/decodeDocOutputPath.test.ts"],"names":[],"mappings":";;AAAA,mDAAiD;AACjD,uCAAuD;AAEvD,+DAA4D;AAE5D,QAAQ,CAAC,oEAAoE,EAAE,GAAG,EAAE;IAClF,IAAA,gBAAK,EAAC,oDAAoD,EAAE,GAAG,EAAE;QAC/D,MAAM,KAAK,GACT,qEAAqE;YACrE,8FAA8F,CAAC;QAEjG,IAAA,eAAI,EAAC,mBAAmB,EAAE,GAAG,EAAE;YAC7B,MAAM,MAAM,GAAG,IAAA,yCAAmB,EAAC,KAAK,CAAC,CAAC;YAE1C,IAAA,eAAI,EAAC,gCAAgC,EAAE,GAAG,EAAE;gBAC1C,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;oBACrB,OAAO,EAAE,SAAS;oBAClB,MAAM,EACJ,qEAAqE;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B,MAAM,MAAM,GAAG,IAAA,yCAAmB,EAAC,KAAK,CAAC,CAAC;YAE1C,IAAA,eAAI,EAAC,8BAA8B,EAAE,GAAG,EAAE;gBACxC,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;oBACrB,OAAO,EAAE,SAAS;oBAClB,MAAM,EAAE,aAAa;oBACrB,QAAQ,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE;oBACtC,SAAS,EAAE,IAAI;iBAChB,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ContextLogTrail } from 'as-procedure';
|
|
2
|
+
import { InvokeOpts } from 'rhachet';
|
|
3
|
+
/**
|
|
4
|
+
* .what = execute the translation of a doc output path
|
|
5
|
+
* .why =
|
|
6
|
+
* - given @translate(references.1)
|
|
7
|
+
* - then, want to apply a standard transformation onto it
|
|
8
|
+
* .how =
|
|
9
|
+
* - .[doctype] replaced
|
|
10
|
+
* - .vNiN trail markers preserved as prefix before .[doctype]
|
|
11
|
+
* - .v1 always started with, to facilitate subsequent trails
|
|
12
|
+
* - .rel(...) optionally re-roots the prefix directory relatively
|
|
13
|
+
*/
|
|
14
|
+
export declare const execTranslateDocOutputPath: (opts: InvokeOpts<{
|
|
15
|
+
ask: string;
|
|
16
|
+
config: string;
|
|
17
|
+
}>, context?: ContextLogTrail) => InvokeOpts<{
|
|
18
|
+
ask: string;
|
|
19
|
+
config: string;
|
|
20
|
+
}>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.execTranslateDocOutputPath = void 0;
|
|
4
|
+
const helpful_errors_1 = require("helpful-errors");
|
|
5
|
+
const type_fns_1 = require("type-fns");
|
|
6
|
+
const decodeDocOutputPath_1 = require("./decodeDocOutputPath");
|
|
7
|
+
const relateDocOutputPath_1 = require("./relateDocOutputPath");
|
|
8
|
+
/**
|
|
9
|
+
* .what = execute the translation of a doc output path
|
|
10
|
+
* .why =
|
|
11
|
+
* - given @translate(references.1)
|
|
12
|
+
* - then, want to apply a standard transformation onto it
|
|
13
|
+
* .how =
|
|
14
|
+
* - .[doctype] replaced
|
|
15
|
+
* - .vNiN trail markers preserved as prefix before .[doctype]
|
|
16
|
+
* - .v1 always started with, to facilitate subsequent trails
|
|
17
|
+
* - .rel(...) optionally re-roots the prefix directory relatively
|
|
18
|
+
*/
|
|
19
|
+
const execTranslateDocOutputPath = (opts, context) => {
|
|
20
|
+
// if no .output or not a string, nothing to do
|
|
21
|
+
if (typeof opts.output !== 'string')
|
|
22
|
+
return opts;
|
|
23
|
+
// if not starts with @translate(, nothing to do
|
|
24
|
+
if (!opts.output.startsWith('@translate('))
|
|
25
|
+
return opts;
|
|
26
|
+
// if not @translate(references.0), fail fast
|
|
27
|
+
if (!opts.output.startsWith('@translate(references.0)'))
|
|
28
|
+
throw new helpful_errors_1.BadRequestError('unsupported @translation source. today, only "references.0" is supported', { opts });
|
|
29
|
+
// grab the "as" doctype, from @translate(references.0).as(doctype)
|
|
30
|
+
const doctypeAs = opts.output.match(/\.as\(([^)]+)\)/i)?.[1] ??
|
|
31
|
+
helpful_errors_1.UnexpectedCodePathError.throw('.as(doctype) was not part of output. can not translate', { opts });
|
|
32
|
+
// grab the extension override, if specified
|
|
33
|
+
const extensionOverride = opts.output.match(/\.ext\(([^)]+)\)/i)?.[1] ?? null;
|
|
34
|
+
// optional: starting variant override via .v(n)
|
|
35
|
+
const startVariantStr = opts.output.match(/\.v\((\d+)\)/i)?.[1] ?? null;
|
|
36
|
+
const startVariant = startVariantStr === null ? 1 : Number.parseInt(startVariantStr, 10);
|
|
37
|
+
if (!Number.isInteger(startVariant) || startVariant < 1) {
|
|
38
|
+
throw new helpful_errors_1.BadRequestError('.v(n) must be a positive integer (e.g. .v(2))', {
|
|
39
|
+
opts,
|
|
40
|
+
startVariantStr,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
// grab the optional relative directory augmenter, e.g. .rel(../step_2.format)
|
|
44
|
+
const relAugment = opts.output
|
|
45
|
+
.match(/\.rel\(([^)]+)\)/i)?.[1]
|
|
46
|
+
?.trim()
|
|
47
|
+
.replace(/^['"]|['"]$/g, '') ?? null;
|
|
48
|
+
// verify that references.0 exists and extract it
|
|
49
|
+
const inputPath = (() => {
|
|
50
|
+
if (typeof opts.references !== 'string')
|
|
51
|
+
throw new helpful_errors_1.BadRequestError('opts.references is not a string', { opts });
|
|
52
|
+
return (opts.references.split(',')[0] ||
|
|
53
|
+
helpful_errors_1.BadRequestError.throw('opts.references is not a string', { opts }));
|
|
54
|
+
})();
|
|
55
|
+
// attempt to grab doctype and versions from it
|
|
56
|
+
const { prefix, versions, extension } = (0, decodeDocOutputPath_1.decodeDocOutputPath)(inputPath);
|
|
57
|
+
// compose new output path
|
|
58
|
+
const outputPath = [
|
|
59
|
+
prefix,
|
|
60
|
+
versions.variant || versions.instance
|
|
61
|
+
? [
|
|
62
|
+
versions.variant ? `v${versions.variant}` : '',
|
|
63
|
+
versions.instance ? `i${versions.instance}` : '',
|
|
64
|
+
].join('')
|
|
65
|
+
: null,
|
|
66
|
+
`[${doctypeAs}]`,
|
|
67
|
+
`v${startVariant}`,
|
|
68
|
+
extensionOverride ?? extension,
|
|
69
|
+
]
|
|
70
|
+
.filter(type_fns_1.isPresent)
|
|
71
|
+
.join('.');
|
|
72
|
+
// relate the output path, if requested
|
|
73
|
+
const outputPathRelated = relAugment
|
|
74
|
+
? (0, relateDocOutputPath_1.relateDocOutputPath)({ path: outputPath, relation: relAugment })
|
|
75
|
+
: outputPath;
|
|
76
|
+
// swap out the opts
|
|
77
|
+
return { ...opts, output: outputPathRelated };
|
|
78
|
+
};
|
|
79
|
+
exports.execTranslateDocOutputPath = execTranslateDocOutputPath;
|
|
80
|
+
//# sourceMappingURL=execTranslateDocOutputPath.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execTranslateDocOutputPath.js","sourceRoot":"","sources":["../../../src/logic/hooks/execTranslateDocOutputPath.ts"],"names":[],"mappings":";;;AACA,mDAA0E;AAE1E,uCAAqC;AAErC,+DAA4D;AAC5D,+DAA4D;AAE5D;;;;;;;;;;GAUG;AACI,MAAM,0BAA0B,GAAG,CACxC,IAAiD,EACjD,OAAyB,EACoB,EAAE;IAC/C,+CAA+C;IAC/C,IAAI,OAAO,IAAI,CAAC,MAAM,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IAEjD,gDAAgD;IAChD,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,aAAa,CAAC;QAAE,OAAO,IAAI,CAAC;IAExD,6CAA6C;IAC7C,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,0BAA0B,CAAC;QACrD,MAAM,IAAI,gCAAe,CACvB,0EAA0E,EAC1E,EAAE,IAAI,EAAE,CACT,CAAC;IAEJ,mEAAmE;IACnE,MAAM,SAAS,GACb,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC,CAAC;QAC1C,wCAAuB,CAAC,KAAK,CAC3B,wDAAwD,EACxD,EAAE,IAAI,EAAE,CACT,CAAC;IAEJ,4CAA4C;IAC5C,MAAM,iBAAiB,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;IAE9E,gDAAgD;IAChD,MAAM,eAAe,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;IACxE,MAAM,YAAY,GAChB,eAAe,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ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