@udondan/avanti 0.1.0 → 0.3.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/CHANGELOG.md +25 -0
- package/README.md +254 -14
- package/dist/cli.js +2 -1
- package/dist/cli.js.map +1 -1
- package/dist/commands/diff.d.ts.map +1 -1
- package/dist/commands/diff.js +9 -5
- package/dist/commands/diff.js.map +1 -1
- package/dist/commands/pull.d.ts.map +1 -1
- package/dist/commands/pull.js +9 -5
- package/dist/commands/pull.js.map +1 -1
- package/dist/config.d.ts +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +85 -55
- package/dist/config.js.map +1 -1
- package/dist/diff.d.ts +2 -1
- package/dist/diff.d.ts.map +1 -1
- package/dist/diff.js +42 -18
- package/dist/diff.js.map +1 -1
- package/dist/processors/post.d.ts +2 -1
- package/dist/processors/post.d.ts.map +1 -1
- package/dist/processors/post.js +7 -5
- package/dist/processors/post.js.map +1 -1
- package/dist/processors/replace.d.ts +2 -2
- package/dist/processors/replace.d.ts.map +1 -1
- package/dist/processors/replace.js +8 -5
- package/dist/processors/replace.js.map +1 -1
- package/dist/sources/exec.js +3 -3
- package/dist/sources/github.js +15 -15
- package/dist/sources/gitlab.js +11 -11
- package/dist/sources/http.js +5 -5
- package/dist/sources/index.d.ts +2 -2
- package/dist/sources/index.d.ts.map +1 -1
- package/dist/sources/index.js +47 -30
- package/dist/sources/index.js.map +1 -1
- package/dist/sources/local.d.ts +1 -1
- package/dist/sources/local.d.ts.map +1 -1
- package/dist/sources/local.js +12 -9
- package/dist/sources/local.js.map +1 -1
- package/dist/types.d.ts +7 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/variables.d.ts +5 -0
- package/dist/variables.d.ts.map +1 -0
- package/dist/variables.js +34 -0
- package/dist/variables.js.map +1 -0
- package/dist/writer.js +3 -3
- package/package.json +19 -7
- package/.claude/settings.local.json +0 -9
package/dist/config.js
CHANGED
|
@@ -27,11 +27,12 @@ exports.loadConfig = exports.resolveConfigPath = void 0;
|
|
|
27
27
|
const fs = __importStar(require("fs"));
|
|
28
28
|
const path = __importStar(require("path"));
|
|
29
29
|
const yaml = __importStar(require("js-yaml"));
|
|
30
|
+
const variables_1 = require("./variables");
|
|
30
31
|
const CONFIG_CANDIDATES = [
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
'.avanti.yml',
|
|
33
|
+
'.avanti.yaml',
|
|
34
|
+
'avanti.yml',
|
|
35
|
+
'avanti.yaml',
|
|
35
36
|
];
|
|
36
37
|
function resolveConfigPath(explicit) {
|
|
37
38
|
if (explicit)
|
|
@@ -53,129 +54,158 @@ function loadConfig(configPath) {
|
|
|
53
54
|
}
|
|
54
55
|
let raw;
|
|
55
56
|
try {
|
|
56
|
-
const content = fs.readFileSync(configPath,
|
|
57
|
+
const content = fs.readFileSync(configPath, 'utf8');
|
|
57
58
|
raw = yaml.load(content);
|
|
58
59
|
}
|
|
59
60
|
catch (err) {
|
|
60
61
|
const msg = err instanceof Error ? err.message : String(err);
|
|
61
62
|
throw new Error(`Failed to parse config file: ${msg}`, { cause: err });
|
|
62
63
|
}
|
|
63
|
-
if (!raw || typeof raw !==
|
|
64
|
-
throw new Error(
|
|
64
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
65
|
+
throw new Error('Config must be a YAML object');
|
|
65
66
|
}
|
|
66
67
|
const obj = raw;
|
|
67
|
-
if (!Array.isArray(obj[
|
|
68
|
+
if (!Array.isArray(obj['files'])) {
|
|
68
69
|
throw new Error('Config must have a "files" array');
|
|
69
70
|
}
|
|
70
|
-
const
|
|
71
|
-
|
|
71
|
+
const variables = parseVariables(obj['variables']);
|
|
72
|
+
const files = obj['files'].map((entry, i) => {
|
|
73
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry)) {
|
|
72
74
|
throw new Error(`files[${i}]: must be an object`);
|
|
73
75
|
}
|
|
74
76
|
const e = entry;
|
|
75
|
-
if (e[
|
|
77
|
+
if (e['src'] === undefined || e['src'] === null) {
|
|
76
78
|
throw new Error(`files[${i}]: "src" is required`);
|
|
77
79
|
}
|
|
78
|
-
const src = Array.isArray(e[
|
|
79
|
-
? e[
|
|
80
|
-
: parseSingleSrc(e[
|
|
80
|
+
const src = Array.isArray(e['src'])
|
|
81
|
+
? e['src'].map((item, j) => parseSingleSrc(item, i, j))
|
|
82
|
+
: parseSingleSrc(e['src'], i, undefined);
|
|
81
83
|
// list src must have an explicit target
|
|
82
|
-
if (Array.isArray(src) && !e[
|
|
84
|
+
if (Array.isArray(src) && !e['target']) {
|
|
83
85
|
throw new Error(`files[${i}]: "target" is required when "src" is a list`);
|
|
84
86
|
}
|
|
85
|
-
// exec sources must have a target
|
|
86
|
-
if (!Array.isArray(src) &&
|
|
87
|
-
|
|
87
|
+
// exec/raw sources must have a target
|
|
88
|
+
if (!Array.isArray(src) &&
|
|
89
|
+
(isExecSrc(src) || isRawSrc(src)) &&
|
|
90
|
+
!e['target']) {
|
|
91
|
+
throw new Error(`files[${i}]: "target" is required for exec/raw sources`);
|
|
88
92
|
}
|
|
89
93
|
const fileEntry = { src };
|
|
90
|
-
if (typeof e[
|
|
91
|
-
fileEntry.target = e[
|
|
92
|
-
if (typeof e[
|
|
93
|
-
fileEntry.mode = e[
|
|
94
|
-
if (typeof e[
|
|
95
|
-
fileEntry.post = e[
|
|
96
|
-
if (e[
|
|
97
|
-
if (!Array.isArray(e[
|
|
94
|
+
if (typeof e['target'] === 'string')
|
|
95
|
+
fileEntry.target = e['target'];
|
|
96
|
+
if (typeof e['mode'] === 'string')
|
|
97
|
+
fileEntry.mode = e['mode'];
|
|
98
|
+
if (typeof e['post'] === 'string')
|
|
99
|
+
fileEntry.post = e['post'];
|
|
100
|
+
if (e['replace'] !== undefined) {
|
|
101
|
+
if (!Array.isArray(e['replace'])) {
|
|
98
102
|
throw new Error(`files[${i}]: "replace" must be an array`);
|
|
99
103
|
}
|
|
100
|
-
fileEntry.replace = e[
|
|
104
|
+
fileEntry.replace = e['replace'].map((r, j) => parseReplaceRule(r, i, j));
|
|
101
105
|
}
|
|
102
106
|
return fileEntry;
|
|
103
107
|
});
|
|
104
|
-
return { files };
|
|
108
|
+
return { variables, files };
|
|
105
109
|
}
|
|
106
110
|
exports.loadConfig = loadConfig;
|
|
111
|
+
function parseVariables(raw) {
|
|
112
|
+
if (raw === undefined || raw === null)
|
|
113
|
+
return {};
|
|
114
|
+
if (typeof raw !== 'object' || Array.isArray(raw)) {
|
|
115
|
+
throw new Error('"variables" must be a map of string keys to string values');
|
|
116
|
+
}
|
|
117
|
+
const obj = raw;
|
|
118
|
+
const vars = {};
|
|
119
|
+
for (const [key, val] of Object.entries(obj)) {
|
|
120
|
+
if (typeof val !== 'string') {
|
|
121
|
+
throw new Error(`variables.${key}: value must be a string`);
|
|
122
|
+
}
|
|
123
|
+
vars[key] = val;
|
|
124
|
+
}
|
|
125
|
+
(0, variables_1.validateVariables)(vars);
|
|
126
|
+
return vars;
|
|
127
|
+
}
|
|
107
128
|
function parseSingleSrc(raw, i, j) {
|
|
108
129
|
const loc = j !== undefined ? `files[${i}].src[${j}]` : `files[${i}].src`;
|
|
109
130
|
// Plain string → http/https URL or local path
|
|
110
|
-
if (typeof raw ===
|
|
131
|
+
if (typeof raw === 'string') {
|
|
111
132
|
return raw;
|
|
112
133
|
}
|
|
113
|
-
if (!raw || typeof raw !==
|
|
134
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
|
|
114
135
|
throw new Error(`${loc}: must be a string or a map with one of: exec, gitlab, github`);
|
|
115
136
|
}
|
|
116
137
|
const obj = raw;
|
|
117
|
-
if (
|
|
118
|
-
if (typeof obj[
|
|
138
|
+
if ('exec' in obj) {
|
|
139
|
+
if (typeof obj['exec'] !== 'string' || !obj['exec']) {
|
|
119
140
|
throw new Error(`${loc}.exec: must be a non-empty string`);
|
|
120
141
|
}
|
|
121
|
-
return { exec: obj[
|
|
142
|
+
return { exec: obj['exec'] };
|
|
122
143
|
}
|
|
123
|
-
if (
|
|
124
|
-
const gl = obj[
|
|
125
|
-
if (!gl || typeof gl !==
|
|
144
|
+
if ('gitlab' in obj) {
|
|
145
|
+
const gl = obj['gitlab'];
|
|
146
|
+
if (!gl || typeof gl !== 'object' || Array.isArray(gl)) {
|
|
126
147
|
throw new Error(`${loc}.gitlab: must be an object`);
|
|
127
148
|
}
|
|
128
149
|
const g = gl;
|
|
129
|
-
if (typeof g[
|
|
150
|
+
if (typeof g['project'] !== 'string' || !g['project']) {
|
|
130
151
|
throw new Error(`${loc}.gitlab.project: required string`);
|
|
131
152
|
}
|
|
132
|
-
if (typeof g[
|
|
153
|
+
if (typeof g['file'] !== 'string' || !g['file']) {
|
|
133
154
|
throw new Error(`${loc}.gitlab.file: required string`);
|
|
134
155
|
}
|
|
135
156
|
return {
|
|
136
157
|
gitlab: {
|
|
137
|
-
project: g[
|
|
138
|
-
file: g[
|
|
139
|
-
ref: typeof g[
|
|
158
|
+
project: g['project'],
|
|
159
|
+
file: g['file'],
|
|
160
|
+
ref: typeof g['ref'] === 'string' ? g['ref'] : undefined,
|
|
140
161
|
},
|
|
141
162
|
};
|
|
142
163
|
}
|
|
143
|
-
if (
|
|
144
|
-
|
|
145
|
-
|
|
164
|
+
if ('raw' in obj) {
|
|
165
|
+
if (typeof obj['raw'] !== 'string') {
|
|
166
|
+
throw new Error(`${loc}.raw: must be a string`);
|
|
167
|
+
}
|
|
168
|
+
return { raw: obj['raw'] };
|
|
169
|
+
}
|
|
170
|
+
if ('github' in obj) {
|
|
171
|
+
const gh = obj['github'];
|
|
172
|
+
if (!gh || typeof gh !== 'object' || Array.isArray(gh)) {
|
|
146
173
|
throw new Error(`${loc}.github: must be an object`);
|
|
147
174
|
}
|
|
148
175
|
const g = gh;
|
|
149
|
-
if (typeof g[
|
|
176
|
+
if (typeof g['repo'] !== 'string' || !g['repo']) {
|
|
150
177
|
throw new Error(`${loc}.github.repo: required string`);
|
|
151
178
|
}
|
|
152
|
-
if (typeof g[
|
|
179
|
+
if (typeof g['file'] !== 'string' || !g['file']) {
|
|
153
180
|
throw new Error(`${loc}.github.file: required string`);
|
|
154
181
|
}
|
|
155
182
|
return {
|
|
156
183
|
github: {
|
|
157
|
-
repo: g[
|
|
158
|
-
file: g[
|
|
159
|
-
ref: typeof g[
|
|
184
|
+
repo: g['repo'],
|
|
185
|
+
file: g['file'],
|
|
186
|
+
ref: typeof g['ref'] === 'string' ? g['ref'] : undefined,
|
|
160
187
|
},
|
|
161
188
|
};
|
|
162
189
|
}
|
|
163
|
-
throw new Error(`${loc}: unknown source type. Must be a string or map with exec/gitlab/github`);
|
|
190
|
+
throw new Error(`${loc}: unknown source type. Must be a string or map with exec/gitlab/github/raw`);
|
|
164
191
|
}
|
|
165
192
|
function isExecSrc(src) {
|
|
166
|
-
return typeof src ===
|
|
193
|
+
return typeof src === 'object' && 'exec' in src;
|
|
194
|
+
}
|
|
195
|
+
function isRawSrc(src) {
|
|
196
|
+
return typeof src === 'object' && 'raw' in src;
|
|
167
197
|
}
|
|
168
198
|
function parseReplaceRule(r, i, j) {
|
|
169
|
-
if (!r || typeof r !==
|
|
199
|
+
if (!r || typeof r !== 'object' || Array.isArray(r)) {
|
|
170
200
|
throw new Error(`files[${i}].replace[${j}]: must be an object`);
|
|
171
201
|
}
|
|
172
202
|
const rule = r;
|
|
173
|
-
if (typeof rule[
|
|
203
|
+
if (typeof rule['from'] !== 'string') {
|
|
174
204
|
throw new Error(`files[${i}].replace[${j}]: "from" must be a string`);
|
|
175
205
|
}
|
|
176
|
-
if (typeof rule[
|
|
206
|
+
if (typeof rule['to'] !== 'string') {
|
|
177
207
|
throw new Error(`files[${i}].replace[${j}]: "to" must be a string`);
|
|
178
208
|
}
|
|
179
|
-
return { from: rule[
|
|
209
|
+
return { from: rule['from'], to: rule['to'] };
|
|
180
210
|
}
|
|
181
211
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAC7B,8CAAgC;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAC7B,8CAAgC;AAQhC,2CAAgD;AAEhD,MAAM,iBAAiB,GAAG;IACxB,aAAa;IACb,cAAc;IACd,YAAY;IACZ,aAAa;CACd,CAAC;AAEF,SAAgB,iBAAiB,CAAC,QAAiB;IACjD,IAAI,QAAQ;QAAE,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE5C,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAC1B,MAAM,OAAO,GAAG,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACpC,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;IAEzD,KAAK,MAAM,SAAS,IAAI,iBAAiB,EAAE,CAAC;QAC1C,MAAM,GAAG,GAAG,YAAY,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAC5C,IAAI,GAAG,KAAK,CAAC,CAAC;YAAE,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;IACzD,CAAC;IAED,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC;AACjD,CAAC;AAbD,8CAaC;AAED,SAAgB,UAAU,CAAC,UAAkB;IAC3C,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,0BAA0B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IAAI,CAAC,MAAM,CAAC,KAAK,QAAQ,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,aAAa,CAAC,4BAA4B,CAAC,CAAC;IACxE,CAAC;IACD,IAAI,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,QAAQ,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CAAC,SAAS,CAAC,aAAa,CAAC,0BAA0B,CAAC,CAAC;IACtE,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAChD,CAAC"}
|
package/dist/diff.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Variables } from './types';
|
|
1
2
|
export interface FileDiff {
|
|
2
3
|
targetPath: string;
|
|
3
4
|
isNew: boolean;
|
|
@@ -9,5 +10,5 @@ export declare function formatDiff(diff: FileDiff): string;
|
|
|
9
10
|
export declare function printDiffs(diffs: FileDiff[]): void;
|
|
10
11
|
export declare function resolveTargetPath(entry: {
|
|
11
12
|
target?: string;
|
|
12
|
-
}, relPath: string,
|
|
13
|
+
}, relPath: string, workingDir: string, vars?: Variables): string;
|
|
13
14
|
//# sourceMappingURL=diff.d.ts.map
|
package/dist/diff.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../src/diff.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../src/diff.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGpC,MAAM,WAAW,QAAQ;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,OAAO,CAAC;IACf,UAAU,EAAE,OAAO,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,QAAQ,CAgB5E;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAajD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,CASlD;AAED,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,EAC1B,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,IAAI,GAAE,SAAc,GACnB,MAAM,CA2BR"}
|
package/dist/diff.js
CHANGED
|
@@ -31,36 +31,37 @@ const fs = __importStar(require("fs"));
|
|
|
31
31
|
const path = __importStar(require("path"));
|
|
32
32
|
const diff_1 = require("diff");
|
|
33
33
|
const chalk_1 = __importDefault(require("chalk"));
|
|
34
|
+
const variables_1 = require("./variables");
|
|
34
35
|
function computeDiff(targetPath, newContent) {
|
|
35
36
|
const isNew = !fs.existsSync(targetPath);
|
|
36
|
-
const oldContent = isNew ?
|
|
37
|
+
const oldContent = isNew ? '' : fs.readFileSync(targetPath, 'utf8');
|
|
37
38
|
const hasChanges = oldContent !== newContent;
|
|
38
|
-
const patch = (0, diff_1.createTwoFilesPatch)(isNew ?
|
|
39
|
+
const patch = (0, diff_1.createTwoFilesPatch)(isNew ? '/dev/null' : targetPath, targetPath, oldContent, newContent, isNew ? '' : undefined, isNew ? 'new file' : undefined);
|
|
39
40
|
return { targetPath, isNew, hasChanges, patch };
|
|
40
41
|
}
|
|
41
42
|
exports.computeDiff = computeDiff;
|
|
42
43
|
function formatDiff(diff) {
|
|
43
44
|
if (!diff.hasChanges)
|
|
44
|
-
return
|
|
45
|
-
const lines = diff.patch.split(
|
|
45
|
+
return '';
|
|
46
|
+
const lines = diff.patch.split('\n');
|
|
46
47
|
const colored = lines.map((line) => {
|
|
47
|
-
if (line.startsWith(
|
|
48
|
+
if (line.startsWith('+++') || line.startsWith('---'))
|
|
48
49
|
return chalk_1.default.bold(line);
|
|
49
|
-
if (line.startsWith(
|
|
50
|
+
if (line.startsWith('@@'))
|
|
50
51
|
return chalk_1.default.cyan(line);
|
|
51
|
-
if (line.startsWith(
|
|
52
|
+
if (line.startsWith('+'))
|
|
52
53
|
return chalk_1.default.green(line);
|
|
53
|
-
if (line.startsWith(
|
|
54
|
+
if (line.startsWith('-'))
|
|
54
55
|
return chalk_1.default.red(line);
|
|
55
56
|
return line;
|
|
56
57
|
});
|
|
57
|
-
return colored.join(
|
|
58
|
+
return colored.join('\n');
|
|
58
59
|
}
|
|
59
60
|
exports.formatDiff = formatDiff;
|
|
60
61
|
function printDiffs(diffs) {
|
|
61
62
|
const changed = diffs.filter((d) => d.hasChanges);
|
|
62
63
|
if (!changed.length) {
|
|
63
|
-
console.log(
|
|
64
|
+
console.log('No changes.');
|
|
64
65
|
return;
|
|
65
66
|
}
|
|
66
67
|
for (const d of changed) {
|
|
@@ -68,16 +69,39 @@ function printDiffs(diffs) {
|
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
exports.printDiffs = printDiffs;
|
|
71
|
-
function resolveTargetPath(entry, relPath,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
function resolveTargetPath(entry, relPath, workingDir, vars = {}) {
|
|
73
|
+
let resolved;
|
|
74
|
+
const target = entry.target ? (0, variables_1.resolveVars)(entry.target, vars) : undefined;
|
|
75
|
+
if (target) {
|
|
76
|
+
if (path.isAbsolute(target)) {
|
|
77
|
+
if (workingDir !== '/') {
|
|
78
|
+
throw new Error(`Absolute target path "${target}" is not allowed when working directory is not "/". Use a relative path or run with -C /.`);
|
|
79
|
+
}
|
|
80
|
+
if (target.endsWith('/') || target.endsWith(path.sep)) {
|
|
81
|
+
return path.resolve(target, relPath);
|
|
82
|
+
}
|
|
83
|
+
return target;
|
|
76
84
|
}
|
|
77
|
-
|
|
78
|
-
|
|
85
|
+
if (target.endsWith('/') || target.endsWith(path.sep)) {
|
|
86
|
+
resolved = path.resolve(workingDir, target, relPath);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
resolved = path.resolve(workingDir, target);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
resolved = path.resolve(workingDir, relPath);
|
|
79
94
|
}
|
|
80
|
-
|
|
95
|
+
assertWithinWorkingDir(resolved, workingDir);
|
|
96
|
+
return resolved;
|
|
81
97
|
}
|
|
82
98
|
exports.resolveTargetPath = resolveTargetPath;
|
|
99
|
+
function assertWithinWorkingDir(resolvedPath, workingDir) {
|
|
100
|
+
const prefix = workingDir.endsWith(path.sep)
|
|
101
|
+
? workingDir
|
|
102
|
+
: workingDir + path.sep;
|
|
103
|
+
if (resolvedPath !== workingDir && !resolvedPath.startsWith(prefix)) {
|
|
104
|
+
throw new Error(`Target path "${resolvedPath}" escapes working directory "${workingDir}".`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
83
107
|
//# sourceMappingURL=diff.js.map
|
package/dist/diff.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diff.js","sourceRoot":"","sources":["../src/diff.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAC7B,+BAA2C;AAC3C,kDAA0B;
|
|
1
|
+
{"version":3,"file":"diff.js","sourceRoot":"","sources":["../src/diff.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAyB;AACzB,2CAA6B;AAC7B,+BAA2C;AAC3C,kDAA0B;AAE1B,2CAA0C;AAS1C,SAAgB,WAAW,CAAC,UAAkB,EAAE,UAAkB;IAChE,MAAM,KAAK,GAAG,CAAC,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IACzC,MAAM,UAAU,GAAG,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,UAAU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AC,EAAE,CAAC;YACtD,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QACvD,CAAC;aAAM,CAAC;YACN,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;SAAM,CAAC;QACN,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAC/C,CAAC;IAED,sBAAsB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IAC7C,OAAO,QAAQ,CAAC;AAClB,CAAC;AAhCD,8CAgCC;AAED,SAAS,sBAAsB,CAC7B,YAAoB,EACpB,UAAkB;IAElB,MAAM,MAAM,GAAG,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC;QAC1C,CAAC,CAAC,UAAU;QACZ,CAAC,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC;IAC1B,IAAI,YAAY,KAAK,UAAU,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QACpE,MAAM,IAAI,KAAK,CACb,gBAAgB,YAAY,gCAAgC,UAAU,IAAI,CAC3E,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post.d.ts","sourceRoot":"","sources":["../../src/processors/post.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"post.d.ts","sourceRoot":"","sources":["../../src/processors/post.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAGrC,wBAAgB,SAAS,CACvB,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,IAAI,GAAE,SAAc,GACnB,MAAM,CAgBR"}
|
package/dist/processors/post.js
CHANGED
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.applyPost = void 0;
|
|
4
4
|
const child_process_1 = require("child_process");
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const variables_1 = require("../variables");
|
|
6
|
+
function applyPost(content, script, vars = {}) {
|
|
7
|
+
const resolvedScript = (0, variables_1.resolveVars)(script, vars);
|
|
8
|
+
const result = (0, child_process_1.spawnSync)('sh', ['-c', resolvedScript], {
|
|
7
9
|
input: content,
|
|
8
|
-
encoding:
|
|
10
|
+
encoding: 'utf8',
|
|
9
11
|
});
|
|
10
12
|
if (result.status !== null && result.status !== 0) {
|
|
11
|
-
const stderr = result.stderr?.trim() ??
|
|
12
|
-
throw new Error(`post script exited with code ${result.status}${stderr ?
|
|
13
|
+
const stderr = result.stderr?.trim() ?? '';
|
|
14
|
+
throw new Error(`post script exited with code ${result.status}${stderr ? ': ' + stderr : ''}`);
|
|
13
15
|
}
|
|
14
16
|
if (result.error) {
|
|
15
17
|
throw new Error(`post script failed to spawn: ${result.error.message}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post.js","sourceRoot":"","sources":["../../src/processors/post.ts"],"names":[],"mappings":";;;AAAA,iDAA0C;AAE1C,SAAgB,SAAS,
|
|
1
|
+
{"version":3,"file":"post.js","sourceRoot":"","sources":["../../src/processors/post.ts"],"names":[],"mappings":";;;AAAA,iDAA0C;AAE1C,4CAA2C;AAE3C,SAAgB,SAAS,CACvB,OAAe,EACf,MAAc,EACd,OAAkB,EAAE;IAEpB,MAAM,cAAc,GAAG,IAAA,uBAAW,EAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IACjD,MAAM,MAAM,GAAG,IAAA,yBAAS,EAAC,IAAI,EAAE,CAAC,IAAI,EAAE,cAAc,CAAC,EAAE;QACrD,KAAK,EAAE,OAAO;QACd,QAAQ,EAAE,MAAM;KACjB,CAAC,CAAC;IACH,IAAI,MAAM,CAAC,MAAM,KAAK,IAAI,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClD,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;QAC3C,MAAM,IAAI,KAAK,CACb,gCAAgC,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAC9E,CAAC;IACJ,CAAC;IACD,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,gCAAgC,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAC1E,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC;AACvB,CAAC;AApBD,8BAoBC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { ReplaceRule } from
|
|
2
|
-
export declare function applyReplace(content: string, rules: ReplaceRule[]): string;
|
|
1
|
+
import { ReplaceRule, Variables } from '../types';
|
|
2
|
+
export declare function applyReplace(content: string, rules: ReplaceRule[], vars?: Variables): string;
|
|
3
3
|
//# sourceMappingURL=replace.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replace.d.ts","sourceRoot":"","sources":["../../src/processors/replace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"replace.d.ts","sourceRoot":"","sources":["../../src/processors/replace.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAWlD,wBAAgB,YAAY,CAC1B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,WAAW,EAAE,EACpB,IAAI,GAAE,SAAc,GACnB,MAAM,CAaR"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.applyReplace = void 0;
|
|
4
|
+
const variables_1 = require("../variables");
|
|
4
5
|
function parseFrom(from) {
|
|
5
6
|
const match = from.match(/^\/(.+)\/([gimsuy]*)$/);
|
|
6
7
|
if (match) {
|
|
@@ -8,15 +9,17 @@ function parseFrom(from) {
|
|
|
8
9
|
}
|
|
9
10
|
return from;
|
|
10
11
|
}
|
|
11
|
-
function applyReplace(content, rules) {
|
|
12
|
+
function applyReplace(content, rules, vars = {}) {
|
|
12
13
|
let result = content;
|
|
13
14
|
for (const rule of rules) {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
const from = (0, variables_1.resolveVars)(rule.from, vars);
|
|
16
|
+
const to = (0, variables_1.resolveVars)(rule.to, vars);
|
|
17
|
+
const pattern = parseFrom(from);
|
|
18
|
+
if (typeof pattern === 'string') {
|
|
19
|
+
result = result.split(pattern).join(to);
|
|
17
20
|
}
|
|
18
21
|
else {
|
|
19
|
-
result = result.replace(pattern,
|
|
22
|
+
result = result.replace(pattern, to);
|
|
20
23
|
}
|
|
21
24
|
}
|
|
22
25
|
return result;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"replace.js","sourceRoot":"","sources":["../../src/processors/replace.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"replace.js","sourceRoot":"","sources":["../../src/processors/replace.ts"],"names":[],"mappings":";;;AACA,4CAA2C;AAE3C,SAAS,SAAS,CAAC,IAAY;IAC7B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAClD,IAAI,KAAK,EAAE,CAAC;QACV,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACxC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAgB,YAAY,CAC1B,OAAe,EACf,KAAoB,EACpB,OAAkB,EAAE;IAEpB,IAAI,MAAM,GAAG,OAAO,CAAC;IACrB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,IAAI,GAAG,IAAA,uBAAW,EAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAC1C,MAAM,EAAE,GAAG,IAAA,uBAAW,EAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QACtC,MAAM,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;QAChC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAChC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC1C,CAAC;aAAM,CAAC;YACN,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACvC,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAjBD,oCAiBC"}
|
package/dist/sources/exec.js
CHANGED
|
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.fetchExec = void 0;
|
|
4
4
|
const child_process_1 = require("child_process");
|
|
5
5
|
function fetchExec(command) {
|
|
6
|
-
const result = (0, child_process_1.spawnSync)(
|
|
6
|
+
const result = (0, child_process_1.spawnSync)('sh', ['-c', command], { encoding: 'utf8' });
|
|
7
7
|
if (result.error) {
|
|
8
8
|
throw new Error(`exec failed to spawn: ${result.error.message}`);
|
|
9
9
|
}
|
|
10
10
|
if (result.status !== 0) {
|
|
11
|
-
const stderr = result.stderr?.trim() ??
|
|
12
|
-
throw new Error(`exec exited with code ${result.status}${stderr ?
|
|
11
|
+
const stderr = result.stderr?.trim() ?? '';
|
|
12
|
+
throw new Error(`exec exited with code ${result.status}${stderr ? ': ' + stderr : ''}`);
|
|
13
13
|
}
|
|
14
14
|
return result.stdout;
|
|
15
15
|
}
|
package/dist/sources/github.js
CHANGED
|
@@ -27,47 +27,47 @@ exports.fetchGitHub = void 0;
|
|
|
27
27
|
const child_process_1 = require("child_process");
|
|
28
28
|
const path = __importStar(require("path"));
|
|
29
29
|
function ghRun(args) {
|
|
30
|
-
const result = (0, child_process_1.spawnSync)(
|
|
30
|
+
const result = (0, child_process_1.spawnSync)('gh', args, { encoding: 'utf8' });
|
|
31
31
|
if (result.error) {
|
|
32
|
-
const msg = result.error.message ??
|
|
33
|
-
if (msg.includes(
|
|
34
|
-
throw new Error(
|
|
32
|
+
const msg = result.error.message ?? '';
|
|
33
|
+
if (msg.includes('ENOENT')) {
|
|
34
|
+
throw new Error('gh CLI not found. Install it from https://cli.github.com');
|
|
35
35
|
}
|
|
36
36
|
throw new Error(`gh error: ${msg}`);
|
|
37
37
|
}
|
|
38
38
|
return {
|
|
39
|
-
stdout: result.stdout ??
|
|
40
|
-
stderr: result.stderr ??
|
|
39
|
+
stdout: result.stdout ?? '',
|
|
40
|
+
stderr: result.stderr ?? '',
|
|
41
41
|
status: result.status,
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
44
|
function fetchFile(repo, filePath, ref) {
|
|
45
45
|
const res = ghRun([
|
|
46
|
-
|
|
46
|
+
'api',
|
|
47
47
|
`repos/${repo}/contents/${filePath}?ref=${encodeURIComponent(ref)}`,
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
'--jq',
|
|
49
|
+
'.content',
|
|
50
50
|
]);
|
|
51
51
|
if (res.status !== 0) {
|
|
52
52
|
throw new Error(`Failed to fetch ${filePath} from ${repo}@${ref}: ${res.stderr}`);
|
|
53
53
|
}
|
|
54
|
-
const b64 = res.stdout.trim().replace(/\\n/g,
|
|
55
|
-
return Buffer.from(b64,
|
|
54
|
+
const b64 = res.stdout.trim().replace(/\\n/g, '').replace(/\n/g, '');
|
|
55
|
+
return Buffer.from(b64, 'base64').toString('utf8');
|
|
56
56
|
}
|
|
57
57
|
function listTree(repo, dirPath, ref) {
|
|
58
58
|
const res = ghRun([
|
|
59
|
-
|
|
59
|
+
'api',
|
|
60
60
|
`repos/${repo}/git/trees/${encodeURIComponent(ref)}?recursive=1`,
|
|
61
|
-
|
|
61
|
+
'--jq',
|
|
62
62
|
`.tree[] | select(.type == "blob") | select(.path | startswith("${dirPath}/")) | .path`,
|
|
63
63
|
]);
|
|
64
64
|
if (res.status !== 0) {
|
|
65
65
|
throw new Error(`Failed to list tree ${dirPath} in ${repo}@${ref}: ${res.stderr}`);
|
|
66
66
|
}
|
|
67
|
-
return res.stdout.trim().split(
|
|
67
|
+
return res.stdout.trim().split('\n').filter(Boolean);
|
|
68
68
|
}
|
|
69
69
|
function fetchGitHub(repo, file, ref) {
|
|
70
|
-
const resolvedRef = ref ??
|
|
70
|
+
const resolvedRef = ref ?? 'HEAD';
|
|
71
71
|
const files = new Map();
|
|
72
72
|
try {
|
|
73
73
|
const content = fetchFile(repo, file, resolvedRef);
|