@w5s/configurator-core 1.0.0-alpha.1 → 1.0.0-alpha.2
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/index.cjs +45 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +36 -1
- package/dist/index.d.ts +36 -1
- package/dist/index.js +44 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/ignoreFile.ts +58 -0
- package/src/index.ts +1 -0
- package/dist/index.d.cts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -251,6 +251,48 @@ function blockSync(options) {
|
|
|
251
251
|
return fileSync(toFileOptions(options));
|
|
252
252
|
}
|
|
253
253
|
//#endregion
|
|
254
|
+
//#region src/ignoreFile.ts
|
|
255
|
+
function toFileOption$1({ update, ...otherOptions }) {
|
|
256
|
+
return {
|
|
257
|
+
...otherOptions,
|
|
258
|
+
update: update == null ? update : (content) => {
|
|
259
|
+
const eol = content.includes("\r\n") ? "\r\n" : "\n";
|
|
260
|
+
const updatedLines = update(content === "" ? void 0 : content.split(eol));
|
|
261
|
+
return updatedLines == null ? void 0 : updatedLines.join(eol);
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Ensure file is present/absent asynchronously with content initialized or modified by line.
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* ```ts
|
|
270
|
+
* await ignoreFile({
|
|
271
|
+
* path: '.gitignore',
|
|
272
|
+
* update: (lines) => [...(lines ?? []), 'dist'],
|
|
273
|
+
* });
|
|
274
|
+
* ```
|
|
275
|
+
* @param options File target options.
|
|
276
|
+
*/
|
|
277
|
+
async function ignoreFile(options) {
|
|
278
|
+
return file(toFileOption$1(options));
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Ensure file is present/absent synchronously with content initialized or modified by line.
|
|
282
|
+
*
|
|
283
|
+
* @example
|
|
284
|
+
* ```ts
|
|
285
|
+
* ignoreFileSync({
|
|
286
|
+
* path: '.gitignore',
|
|
287
|
+
* update: (lines) => [...(lines ?? []), 'dist'],
|
|
288
|
+
* });
|
|
289
|
+
* ```
|
|
290
|
+
* @param options File target options.
|
|
291
|
+
*/
|
|
292
|
+
function ignoreFileSync(options) {
|
|
293
|
+
return fileSync(toFileOption$1(options));
|
|
294
|
+
}
|
|
295
|
+
//#endregion
|
|
254
296
|
//#region src/json.ts
|
|
255
297
|
function toFileOption({ update, ...otherOptions }) {
|
|
256
298
|
return {
|
|
@@ -281,7 +323,7 @@ function jsonSync(options) {
|
|
|
281
323
|
//#region src/meta.ts
|
|
282
324
|
const meta = Object.freeze({
|
|
283
325
|
name: "@w5s/configurator-core",
|
|
284
|
-
version: "1.0.0-alpha.
|
|
326
|
+
version: "1.0.0-alpha.2",
|
|
285
327
|
buildNumber: 1
|
|
286
328
|
});
|
|
287
329
|
//#endregion
|
|
@@ -435,6 +477,8 @@ exports.directory = directory;
|
|
|
435
477
|
exports.directorySync = directorySync;
|
|
436
478
|
exports.file = file;
|
|
437
479
|
exports.fileSync = fileSync;
|
|
480
|
+
exports.ignoreFile = ignoreFile;
|
|
481
|
+
exports.ignoreFileSync = ignoreFileSync;
|
|
438
482
|
exports.json = json;
|
|
439
483
|
exports.jsonSync = jsonSync;
|
|
440
484
|
exports.meta = meta;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["constants","constants"],"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,OAAA,GAAA,iBAAA,QAAa,MAAMA,QAAAA,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,W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,QAAQ;EAAC;EAAO;EAAW,GAAG,UAAU,OAAO,UAAU,QAAQ;EAAG,CAAC;MAGhF,MAAM,IAAI,MAAM,kBAAkB"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["constants","constants","toFileOption"],"sources":["../src/__exists.ts","../src/__toMode.ts","../src/__existsSync.ts","../src/directory.ts","../src/file.ts","../src/block.ts","../src/ignoreFile.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 interface IgnoreFileOptions extends Omit<FileOptions, 'update'> {\n /**\n * File content mapping function where content is represented as lines.\n * When the file does not yet exist, the callback receives `undefined`.\n */\n readonly update?: ((content: string[] | undefined) => string[] | undefined) | undefined;\n}\n\nfunction toFileOption({ update, ...otherOptions }: IgnoreFileOptions): FileOptions {\n return {\n ...otherOptions,\n\n update:\n update == null\n ? update\n : (content) => {\n const eol = content.includes('\\r\\n') ? '\\r\\n' : '\\n';\n const lines = content === '' ? undefined : content.split(eol);\n const updatedLines = update(lines);\n\n return updatedLines == null ? undefined : updatedLines.join(eol);\n },\n };\n}\n\n/**\n * Ensure file is present/absent asynchronously with content initialized or modified by line.\n *\n * @example\n * ```ts\n * await ignoreFile({\n * path: '.gitignore',\n * update: (lines) => [...(lines ?? []), 'dist'],\n * });\n * ```\n * @param options File target options.\n */\nexport async function ignoreFile(options: IgnoreFileOptions): Promise<void> {\n return file(toFileOption(options));\n}\n\n/**\n * Ensure file is present/absent synchronously with content initialized or modified by line.\n *\n * @example\n * ```ts\n * ignoreFileSync({\n * path: '.gitignore',\n * update: (lines) => [...(lines ?? []), 'dist'],\n * });\n * ```\n * @param options File target options.\n */\nexport function ignoreFileSync(options: IgnoreFileOptions): void {\n return fileSync(toFileOption(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,OAAA,GAAA,iBAAA,QAAa,MAAMA,QAAAA,UAAU,IAAI;EACjC,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;;;ACRA,SAAS,WAAW,eAA8C,MAAc,OAAe,SAAyB;CACtH,QACG,eAAe,SAAS,OAAO,OAAO,MACpC,eAAe,UAAU,OAAO,QAAQ,MACxC,eAAe,YAAY,OAAO,UAAU;AAEnD;AAEA,SAAgB,SAAS,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AQ,CAAC,UAAU,OAAO,CAAC;AAExC;;;;;;;;;;;;AAaA,eAAsB,WAAW,SAA2C;CAC1E,MAAM,EAAE,KAAK,OAAO,WAAW;CAC/B,IAAI,UAAU,WAAW;EACvB,MAAM,EAAE,WAAW,MAAM,KAAK,QAAQ;GAAC;GAAU;GAAO,OAAO,GAAG;EAAC,CAAC;EACpE,MAAM,KAAK,QAAQ;GAAC;GAAU;GAAO,OAAO,GAAG;GAAG,GAAG,UAAU,OAAO,KAAK,OAAO,MAAM;EAAG,CAAC;CAC9F,OACE,MAAM,KAAK,QAAQ,CAAC,UAAU,OAAO,CAAC;AAE1C;;;;;;;;;;;;;ACjCA,SAAgB,gBAAgB,SAA6B;CAC3D,MAAM,EAAE,OAAO,WAAW;CAC1B,IAAI,UAAU,WACZ,SAAS,QAAQ;EAAC;EAAO;EAAW,GAAG,UAAU,OAAO,UAAU,OAAO;CAAG,CAAC;MAG7E,MAAM,IAAI,MAAM,iBAAiB;AAErC;;;;;;;;;;;AAYA,eAAsB,YAAY,SAA4C;CAC5E,MAAM,EAAE,OAAO,WAAW;CAC1B,IAAI,UAAU,WACZ,MAAM,KAAK,QAAQ;EAAC;EAAO;EAAW,GAAG,UAAU,OAAO,UAAU,OAAO;CAAG,CAAC;MAG/E,MAAM,IAAI,MAAM,iBAAiB;AAErC"}
|
package/dist/index.d.cts
CHANGED
|
@@ -193,6 +193,41 @@ declare function file(options: FileOptions): Promise<void>;
|
|
|
193
193
|
*/
|
|
194
194
|
declare function fileSync(options: FileOptions): void;
|
|
195
195
|
//#endregion
|
|
196
|
+
//#region src/ignoreFile.d.ts
|
|
197
|
+
interface IgnoreFileOptions extends Omit<FileOptions, 'update'> {
|
|
198
|
+
/**
|
|
199
|
+
* File content mapping function where content is represented as lines.
|
|
200
|
+
* When the file does not yet exist, the callback receives `undefined`.
|
|
201
|
+
*/
|
|
202
|
+
readonly update?: ((content: string[] | undefined) => string[] | undefined) | undefined;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Ensure file is present/absent asynchronously with content initialized or modified by line.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```ts
|
|
209
|
+
* await ignoreFile({
|
|
210
|
+
* path: '.gitignore',
|
|
211
|
+
* update: (lines) => [...(lines ?? []), 'dist'],
|
|
212
|
+
* });
|
|
213
|
+
* ```
|
|
214
|
+
* @param options File target options.
|
|
215
|
+
*/
|
|
216
|
+
declare function ignoreFile(options: IgnoreFileOptions): Promise<void>;
|
|
217
|
+
/**
|
|
218
|
+
* Ensure file is present/absent synchronously with content initialized or modified by line.
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```ts
|
|
222
|
+
* ignoreFileSync({
|
|
223
|
+
* path: '.gitignore',
|
|
224
|
+
* update: (lines) => [...(lines ?? []), 'dist'],
|
|
225
|
+
* });
|
|
226
|
+
* ```
|
|
227
|
+
* @param options File target options.
|
|
228
|
+
*/
|
|
229
|
+
declare function ignoreFileSync(options: IgnoreFileOptions): void;
|
|
230
|
+
//#endregion
|
|
196
231
|
//#region src/json.d.ts
|
|
197
232
|
type JSONValue = null | number | string | boolean | JSONValue[] | {
|
|
198
233
|
[key: string]: JSONValue;
|
|
@@ -300,5 +335,5 @@ declare function yarnVersionSync(options: YarnVersionOptions): void;
|
|
|
300
335
|
*/
|
|
301
336
|
declare function yarnVersion(options: YarnVersionOptions): Promise<void>;
|
|
302
337
|
//#endregion
|
|
303
|
-
export { BlockOptions, DirectoryOptions, FileOptions, JSONOption, JSONValue, YarnConfigOptions, YarnVersionKind, YarnVersionOptions, block, blockSync, directory, directorySync, file, fileSync, json, jsonSync, meta, yarnConfig, yarnConfigSync, yarnVersion, yarnVersionSync };
|
|
338
|
+
export { BlockOptions, DirectoryOptions, FileOptions, IgnoreFileOptions, JSONOption, JSONValue, YarnConfigOptions, YarnVersionKind, YarnVersionOptions, block, blockSync, directory, directorySync, file, fileSync, ignoreFile, ignoreFileSync, json, jsonSync, meta, yarnConfig, yarnConfigSync, yarnVersion, yarnVersionSync };
|
|
304
339
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -193,6 +193,41 @@ declare function file(options: FileOptions): Promise<void>;
|
|
|
193
193
|
*/
|
|
194
194
|
declare function fileSync(options: FileOptions): void;
|
|
195
195
|
//#endregion
|
|
196
|
+
//#region src/ignoreFile.d.ts
|
|
197
|
+
interface IgnoreFileOptions extends Omit<FileOptions, 'update'> {
|
|
198
|
+
/**
|
|
199
|
+
* File content mapping function where content is represented as lines.
|
|
200
|
+
* When the file does not yet exist, the callback receives `undefined`.
|
|
201
|
+
*/
|
|
202
|
+
readonly update?: ((content: string[] | undefined) => string[] | undefined) | undefined;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Ensure file is present/absent asynchronously with content initialized or modified by line.
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```ts
|
|
209
|
+
* await ignoreFile({
|
|
210
|
+
* path: '.gitignore',
|
|
211
|
+
* update: (lines) => [...(lines ?? []), 'dist'],
|
|
212
|
+
* });
|
|
213
|
+
* ```
|
|
214
|
+
* @param options File target options.
|
|
215
|
+
*/
|
|
216
|
+
declare function ignoreFile(options: IgnoreFileOptions): Promise<void>;
|
|
217
|
+
/**
|
|
218
|
+
* Ensure file is present/absent synchronously with content initialized or modified by line.
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```ts
|
|
222
|
+
* ignoreFileSync({
|
|
223
|
+
* path: '.gitignore',
|
|
224
|
+
* update: (lines) => [...(lines ?? []), 'dist'],
|
|
225
|
+
* });
|
|
226
|
+
* ```
|
|
227
|
+
* @param options File target options.
|
|
228
|
+
*/
|
|
229
|
+
declare function ignoreFileSync(options: IgnoreFileOptions): void;
|
|
230
|
+
//#endregion
|
|
196
231
|
//#region src/json.d.ts
|
|
197
232
|
type JSONValue = null | number | string | boolean | JSONValue[] | {
|
|
198
233
|
[key: string]: JSONValue;
|
|
@@ -300,5 +335,5 @@ declare function yarnVersionSync(options: YarnVersionOptions): void;
|
|
|
300
335
|
*/
|
|
301
336
|
declare function yarnVersion(options: YarnVersionOptions): Promise<void>;
|
|
302
337
|
//#endregion
|
|
303
|
-
export { BlockOptions, DirectoryOptions, FileOptions, JSONOption, JSONValue, YarnConfigOptions, YarnVersionKind, YarnVersionOptions, block, blockSync, directory, directorySync, file, fileSync, json, jsonSync, meta, yarnConfig, yarnConfigSync, yarnVersion, yarnVersionSync };
|
|
338
|
+
export { BlockOptions, DirectoryOptions, FileOptions, IgnoreFileOptions, JSONOption, JSONValue, YarnConfigOptions, YarnVersionKind, YarnVersionOptions, block, blockSync, directory, directorySync, file, fileSync, ignoreFile, ignoreFileSync, json, jsonSync, meta, yarnConfig, yarnConfigSync, yarnVersion, yarnVersionSync };
|
|
304
339
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -250,6 +250,48 @@ function blockSync(options) {
|
|
|
250
250
|
return fileSync(toFileOptions(options));
|
|
251
251
|
}
|
|
252
252
|
//#endregion
|
|
253
|
+
//#region src/ignoreFile.ts
|
|
254
|
+
function toFileOption$1({ update, ...otherOptions }) {
|
|
255
|
+
return {
|
|
256
|
+
...otherOptions,
|
|
257
|
+
update: update == null ? update : (content) => {
|
|
258
|
+
const eol = content.includes("\r\n") ? "\r\n" : "\n";
|
|
259
|
+
const updatedLines = update(content === "" ? void 0 : content.split(eol));
|
|
260
|
+
return updatedLines == null ? void 0 : updatedLines.join(eol);
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Ensure file is present/absent asynchronously with content initialized or modified by line.
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* ```ts
|
|
269
|
+
* await ignoreFile({
|
|
270
|
+
* path: '.gitignore',
|
|
271
|
+
* update: (lines) => [...(lines ?? []), 'dist'],
|
|
272
|
+
* });
|
|
273
|
+
* ```
|
|
274
|
+
* @param options File target options.
|
|
275
|
+
*/
|
|
276
|
+
async function ignoreFile(options) {
|
|
277
|
+
return file(toFileOption$1(options));
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Ensure file is present/absent synchronously with content initialized or modified by line.
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* ```ts
|
|
284
|
+
* ignoreFileSync({
|
|
285
|
+
* path: '.gitignore',
|
|
286
|
+
* update: (lines) => [...(lines ?? []), 'dist'],
|
|
287
|
+
* });
|
|
288
|
+
* ```
|
|
289
|
+
* @param options File target options.
|
|
290
|
+
*/
|
|
291
|
+
function ignoreFileSync(options) {
|
|
292
|
+
return fileSync(toFileOption$1(options));
|
|
293
|
+
}
|
|
294
|
+
//#endregion
|
|
253
295
|
//#region src/json.ts
|
|
254
296
|
function toFileOption({ update, ...otherOptions }) {
|
|
255
297
|
return {
|
|
@@ -280,7 +322,7 @@ function jsonSync(options) {
|
|
|
280
322
|
//#region src/meta.ts
|
|
281
323
|
const meta = Object.freeze({
|
|
282
324
|
name: "@w5s/configurator-core",
|
|
283
|
-
version: "1.0.0-alpha.
|
|
325
|
+
version: "1.0.0-alpha.2",
|
|
284
326
|
buildNumber: 1
|
|
285
327
|
});
|
|
286
328
|
//#endregion
|
|
@@ -428,6 +470,6 @@ async function yarnVersion(options) {
|
|
|
428
470
|
else throw new Error("Not implemented");
|
|
429
471
|
}
|
|
430
472
|
//#endregion
|
|
431
|
-
export { block, blockSync, directory, directorySync, file, fileSync, json, jsonSync, meta, yarnConfig, yarnConfigSync, yarnVersion, yarnVersionSync };
|
|
473
|
+
export { block, blockSync, directory, directorySync, file, fileSync, ignoreFile, ignoreFileSync, json, jsonSync, meta, yarnConfig, yarnConfigSync, yarnVersion, yarnVersionSync };
|
|
432
474
|
|
|
433
475
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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;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;EAAC;EAAO;EAAW,GAAG,UAAU,OAAO,UAAU,QAAQ;EAAG,CAAC;MAGhF,MAAM,IAAI,MAAM,kBAAkB"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["toFileOption"],"sources":["../src/__exists.ts","../src/__toMode.ts","../src/__existsSync.ts","../src/directory.ts","../src/file.ts","../src/block.ts","../src/ignoreFile.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 interface IgnoreFileOptions extends Omit<FileOptions, 'update'> {\n /**\n * File content mapping function where content is represented as lines.\n * When the file does not yet exist, the callback receives `undefined`.\n */\n readonly update?: ((content: string[] | undefined) => string[] | undefined) | undefined;\n}\n\nfunction toFileOption({ update, ...otherOptions }: IgnoreFileOptions): FileOptions {\n return {\n ...otherOptions,\n\n update:\n update == null\n ? update\n : (content) => {\n const eol = content.includes('\\r\\n') ? '\\r\\n' : '\\n';\n const lines = content === '' ? undefined : content.split(eol);\n const updatedLines = update(lines);\n\n return updatedLines == null ? undefined : updatedLines.join(eol);\n },\n };\n}\n\n/**\n * Ensure file is present/absent asynchronously with content initialized or modified by line.\n *\n * @example\n * ```ts\n * await ignoreFile({\n * path: '.gitignore',\n * update: (lines) => [...(lines ?? []), 'dist'],\n * });\n * ```\n * @param options File target options.\n */\nexport async function ignoreFile(options: IgnoreFileOptions): Promise<void> {\n return file(toFileOption(options));\n}\n\n/**\n * Ensure file is present/absent synchronously with content initialized or modified by line.\n *\n * @example\n * ```ts\n * ignoreFileSync({\n * path: '.gitignore',\n * update: (lines) => [...(lines ?? []), 'dist'],\n * });\n * ```\n * @param options File target options.\n */\nexport function ignoreFileSync(options: IgnoreFileOptions): void {\n return fileSync(toFileOption(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,IAAI;EACjC,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;;;ACRA,SAAS,WAAW,eAA8C,MAAc,OAAe,SAAyB;CACtH,QACG,eAAe,SAAS,OAAO,OAAO,MACpC,eAAe,UAAU,OAAO,QAAQ,MACxC,eAAe,YAAY,OAAO,UAAU;AAEnD;AAEA,SAAgB,SAAS,MAAgD;CACvE,OAAO,QAAQ,OACX,OAEE,W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,OAAO,MAAM;EAAG,CAAC;CAC9F,OACE,MAAM,KAAK,QAAQ,CAAC,UAAU,OAAO,CAAC;AAE1C;;;;;;;;;;;;;ACjCA,SAAgB,gBAAgB,SAA6B;CAC3D,MAAM,EAAE,OAAO,WAAW;CAC1B,IAAI,UAAU,WACZ,SAAS,QAAQ;EAAC;EAAO;EAAW,GAAG,UAAU,OAAO,UAAU,OAAO;CAAG,CAAC;MAG7E,MAAM,IAAI,MAAM,iBAAiB;AAErC;;;;;;;;;;;AAYA,eAAsB,YAAY,SAA4C;CAC5E,MAAM,EAAE,OAAO,WAAW;CAC1B,IAAI,UAAU,WACZ,MAAM,KAAK,QAAQ;EAAC;EAAO;EAAW,GAAG,UAAU,OAAO,UAAU,OAAO;CAAG,CAAC;MAG/E,MAAM,IAAI,MAAM,iBAAiB;AAErC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@w5s/configurator-core",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.2",
|
|
4
4
|
"description": "Core library for @w5s/configurator-core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"config",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
|
17
|
-
"url": "git@github.com:w5s/project-config.git",
|
|
17
|
+
"url": "git+ssh@github.com:w5s/project-config.git",
|
|
18
18
|
"directory": "packages/configurator-core"
|
|
19
19
|
},
|
|
20
20
|
"license": "MIT",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
56
|
"sideEffect": false,
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "ab7987a57772b2e7fb3ef7eb4cadb3cedd9cc9ae"
|
|
58
58
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type FileOptions, file, fileSync } from './file.js';
|
|
2
|
+
|
|
3
|
+
export interface IgnoreFileOptions extends Omit<FileOptions, 'update'> {
|
|
4
|
+
/**
|
|
5
|
+
* File content mapping function where content is represented as lines.
|
|
6
|
+
* When the file does not yet exist, the callback receives `undefined`.
|
|
7
|
+
*/
|
|
8
|
+
readonly update?: ((content: string[] | undefined) => string[] | undefined) | undefined;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function toFileOption({ update, ...otherOptions }: IgnoreFileOptions): FileOptions {
|
|
12
|
+
return {
|
|
13
|
+
...otherOptions,
|
|
14
|
+
|
|
15
|
+
update:
|
|
16
|
+
update == null
|
|
17
|
+
? update
|
|
18
|
+
: (content) => {
|
|
19
|
+
const eol = content.includes('\r\n') ? '\r\n' : '\n';
|
|
20
|
+
const lines = content === '' ? undefined : content.split(eol);
|
|
21
|
+
const updatedLines = update(lines);
|
|
22
|
+
|
|
23
|
+
return updatedLines == null ? undefined : updatedLines.join(eol);
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Ensure file is present/absent asynchronously with content initialized or modified by line.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* await ignoreFile({
|
|
34
|
+
* path: '.gitignore',
|
|
35
|
+
* update: (lines) => [...(lines ?? []), 'dist'],
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
* @param options File target options.
|
|
39
|
+
*/
|
|
40
|
+
export async function ignoreFile(options: IgnoreFileOptions): Promise<void> {
|
|
41
|
+
return file(toFileOption(options));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Ensure file is present/absent synchronously with content initialized or modified by line.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* ignoreFileSync({
|
|
50
|
+
* path: '.gitignore',
|
|
51
|
+
* update: (lines) => [...(lines ?? []), 'dist'],
|
|
52
|
+
* });
|
|
53
|
+
* ```
|
|
54
|
+
* @param options File target options.
|
|
55
|
+
*/
|
|
56
|
+
export function ignoreFileSync(options: IgnoreFileOptions): void {
|
|
57
|
+
return fileSync(toFileOption(options));
|
|
58
|
+
}
|
package/src/index.ts
CHANGED
package/dist/index.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/FileMode.ts","../src/directory.ts","../src/block.ts","../src/file.ts","../src/json.ts","../src/meta.ts","../src/yarnConfig.ts","../src/yarnVersion.ts"],"mappings":";UAAiB,iBAAA;EAAA;;;EAAA,SAIN,IAAA;EAAA;;;EAAA,SAKA,KAAA;EAKO;AAGlB;;EAHkB,SAAP,OAAA;AAAA;AAAA,UAGM,QAAA;EAcE;;;EAAA,SAVR,KAAA,GAAQ,iBAAA;EAAA;;;EAAA,SAKR,KAAA,GAAQ,iBAAA;EAKA;;;EAAA,SAAR,KAAA,GAAQ,iBAAA;AAAA;;;UCxBF,gBAAA;EDPiB;;;EAAA,SCWvB,IAAA;EDFA;;;EAAA,SCOA,KAAA;EDCM;;;EAAA,SCIN,IAAA,GAAO,QAAA;AAAA;;;;;;;;;;;;;;;AAdlB;;;;iBAmCsB,SAAA,CAAU,OAAA,EAAS,gBAAA,GAAmB,OAAA;;;;;;AAA5D;;;;;;;;;AAkCA;;;;iBAAgB,aAAA,CAAc,OAAA,EAAS,gBAAA;;;UC1EtB,YAAA;EFFA;;;;;EEQf,MAAA,IAAU,IAAA;EFMD;;;EEDT,IAAA;EFIuB;;;EECvB,KAAA;EFaiB;;;EERjB,cAAA,kCAAgD,MAAA,4BAAkC,MAAA;EFFjE;;;EEOjB,KAAA;AAAA;;;;;;ADrBF;;;;iBCkIgB,KAAA,CAAM,OAAA,EAAS,YAAA,GAAY,OAAA;;;;;;AD/F3C;;;;iBC4GgB,SAAA,CAAU,OAAA,EAAS,YAAA;;;UC/IlB,WAAA;EHPiB;;;EAAA,SGWvB,IAAA;EHFA;;;EAAA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