@w5s/configurator-core 1.0.0-alpha.1
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/LICENSE +21 -0
- package/README.md +44 -0
- package/dist/index.cjs +446 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +304 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +304 -0
- package/dist/index.js +433 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -0
- package/src/FileMode.ts +33 -0
- package/src/__exists.ts +11 -0
- package/src/__existsSync.ts +10 -0
- package/src/__toMode.ts +19 -0
- package/src/block.ts +153 -0
- package/src/directory.ts +91 -0
- package/src/exec.ts +73 -0
- package/src/file.ts +108 -0
- package/src/index.ts +7 -0
- package/src/json.ts +43 -0
- package/src/meta.ts +8 -0
- package/src/testing/getRootPath.ts +9 -0
- package/src/testing/getTempPath.ts +6 -0
- package/src/testing/getTestPath.ts +25 -0
- package/src/testing/index.ts +1 -0
- package/src/yarnConfig.ts +61 -0
- package/src/yarnVersion.ts +56 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
import { accessSync, chmodSync, constants, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { access, chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
3
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
4
|
+
//#region src/__exists.ts
|
|
5
|
+
async function __exists(path) {
|
|
6
|
+
try {
|
|
7
|
+
await access(path, constants.F_OK);
|
|
8
|
+
return true;
|
|
9
|
+
} catch {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/__toMode.ts
|
|
15
|
+
function toModeFlag(permissionSet, read, write, execute) {
|
|
16
|
+
return (permissionSet?.read === true ? read : 0) | (permissionSet?.write === true ? write : 0) | (permissionSet?.execute === true ? execute : 0);
|
|
17
|
+
}
|
|
18
|
+
function __toMode(mode) {
|
|
19
|
+
return mode == null ? mode : toModeFlag(mode.owner, 256, 128, 64) | toModeFlag(mode.group, 32, 16, 8) | toModeFlag(mode.other, 4, 2, 1);
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/__existsSync.ts
|
|
23
|
+
function __existsSync(path) {
|
|
24
|
+
try {
|
|
25
|
+
accessSync(path, constants.F_OK);
|
|
26
|
+
return true;
|
|
27
|
+
} catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/directory.ts
|
|
33
|
+
/**
|
|
34
|
+
* Ensure directory is present/absent
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* await directory({
|
|
39
|
+
* path: 'foo/bar',
|
|
40
|
+
* state: 'present',
|
|
41
|
+
* mode: {
|
|
42
|
+
* owner: { read: true, write: true, execute: true },
|
|
43
|
+
* group: { read: true, write: true, execute: true },
|
|
44
|
+
* other: { read: true, write: true, execute: true },
|
|
45
|
+
* },
|
|
46
|
+
* })
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @param options
|
|
50
|
+
*/
|
|
51
|
+
async function directory(options) {
|
|
52
|
+
const { path, state, mode } = options;
|
|
53
|
+
const isPresent = await __exists(path);
|
|
54
|
+
if (state === "present") {
|
|
55
|
+
const newMode = __toMode(mode);
|
|
56
|
+
if (!isPresent) await mkdir(path, {
|
|
57
|
+
recursive: true,
|
|
58
|
+
mode: newMode
|
|
59
|
+
});
|
|
60
|
+
if (newMode != null && isPresent) await chmod(path, newMode);
|
|
61
|
+
} else if (isPresent) await rm(path, { recursive: true });
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Ensure directory is present/absent
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```ts
|
|
68
|
+
* directorySync({
|
|
69
|
+
* path: 'foo/bar',
|
|
70
|
+
* state: 'present',
|
|
71
|
+
* mode: {
|
|
72
|
+
* owner: { read: true, write: true, execute: true },
|
|
73
|
+
* group: { read: true, write: true, execute: true },
|
|
74
|
+
* other: { read: true, write: true, execute: true },
|
|
75
|
+
* },
|
|
76
|
+
* })
|
|
77
|
+
* ```
|
|
78
|
+
*
|
|
79
|
+
* @param options
|
|
80
|
+
*/
|
|
81
|
+
function directorySync(options) {
|
|
82
|
+
const { path, state, mode } = options;
|
|
83
|
+
const isPresent = __existsSync(path);
|
|
84
|
+
if (state === "present") {
|
|
85
|
+
const newMode = __toMode(mode);
|
|
86
|
+
if (!isPresent) mkdirSync(path, {
|
|
87
|
+
recursive: true,
|
|
88
|
+
mode: newMode
|
|
89
|
+
});
|
|
90
|
+
if (newMode != null && isPresent) chmodSync(path, newMode);
|
|
91
|
+
} else if (isPresent) rmSync(path, { recursive: true });
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
94
|
+
//#region src/file.ts
|
|
95
|
+
/**
|
|
96
|
+
* Ensure file is present/absent with content initialized or modified with `update
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```ts
|
|
100
|
+
* await file({
|
|
101
|
+
* path: 'foo/bar',
|
|
102
|
+
* state: 'present',
|
|
103
|
+
* update: (content) => content + '_test', // This will append '_test' after current content
|
|
104
|
+
* mode: {
|
|
105
|
+
* owner: { read: true, write: true, execute: true },
|
|
106
|
+
* group: { read: true, write: true, execute: true },
|
|
107
|
+
* other: { read: true, write: true, execute: true },
|
|
108
|
+
* },
|
|
109
|
+
* })
|
|
110
|
+
* ```
|
|
111
|
+
*
|
|
112
|
+
* @param options
|
|
113
|
+
*/
|
|
114
|
+
async function file(options) {
|
|
115
|
+
const { path, state, update, encoding = "utf8", mode } = options;
|
|
116
|
+
if (state === "present") {
|
|
117
|
+
const isPresent = await __exists(path);
|
|
118
|
+
const previousContent = isPresent ? await readFile(path, encoding) : "";
|
|
119
|
+
const newContent = update == null ? isPresent ? void 0 : "" : update(previousContent);
|
|
120
|
+
const newMode = __toMode(mode);
|
|
121
|
+
if (newContent != null) await writeFile(path, newContent, {
|
|
122
|
+
encoding,
|
|
123
|
+
mode: newMode
|
|
124
|
+
});
|
|
125
|
+
if (newMode != null && (isPresent || newContent != null)) await chmod(path, newMode);
|
|
126
|
+
} else await rm(path, { force: true });
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Ensure file is present/absent with content initialized or modified with `update
|
|
130
|
+
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```ts
|
|
133
|
+
* fileSync({
|
|
134
|
+
* path: 'foo/bar',
|
|
135
|
+
* state: 'present',
|
|
136
|
+
* update: (content) => content + '_test', // This will append '_test' after current content
|
|
137
|
+
* mode: {
|
|
138
|
+
* owner: { read: true, write: true, execute: true },
|
|
139
|
+
* group: { read: true, write: true, execute: true },
|
|
140
|
+
* other: { read: true, write: true, execute: true },
|
|
141
|
+
* },
|
|
142
|
+
* })
|
|
143
|
+
* ```
|
|
144
|
+
*
|
|
145
|
+
* @param options
|
|
146
|
+
*/
|
|
147
|
+
function fileSync(options) {
|
|
148
|
+
const { path, state, update, encoding = "utf8", mode } = options;
|
|
149
|
+
if (state === "present") {
|
|
150
|
+
const isPresent = __existsSync(path);
|
|
151
|
+
const previousContent = isPresent ? readFileSync(path, encoding) : "";
|
|
152
|
+
const newContent = update == null ? isPresent ? void 0 : "" : update(previousContent);
|
|
153
|
+
const newMode = __toMode(mode);
|
|
154
|
+
if (newContent != null) writeFileSync(path, newContent, {
|
|
155
|
+
encoding,
|
|
156
|
+
mode: newMode
|
|
157
|
+
});
|
|
158
|
+
if (newMode != null && (isPresent || newContent != null)) chmodSync(path, newMode);
|
|
159
|
+
} else rmSync(path, { force: true });
|
|
160
|
+
}
|
|
161
|
+
//#endregion
|
|
162
|
+
//#region src/block.ts
|
|
163
|
+
const EOF = "EndOfFile";
|
|
164
|
+
const BOF = "BeginningOfFile";
|
|
165
|
+
const insertAt = (str, index, toInsert) => str.slice(0, index) + toInsert + str.slice(index);
|
|
166
|
+
const matchLast = (string, regexp) => {
|
|
167
|
+
const matcher = new RegExp(regexp.source, `${regexp.flags}g`);
|
|
168
|
+
let firstIndex = -1;
|
|
169
|
+
let lastIndex = -1;
|
|
170
|
+
let matches;
|
|
171
|
+
while (true) {
|
|
172
|
+
matches = matcher.exec(string);
|
|
173
|
+
if (matches == null) break;
|
|
174
|
+
firstIndex = matches.index;
|
|
175
|
+
lastIndex = matcher.lastIndex;
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
firstIndex,
|
|
179
|
+
lastIndex
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
function toFileOptions(options) {
|
|
183
|
+
const { marker = (mark) => `# ${mark.toUpperCase()} MANAGED BLOCK`, path, block: blockName, insertPosition = ["after", EOF], state = "present" } = options;
|
|
184
|
+
const EOL = "\n";
|
|
185
|
+
const beginBlock = marker("Begin");
|
|
186
|
+
const endBlock = marker("End");
|
|
187
|
+
/**
|
|
188
|
+
* @param content
|
|
189
|
+
*/
|
|
190
|
+
function findBlock(content) {
|
|
191
|
+
const startIndex = content.indexOf(beginBlock);
|
|
192
|
+
const endIndex = content.indexOf(endBlock) + endBlock.length;
|
|
193
|
+
return {
|
|
194
|
+
endIndex,
|
|
195
|
+
exists: startIndex !== -1 && endIndex >= 0,
|
|
196
|
+
startIndex
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function apply(fullContent, blockContent) {
|
|
200
|
+
const found = findBlock(fullContent);
|
|
201
|
+
const remove = state === "absent";
|
|
202
|
+
const replaceBlock = remove ? "" : beginBlock + EOL + blockContent + EOL + endBlock;
|
|
203
|
+
const [positionDirection, positionAnchor] = insertPosition;
|
|
204
|
+
if (found.exists) return fullContent.slice(0, found.startIndex) + replaceBlock + fullContent.slice(found.endIndex);
|
|
205
|
+
if (remove) return fullContent;
|
|
206
|
+
switch (positionDirection) {
|
|
207
|
+
case "before":
|
|
208
|
+
if (positionAnchor !== BOF) {
|
|
209
|
+
const { firstIndex } = matchLast(fullContent, positionAnchor);
|
|
210
|
+
if (firstIndex >= 0) return insertAt(fullContent, firstIndex, replaceBlock + EOL);
|
|
211
|
+
}
|
|
212
|
+
return replaceBlock + EOL + fullContent;
|
|
213
|
+
case "after":
|
|
214
|
+
if (positionAnchor !== EOF) {
|
|
215
|
+
const { lastIndex } = matchLast(fullContent, positionAnchor);
|
|
216
|
+
if (lastIndex >= 0) return insertAt(fullContent, lastIndex, EOL + replaceBlock);
|
|
217
|
+
}
|
|
218
|
+
return fullContent + EOL + replaceBlock;
|
|
219
|
+
default: throw new Error(`Unsupported position ${String(positionDirection)}`);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
path,
|
|
224
|
+
state: "present",
|
|
225
|
+
update: (sourceContent) => apply(sourceContent, blockName)
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Replace asynchronously a block in file that follows pattern :
|
|
230
|
+
*
|
|
231
|
+
* marker(markerBegin)
|
|
232
|
+
* ...
|
|
233
|
+
* marker(markerEnd)
|
|
234
|
+
*
|
|
235
|
+
* @param options
|
|
236
|
+
*/
|
|
237
|
+
function block(options) {
|
|
238
|
+
return file(toFileOptions(options));
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Replace synchronously a block in file that follows pattern :
|
|
242
|
+
*
|
|
243
|
+
* marker(markerBegin)
|
|
244
|
+
* ...
|
|
245
|
+
* marker(markerEnd)
|
|
246
|
+
*
|
|
247
|
+
* @param options
|
|
248
|
+
*/
|
|
249
|
+
function blockSync(options) {
|
|
250
|
+
return fileSync(toFileOptions(options));
|
|
251
|
+
}
|
|
252
|
+
//#endregion
|
|
253
|
+
//#region src/json.ts
|
|
254
|
+
function toFileOption({ update, ...otherOptions }) {
|
|
255
|
+
return {
|
|
256
|
+
...otherOptions,
|
|
257
|
+
update: update == null ? update : (content) => {
|
|
258
|
+
const jsonValue = content === "" ? void 0 : JSON.parse(content);
|
|
259
|
+
return JSON.stringify(update(jsonValue));
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Ensure file is present/absent asynchronously with content value initialized or modified with `update`
|
|
265
|
+
*
|
|
266
|
+
* @param options
|
|
267
|
+
*/
|
|
268
|
+
async function json(options) {
|
|
269
|
+
return file(toFileOption(options));
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Ensure file is present/absent synchronously with content value initialized or modified with `update`
|
|
273
|
+
*
|
|
274
|
+
* @param options
|
|
275
|
+
*/
|
|
276
|
+
function jsonSync(options) {
|
|
277
|
+
return fileSync(toFileOption(options));
|
|
278
|
+
}
|
|
279
|
+
//#endregion
|
|
280
|
+
//#region src/meta.ts
|
|
281
|
+
const meta = Object.freeze({
|
|
282
|
+
name: "@w5s/configurator-core",
|
|
283
|
+
version: "1.0.0-alpha.1",
|
|
284
|
+
buildNumber: 1
|
|
285
|
+
});
|
|
286
|
+
//#endregion
|
|
287
|
+
//#region src/exec.ts
|
|
288
|
+
/**
|
|
289
|
+
* Runs a command in a shell and returns a promise that resolves with an object
|
|
290
|
+
* containing the stdout and stderr strings.
|
|
291
|
+
*
|
|
292
|
+
* @param command The command to run
|
|
293
|
+
* @param args The arguments to pass to the command
|
|
294
|
+
* @param options
|
|
295
|
+
* @returns A promise that resolves with an object like `{ stdout: string, stderr: string }`
|
|
296
|
+
*/
|
|
297
|
+
function execSync(command, args, options) {
|
|
298
|
+
const result = spawnSync(command, args, { ...options });
|
|
299
|
+
const encoding = "utf8";
|
|
300
|
+
return {
|
|
301
|
+
stdout: result.stdout.toString(encoding),
|
|
302
|
+
stderr: result.stderr.toString(encoding)
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Runs a command in a shell and returns a promise that resolves with an object
|
|
307
|
+
* containing the stdout and stderr strings.
|
|
308
|
+
*
|
|
309
|
+
* @param command The command to run
|
|
310
|
+
* @param args The arguments to pass to the command
|
|
311
|
+
* @param options
|
|
312
|
+
*/
|
|
313
|
+
async function exec(command, args, options) {
|
|
314
|
+
return new Promise((resolve, reject) => {
|
|
315
|
+
const encoding = "utf8";
|
|
316
|
+
const child = spawn(command, args, { ...options });
|
|
317
|
+
let stdout = "";
|
|
318
|
+
let stderr = "";
|
|
319
|
+
if (child.stdout != null) child.stdout.on("data", (data) => {
|
|
320
|
+
stdout += data.toString(encoding);
|
|
321
|
+
});
|
|
322
|
+
if (child.stderr != null) child.stderr.on("data", (data) => {
|
|
323
|
+
stderr += data.toString(encoding);
|
|
324
|
+
});
|
|
325
|
+
child.on("close", (_code) => {
|
|
326
|
+
resolve({
|
|
327
|
+
stdout,
|
|
328
|
+
stderr
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
child.on("error", reject);
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
//#endregion
|
|
335
|
+
//#region src/yarnConfig.ts
|
|
336
|
+
/**
|
|
337
|
+
* Synchronous version of {@link yarnConfig}
|
|
338
|
+
*
|
|
339
|
+
* @param options
|
|
340
|
+
* @example
|
|
341
|
+
* yarnConfigSync({
|
|
342
|
+
* key: 'nodeLinker',
|
|
343
|
+
* state: 'present',
|
|
344
|
+
* update: (content) => content.replace('node-modules', 'hoisted'),
|
|
345
|
+
* })
|
|
346
|
+
*/
|
|
347
|
+
function yarnConfigSync(options) {
|
|
348
|
+
const { key, state, update } = options;
|
|
349
|
+
if (state === "present") {
|
|
350
|
+
const { stdout } = execSync("yarn", [
|
|
351
|
+
"config",
|
|
352
|
+
"get",
|
|
353
|
+
String(key)
|
|
354
|
+
]);
|
|
355
|
+
execSync("yarn", [
|
|
356
|
+
"config",
|
|
357
|
+
"set",
|
|
358
|
+
String(key),
|
|
359
|
+
`${update == null ? "" : update(stdout)}`
|
|
360
|
+
]);
|
|
361
|
+
} else execSync("yarn", ["config", "unset"]);
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Set/Unset yarn configuration value
|
|
365
|
+
*
|
|
366
|
+
* @param options
|
|
367
|
+
* @example
|
|
368
|
+
* await yarnConfig({
|
|
369
|
+
* key: 'nodeLinker',
|
|
370
|
+
* state: 'present',
|
|
371
|
+
* update: (content) => content.replace('node-modules', 'hoisted'),
|
|
372
|
+
* })
|
|
373
|
+
*/
|
|
374
|
+
async function yarnConfig(options) {
|
|
375
|
+
const { key, state, update } = options;
|
|
376
|
+
if (state === "present") {
|
|
377
|
+
const { stdout } = await exec("yarn", [
|
|
378
|
+
"config",
|
|
379
|
+
"get",
|
|
380
|
+
String(key)
|
|
381
|
+
]);
|
|
382
|
+
await exec("yarn", [
|
|
383
|
+
"config",
|
|
384
|
+
"set",
|
|
385
|
+
String(key),
|
|
386
|
+
`${update == null ? "" : update(stdout)}`
|
|
387
|
+
]);
|
|
388
|
+
} else await exec("yarn", ["config", "unset"]);
|
|
389
|
+
}
|
|
390
|
+
//#endregion
|
|
391
|
+
//#region src/yarnVersion.ts
|
|
392
|
+
/**
|
|
393
|
+
* Synchronous version of {@link yarnVersion}
|
|
394
|
+
*
|
|
395
|
+
* @param options
|
|
396
|
+
* @example
|
|
397
|
+
* yarnVersionSync({
|
|
398
|
+
* state: 'present',
|
|
399
|
+
* update: () => 'berry', // or 'classic'
|
|
400
|
+
* })
|
|
401
|
+
*/
|
|
402
|
+
function yarnVersionSync(options) {
|
|
403
|
+
const { state, update } = options;
|
|
404
|
+
if (state === "present") execSync("yarn", [
|
|
405
|
+
"set",
|
|
406
|
+
"version",
|
|
407
|
+
`${update == null ? "berry" : update()}`
|
|
408
|
+
]);
|
|
409
|
+
else throw new Error("Not implemented");
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Set/Unset yarn configuration value
|
|
413
|
+
*
|
|
414
|
+
* @param options
|
|
415
|
+
* @example
|
|
416
|
+
* await yarnVersion({
|
|
417
|
+
* state: 'present',
|
|
418
|
+
* update: () => 'berry', // or 'classic'
|
|
419
|
+
* })
|
|
420
|
+
*/
|
|
421
|
+
async function yarnVersion(options) {
|
|
422
|
+
const { state, update } = options;
|
|
423
|
+
if (state === "present") await exec("yarn", [
|
|
424
|
+
"set",
|
|
425
|
+
"version",
|
|
426
|
+
`${update == null ? "berry" : update()}`
|
|
427
|
+
]);
|
|
428
|
+
else throw new Error("Not implemented");
|
|
429
|
+
}
|
|
430
|
+
//#endregion
|
|
431
|
+
export { block, blockSync, directory, directorySync, file, fileSync, json, jsonSync, meta, yarnConfig, yarnConfigSync, yarnVersion, yarnVersionSync };
|
|
432
|
+
|
|
433
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/__exists.ts","../src/__toMode.ts","../src/__existsSync.ts","../src/directory.ts","../src/file.ts","../src/block.ts","../src/json.ts","../src/meta.ts","../src/exec.ts","../src/yarnConfig.ts","../src/yarnVersion.ts"],"sourcesContent":["import { access } from 'node:fs/promises';\nimport { constants } from 'node:fs';\n\nexport async function __exists(path: string) {\n try {\n await access(path, constants.F_OK);\n return true;\n } catch {\n return false;\n }\n}\n","import type { FileMode, FilePermissionSet } from './FileMode.js';\n\nfunction toModeFlag(permissionSet: FilePermissionSet | undefined, read: number, write: number, execute: number): number {\n return (\n (permissionSet?.read === true ? read : 0)\n | (permissionSet?.write === true ? write : 0)\n | (permissionSet?.execute === true ? execute : 0)\n );\n}\n\nexport function __toMode(mode: FileMode | undefined): number | undefined {\n return mode == null\n ? mode\n : (\n toModeFlag(mode.owner, 0o400, 0o200, 0o100)\n | toModeFlag(mode.group, 0o040, 0o020, 0o010)\n | toModeFlag(mode.other, 0o004, 0o002, 0o001)\n );\n}\n","import { accessSync, constants } from 'node:fs';\n\nexport function __existsSync(path: string) {\n try {\n accessSync(path, constants.F_OK);\n return true;\n } catch {\n return false;\n }\n}\n","import { chmodSync, mkdirSync, rmSync } from 'node:fs';\nimport { chmod, mkdir, rm } from 'node:fs/promises';\nimport { __exists } from './__exists.js';\nimport type { FileMode } from './FileMode.js';\nimport { __toMode } from './__toMode.js';\nimport { __existsSync } from './__existsSync.js';\n\nexport interface DirectoryOptions {\n /**\n * Directory path\n */\n readonly path: string;\n\n /**\n * Directory target state\n */\n readonly state: 'present' | 'absent';\n\n /**\n * File permissions\n */\n readonly mode?: FileMode;\n}\n\n/**\n * Ensure directory is present/absent\n *\n * @example\n * ```ts\n * await directory({\n * path: 'foo/bar',\n * state: 'present',\n * mode: {\n * owner: { read: true, write: true, execute: true },\n * group: { read: true, write: true, execute: true },\n * other: { read: true, write: true, execute: true },\n * },\n * })\n * ```\n *\n * @param options\n */\nexport async function directory(options: DirectoryOptions): Promise<void> {\n const { path, state, mode } = options;\n const isPresent = await __exists(path);\n if (state === 'present') {\n const newMode = __toMode(mode);\n if (!isPresent) {\n await mkdir(path, { recursive: true, mode: newMode });\n }\n if (newMode != null && isPresent) {\n await chmod(path, newMode);\n }\n } else if (isPresent) {\n await rm(path, { recursive: true });\n }\n}\n\n/**\n * Ensure directory is present/absent\n *\n * @example\n * ```ts\n * directorySync({\n * path: 'foo/bar',\n * state: 'present',\n * mode: {\n * owner: { read: true, write: true, execute: true },\n * group: { read: true, write: true, execute: true },\n * other: { read: true, write: true, execute: true },\n * },\n * })\n * ```\n *\n * @param options\n */\nexport function directorySync(options: DirectoryOptions): void {\n const { path, state, mode } = options;\n const isPresent = __existsSync(path);\n if (state === 'present') {\n const newMode = __toMode(mode);\n if (!isPresent) {\n mkdirSync(path, { recursive: true, mode: newMode });\n }\n if (newMode != null && isPresent) {\n chmodSync(path, newMode);\n }\n } else if (isPresent) {\n rmSync(path, { recursive: true });\n }\n}\n","import { chmod, readFile, rm, writeFile } from 'node:fs/promises';\nimport { chmodSync, readFileSync, rmSync, writeFileSync } from 'node:fs';\nimport { __exists } from './__exists.js';\nimport { __existsSync } from './__existsSync.js';\nimport type { FileMode } from './FileMode.js';\nimport { __toMode } from './__toMode.js';\n\nexport interface FileOptions {\n /**\n * File path\n */\n readonly path: string;\n\n /**\n * File target state\n */\n readonly state: 'present' | 'absent';\n\n /**\n * File content mapping function\n *\n */\n readonly update?: ((content: string) => string | undefined) | undefined;\n\n /**\n * File encoding\n */\n readonly encoding?: BufferEncoding;\n\n /**\n * File permissions\n */\n readonly mode?: FileMode;\n}\n\n/**\n * Ensure file is present/absent with content initialized or modified with `update\n *\n * @example\n * ```ts\n * await file({\n * path: 'foo/bar',\n * state: 'present',\n * update: (content) => content + '_test', // This will append '_test' after current content\n * mode: {\n * owner: { read: true, write: true, execute: true },\n * group: { read: true, write: true, execute: true },\n * other: { read: true, write: true, execute: true },\n * },\n * })\n * ```\n *\n * @param options\n */\nexport async function file(options: FileOptions): Promise<void> {\n const { path, state, update, encoding = 'utf8', mode } = options;\n if (state === 'present') {\n const isPresent = await __exists(path);\n const previousContent = isPresent ? await readFile(path, encoding) : '';\n const newContent = update == null ? (isPresent ? undefined : '') : update(previousContent);\n const newMode = __toMode(mode);\n if (newContent != null) {\n await writeFile(path, newContent, { encoding, mode: newMode });\n }\n if (newMode != null && (isPresent || newContent != null)) {\n await chmod(path, newMode);\n }\n } else {\n await rm(path, { force: true });\n }\n}\n\n/**\n * Ensure file is present/absent with content initialized or modified with `update\n *\n * @example\n * ```ts\n * fileSync({\n * path: 'foo/bar',\n * state: 'present',\n * update: (content) => content + '_test', // This will append '_test' after current content\n * mode: {\n * owner: { read: true, write: true, execute: true },\n * group: { read: true, write: true, execute: true },\n * other: { read: true, write: true, execute: true },\n * },\n * })\n * ```\n *\n * @param options\n */\nexport function fileSync(options: FileOptions): void {\n const { path, state, update, encoding = 'utf8', mode } = options;\n if (state === 'present') {\n const isPresent = __existsSync(path);\n const previousContent = isPresent ? readFileSync(path, encoding) : '';\n const newContent = update == null ? (isPresent ? undefined : '') : update(previousContent);\n const newMode = __toMode(mode);\n if (newContent != null) {\n writeFileSync(path, newContent, { encoding, mode: newMode });\n }\n if (newMode != null && (isPresent || newContent != null)) {\n chmodSync(path, newMode);\n }\n } else {\n rmSync(path, { force: true });\n }\n}\n","import { type FileOptions, file, fileSync } from './file.js';\n\nexport interface BlockOptions {\n /**\n * The marker builder function that will take either `markerBegin` or `markerEnd`\n *\n * @default '# ${mark} MANAGED BLOCK'\n */\n marker?: (mark: 'Begin' | 'End') => string;\n\n /**\n * File path\n */\n path: string;\n\n /**\n * Block content to insert\n */\n block: string;\n\n /**\n * Insert position\n */\n insertPosition?: ['before', 'BeginningOfFile' | RegExp] | ['after', 'EndOfFile' | RegExp];\n\n /**\n * Block target state\n */\n state?: 'present' | 'absent';\n}\n\nconst EOF = 'EndOfFile';\nconst BOF = 'BeginningOfFile';\nconst insertAt = (str: string, index: number, toInsert: string) => str.slice(0, index) + toInsert + str.slice(index);\nconst matchLast = (string: string, regexp: RegExp) => {\n const matcher = new RegExp(regexp.source, `${regexp.flags}g`);\n let firstIndex = -1;\n let lastIndex = -1;\n let matches;\n\n while (true) {\n matches = matcher.exec(string);\n if (matches == null) {\n break;\n }\n firstIndex = matches.index;\n lastIndex = matcher.lastIndex;\n }\n return { firstIndex, lastIndex };\n};\n\nfunction toFileOptions(options: BlockOptions): FileOptions {\n const {\n marker = (mark) => `# ${mark.toUpperCase()} MANAGED BLOCK`,\n path,\n block: blockName,\n insertPosition = ['after', EOF],\n state = 'present',\n } = options;\n\n const EOL = '\\n';\n const beginBlock = marker('Begin');\n const endBlock = marker('End');\n\n /**\n * @param content\n */\n function findBlock(content: string) {\n const startIndex = content.indexOf(beginBlock);\n const endIndex = content.indexOf(endBlock) + endBlock.length;\n\n return {\n endIndex,\n exists: startIndex !== -1 && endIndex >= 0,\n startIndex,\n };\n }\n\n function apply(fullContent: string, blockContent: string) {\n const found = findBlock(fullContent);\n const remove = state === 'absent';\n const replaceBlock = remove ? '' : beginBlock + EOL + blockContent + EOL + endBlock;\n const [positionDirection, positionAnchor] = insertPosition;\n\n if (found.exists) {\n return fullContent.slice(0, found.startIndex) + replaceBlock + fullContent.slice(found.endIndex);\n }\n if (remove) {\n return fullContent;\n }\n switch (positionDirection) {\n case 'before': {\n if (positionAnchor !== BOF) {\n const { firstIndex } = matchLast(fullContent, positionAnchor);\n if (firstIndex >= 0) {\n return insertAt(fullContent, firstIndex, replaceBlock + EOL);\n }\n }\n\n // Beginning of file\n return replaceBlock + EOL + fullContent;\n }\n case 'after': {\n // insert\n if (positionAnchor !== EOF) {\n const { lastIndex } = matchLast(fullContent, positionAnchor);\n if (lastIndex >= 0) {\n return insertAt(fullContent, lastIndex, EOL + replaceBlock);\n }\n }\n\n // end of file\n return fullContent + EOL + replaceBlock;\n }\n\n default: {\n throw new Error(`Unsupported position ${String(positionDirection)}`);\n }\n }\n }\n\n return {\n path,\n state: 'present',\n update: (sourceContent) => apply(sourceContent, blockName),\n };\n}\n\n/**\n * Replace asynchronously a block in file that follows pattern :\n *\n * marker(markerBegin)\n * ...\n * marker(markerEnd)\n *\n * @param options\n */\nexport function block(options: BlockOptions) {\n return file(toFileOptions(options));\n}\n\n/**\n * Replace synchronously a block in file that follows pattern :\n *\n * marker(markerBegin)\n * ...\n * marker(markerEnd)\n *\n * @param options\n */\nexport function blockSync(options: BlockOptions) {\n return fileSync(toFileOptions(options));\n}\n","import { type FileOptions, file, fileSync } from './file.js';\n\nexport type JSONValue = null | number | string | boolean | JSONValue[] | { [key: string]: JSONValue };\n\nexport interface JSONOption<V = JSONValue> extends Omit<FileOptions, 'update'> {\n /**\n * File content mapping function\n */\n readonly update?: ((content: V | undefined) => V | undefined) | undefined;\n}\n\nfunction toFileOption<Value>({ update, ...otherOptions }: JSONOption<Value>): FileOptions {\n return {\n ...otherOptions,\n\n update:\n update == null\n ? update\n : (content) => {\n const jsonValue = content === '' ? undefined : (JSON.parse(content) as Value);\n\n return JSON.stringify(update(jsonValue));\n },\n };\n}\n\n/**\n * Ensure file is present/absent asynchronously with content value initialized or modified with `update`\n *\n * @param options\n */\nexport async function json<Value>(options: JSONOption<Value>): Promise<void> {\n return file(toFileOption(options));\n}\n\n/**\n * Ensure file is present/absent synchronously with content value initialized or modified with `update`\n *\n * @param options\n */\nexport function jsonSync<Value>(options: JSONOption<Value>): void {\n return fileSync(toFileOption(options));\n}\n","export const meta = Object.freeze({\n // @ts-ignore - these variables are injected at build time\n name: (typeof __PACKAGE_NAME__ === 'undefined' ? '' : __PACKAGE_NAME__) as string,\n // @ts-ignore - these variables are injected at build time\n version: (typeof __PACKAGE_VERSION__ === 'undefined' ? '' : __PACKAGE_VERSION__) as string,\n // @ts-ignore - these variables are injected at build time\n buildNumber: 1 as number, // (typeof __PACKAGE_BUILD_NUMBER__ === 'undefined' ? 0 : __PACKAGE_BUILD_NUMBER__) as number,\n});\n","import { spawn, spawnSync } from 'node:child_process';\n\nexport interface ExecOptions {\n /**\n * Current working directory\n */\n cwd?: string;\n\n /**\n * Stdio options\n */\n stdio?: 'inherit' | 'pipe' | 'ignore';\n}\n\n/**\n * Runs a command in a shell and returns a promise that resolves with an object\n * containing the stdout and stderr strings.\n *\n * @param command The command to run\n * @param args The arguments to pass to the command\n * @param options\n * @returns A promise that resolves with an object like `{ stdout: string, stderr: string }`\n */\nexport function execSync(\n command: string,\n args: ReadonlyArray<string>,\n options?: ExecOptions,\n): { stdout: string; stderr: string } {\n const result = spawnSync(command, args, { ...options });\n const encoding = 'utf8';\n\n return { stdout: result.stdout.toString(encoding), stderr: result.stderr.toString(encoding) };\n}\n\n/**\n * Runs a command in a shell and returns a promise that resolves with an object\n * containing the stdout and stderr strings.\n *\n * @param command The command to run\n * @param args The arguments to pass to the command\n * @param options\n */\nexport async function exec(\n command: string,\n args: ReadonlyArray<string>,\n options?: ExecOptions,\n): Promise<{ stdout: string; stderr: string }> {\n return new Promise((resolve, reject) => {\n const encoding = 'utf8';\n const child = spawn(command, args, { ...options });\n let stdout = '';\n let stderr = '';\n\n // Capture the stdout and stderr streams\n if (child.stdout != null) {\n child.stdout.on('data', (data) => {\n stdout += data.toString(encoding);\n });\n }\n if (child.stderr != null) {\n child.stderr.on('data', (data) => {\n stderr += data.toString(encoding);\n });\n }\n // Handle process exit\n child.on('close', (_code) => {\n resolve({ stdout, stderr });\n });\n\n // Handle errors\n child.on('error', reject);\n });\n}\n","import { exec, execSync } from './exec.js';\n\nexport interface YarnConfigOptions {\n /**\n * Configuration key\n */\n readonly key: string;\n\n /**\n * Option target state\n */\n readonly state: 'present' | 'absent';\n\n /**\n * File content mapping function\n *\n */\n readonly update?: ((content: string) => string | undefined) | undefined;\n}\n\n/**\n * Synchronous version of {@link yarnConfig}\n *\n * @param options\n * @example\n * yarnConfigSync({\n * key: 'nodeLinker',\n * state: 'present',\n * update: (content) => content.replace('node-modules', 'hoisted'),\n * })\n */\nexport function yarnConfigSync(options: YarnConfigOptions) {\n const { key, state, update } = options;\n if (state === 'present') {\n const { stdout } = execSync('yarn', ['config', 'get', String(key)]);\n execSync('yarn', ['config', 'set', String(key), `${update == null ? '' : update(stdout)}`]);\n } else {\n execSync('yarn', ['config', 'unset']);\n }\n}\n\n/**\n * Set/Unset yarn configuration value\n *\n * @param options\n * @example\n * await yarnConfig({\n * key: 'nodeLinker',\n * state: 'present',\n * update: (content) => content.replace('node-modules', 'hoisted'),\n * })\n */\nexport async function yarnConfig(options: YarnConfigOptions): Promise<void> {\n const { key, state, update } = options;\n if (state === 'present') {\n const { stdout } = await exec('yarn', ['config', 'get', String(key)]);\n await exec('yarn', ['config', 'set', String(key), `${update == null ? '' : update(stdout)}`]);\n } else {\n await exec('yarn', ['config', 'unset']);\n }\n}\n","import { exec, execSync } from './exec.js';\n\nexport type YarnVersionKind = 'berry' | 'classic';\n\nexport interface YarnVersionOptions {\n /**\n * Option target state\n */\n readonly state: 'present' | 'absent';\n\n /**\n * Version mapping function\n *\n */\n readonly update?: (() => YarnVersionKind | undefined) | undefined;\n}\n\n/**\n * Synchronous version of {@link yarnVersion}\n *\n * @param options\n * @example\n * yarnVersionSync({\n * state: 'present',\n * update: () => 'berry', // or 'classic'\n * })\n */\nexport function yarnVersionSync(options: YarnVersionOptions) {\n const { state, update } = options;\n if (state === 'present') {\n execSync('yarn', ['set', 'version', `${update == null ? 'berry' : update()}`]);\n } else {\n // TODO: remove yarn.lock\n throw new Error('Not implemented');\n }\n}\n\n/**\n * Set/Unset yarn configuration value\n *\n * @param options\n * @example\n * await yarnVersion({\n * state: 'present',\n * update: () => 'berry', // or 'classic'\n * })\n */\nexport async function yarnVersion(options: YarnVersionOptions): Promise<void> {\n const { state, update } = options;\n if (state === 'present') {\n await exec('yarn', ['set', 'version', `${update == null ? 'berry' : update()}`]);\n } else {\n // TODO: remove yarn.lock\n throw new Error('Not implemented');\n }\n}\n"],"mappings":";;;;AAGA,eAAsB,SAAS,MAAc;CAC3C,IAAI;EACF,MAAM,OAAO,MAAM,UAAU,KAAK;EAClC,OAAO;SACD;EACN,OAAO;;;;;ACNX,SAAS,WAAW,eAA8C,MAAc,OAAe,SAAyB;CACtH,QACG,eAAe,SAAS,OAAO,OAAO,MACpC,eAAe,UAAU,OAAO,QAAQ,MACxC,eAAe,YAAY,OAAO,UAAU;;AAInD,SAAgB,SAAS,MAAgD;CACvE,OAAO,QAAQ,OACX,OAEE,WAAW,KAAK,OAAO,KAAO,KAAO,GAAM,GACzC,WAAW,KAAK,OAAO,IAAO,IAAO,EAAM,GAC3C,WAAW,KAAK,OAAO,GAAO,GAAO,EAAM;;;;ACdrD,SAAgB,aAAa,MAAc;CACzC,IAAI;EACF,WAAW,MAAM,UAAU,KAAK;EAChC,OAAO;SACD;EACN,OAAO;;;;;;;;;;;;;;;;;;;;;;;ACmCX,eAAsB,UAAU,SAA0C;CACxE,MAAM,EAAE,MAAM,OAAO,SAAS;CAC9B,MAAM,YAAY,MAAM,SAAS,KAAK;CACtC,IAAI,UAAU,WAAW;EACvB,MAAM,UAAU,SAAS,KAAK;EAC9B,IAAI,CAAC,WACH,MAAM,MAAM,MAAM;GAAE,WAAW;GAAM,MAAM;GAAS,CAAC;EAEvD,IAAI,WAAW,QAAQ,WACrB,MAAM,MAAM,MAAM,QAAQ;QAEvB,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,QAAQ;GAAC;GAAU;GAAO,OAAO,IAAI;GAAE,GAAG,UAAU,OAAO,KAAK,OAAO,OAAO;GAAG,CAAC;QAE7F,MAAM,KAAK,QAAQ,CAAC,UAAU,QAAQ,CAAC;;;;;;;;;;;;;;AC/B3C,SAAgB,gBAAgB,SAA6B;CAC3D,MAAM,EAAE,OAAO,WAAW;CAC1B,IAAI,UAAU,WACZ,SAAS,QAAQ;EAAC;EAAO;EAAW,GAAG,UAAU,OAAO,UAAU,QAAQ;EAAG,CAAC;MAG9E,MAAM,IAAI,MAAM,kBAAkB;;;;;;;;;;;;AActC,eAAsB,YAAY,SAA4C;CAC5E,MAAM,EAAE,OAAO,WAAW;CAC1B,IAAI,UAAU,WACZ,MAAM,KAAK,QAAQ;EAAC;EAAO;EAAW,GAAG,UAAU,OAAO,UAAU,QAAQ;EAAG,CAAC;MAGhF,MAAM,IAAI,MAAM,kBAAkB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@w5s/configurator-core",
|
|
3
|
+
"version": "1.0.0-alpha.1",
|
|
4
|
+
"description": "Core library for @w5s/configurator-core",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"config",
|
|
7
|
+
"configurator",
|
|
8
|
+
"file",
|
|
9
|
+
"json"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/w5s/project-config/blob/main/packages/configurator-core#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/w5s/project-config/issues"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git@github.com:w5s/project-config.git",
|
|
18
|
+
"directory": "packages/configurator-core"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"author": "Julien Polo <julien.polo@gmail.com>",
|
|
22
|
+
"type": "module",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"require": {
|
|
26
|
+
"types": "./dist/index.d.cts",
|
|
27
|
+
"default": "./dist/index.cjs"
|
|
28
|
+
},
|
|
29
|
+
"import": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"default": "./dist/index.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"./dist/*": "./dist/*"
|
|
35
|
+
},
|
|
36
|
+
"typings": "./index.d.ts",
|
|
37
|
+
"files": [
|
|
38
|
+
"dist/",
|
|
39
|
+
"src/",
|
|
40
|
+
"index.js",
|
|
41
|
+
"index.d.ts",
|
|
42
|
+
"!*.d.ts.map",
|
|
43
|
+
"!**/*.spec.*",
|
|
44
|
+
"!**/__tests__/**"
|
|
45
|
+
],
|
|
46
|
+
"scripts": {
|
|
47
|
+
"postpack": "clean-package restore"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {},
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=22.0.0"
|
|
52
|
+
},
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public"
|
|
55
|
+
},
|
|
56
|
+
"sideEffect": false,
|
|
57
|
+
"gitHead": "38cf5f5877af4c8a1c292b9b7039c5a11863fc00"
|
|
58
|
+
}
|
package/src/FileMode.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface FilePermissionSet {
|
|
2
|
+
/**
|
|
3
|
+
* Read permission
|
|
4
|
+
*/
|
|
5
|
+
readonly read?: boolean;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Write permission
|
|
9
|
+
*/
|
|
10
|
+
readonly write?: boolean;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Execute permission
|
|
14
|
+
*/
|
|
15
|
+
readonly execute?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface FileMode {
|
|
19
|
+
/**
|
|
20
|
+
* Owner permissions
|
|
21
|
+
*/
|
|
22
|
+
readonly owner?: FilePermissionSet;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Group permissions
|
|
26
|
+
*/
|
|
27
|
+
readonly group?: FilePermissionSet;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Other permissions
|
|
31
|
+
*/
|
|
32
|
+
readonly other?: FilePermissionSet;
|
|
33
|
+
}
|
package/src/__exists.ts
ADDED
package/src/__toMode.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { FileMode, FilePermissionSet } from './FileMode.js';
|
|
2
|
+
|
|
3
|
+
function toModeFlag(permissionSet: FilePermissionSet | undefined, read: number, write: number, execute: number): number {
|
|
4
|
+
return (
|
|
5
|
+
(permissionSet?.read === true ? read : 0)
|
|
6
|
+
| (permissionSet?.write === true ? write : 0)
|
|
7
|
+
| (permissionSet?.execute === true ? execute : 0)
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function __toMode(mode: FileMode | undefined): number | undefined {
|
|
12
|
+
return mode == null
|
|
13
|
+
? mode
|
|
14
|
+
: (
|
|
15
|
+
toModeFlag(mode.owner, 0o400, 0o200, 0o100)
|
|
16
|
+
| toModeFlag(mode.group, 0o040, 0o020, 0o010)
|
|
17
|
+
| toModeFlag(mode.other, 0o004, 0o002, 0o001)
|
|
18
|
+
);
|
|
19
|
+
}
|