@w5s/dev 2.2.7 → 2.2.11
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 +332 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +299 -0
- package/dist/index.d.ts +299 -8
- package/dist/index.js +320 -22
- package/dist/index.js.map +1 -1
- package/package.json +13 -4
- package/dist/block.d.ts +0 -45
- package/dist/block.js +0 -110
- package/dist/block.js.map +0 -1
- package/dist/directory.d.ts +0 -39
- package/dist/directory.js +0 -66
- package/dist/directory.js.map +0 -1
- package/dist/eslint.d.ts +0 -15
- package/dist/eslint.js +0 -56
- package/dist/eslint.js.map +0 -1
- package/dist/file.d.ts +0 -51
- package/dist/file.js +0 -81
- package/dist/file.js.map +0 -1
- package/dist/json.d.ts +0 -36
- package/dist/json.js +0 -33
- package/dist/json.js.map +0 -1
- package/dist/project.d.ts +0 -89
- package/dist/project.js +0 -132
- package/dist/project.js.map +0 -1
- package/dist/projectScript.d.ts +0 -22
- package/dist/projectScript.js +0 -24
- package/dist/projectScript.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,299 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { ESLint, Linter } from 'eslint';
|
|
2
|
+
|
|
3
|
+
interface DirectoryOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Directory path
|
|
6
|
+
*/
|
|
7
|
+
readonly path: string;
|
|
8
|
+
/**
|
|
9
|
+
* Directory target state
|
|
10
|
+
*/
|
|
11
|
+
readonly state: 'present' | 'absent';
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Ensure directory is present/absent
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* await directory({
|
|
19
|
+
* path: 'foo/bar',
|
|
20
|
+
* state: 'present',
|
|
21
|
+
* })
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @param options
|
|
25
|
+
*/
|
|
26
|
+
declare function directory(options: DirectoryOptions): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Ensure directory is present/absent
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* await directorySync({
|
|
33
|
+
* path: 'foo/bar',
|
|
34
|
+
* state: 'present',
|
|
35
|
+
* })
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @param options
|
|
39
|
+
*/
|
|
40
|
+
declare function directorySync(options: DirectoryOptions): void;
|
|
41
|
+
|
|
42
|
+
declare namespace ESLintConfig {
|
|
43
|
+
/**
|
|
44
|
+
*
|
|
45
|
+
* @param configs
|
|
46
|
+
*/
|
|
47
|
+
function concat(...configs: ESLint.ConfigData[]): ESLint.ConfigData;
|
|
48
|
+
/**
|
|
49
|
+
* Always return 'off'. `_status` is the previous rule value.
|
|
50
|
+
*
|
|
51
|
+
* @param _status
|
|
52
|
+
*/
|
|
53
|
+
function fixme(_status: Linter.RuleLevel | [Linter.RuleLevel, ...any[]] | undefined): "off";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface BlockOptions {
|
|
57
|
+
/**
|
|
58
|
+
* The marker builder function that will take either `markerBegin` or `markerEnd`
|
|
59
|
+
*
|
|
60
|
+
* @default '# ${mark} MANAGED BLOCK'
|
|
61
|
+
*/
|
|
62
|
+
marker?: (mark: 'Begin' | 'End') => string;
|
|
63
|
+
/**
|
|
64
|
+
* File path
|
|
65
|
+
*/
|
|
66
|
+
path: string;
|
|
67
|
+
/**
|
|
68
|
+
* Block content to insert
|
|
69
|
+
*/
|
|
70
|
+
block: string;
|
|
71
|
+
/**
|
|
72
|
+
* Insert position
|
|
73
|
+
*/
|
|
74
|
+
insertPosition?: ['before', 'BeginningOfFile' | RegExp] | ['after', 'EndOfFile' | RegExp];
|
|
75
|
+
/**
|
|
76
|
+
* Block target state
|
|
77
|
+
*/
|
|
78
|
+
state?: 'present' | 'absent';
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Replace asynchronously a block in file that follows pattern :
|
|
82
|
+
*
|
|
83
|
+
* marker(markerBegin)
|
|
84
|
+
* ...
|
|
85
|
+
* marker(markerEnd)
|
|
86
|
+
*
|
|
87
|
+
* @param options
|
|
88
|
+
*/
|
|
89
|
+
declare function block(options: BlockOptions): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Replace synchronously a block in file that follows pattern :
|
|
92
|
+
*
|
|
93
|
+
* marker(markerBegin)
|
|
94
|
+
* ...
|
|
95
|
+
* marker(markerEnd)
|
|
96
|
+
*
|
|
97
|
+
* @param options
|
|
98
|
+
*/
|
|
99
|
+
declare function blockSync(options: BlockOptions): void;
|
|
100
|
+
|
|
101
|
+
interface FileOptions {
|
|
102
|
+
/**
|
|
103
|
+
* File path
|
|
104
|
+
*/
|
|
105
|
+
readonly path: string;
|
|
106
|
+
/**
|
|
107
|
+
* File target state
|
|
108
|
+
*/
|
|
109
|
+
readonly state: 'present' | 'absent';
|
|
110
|
+
/**
|
|
111
|
+
* File content mapping function
|
|
112
|
+
*
|
|
113
|
+
* @param content
|
|
114
|
+
*/
|
|
115
|
+
readonly update?: (content: string) => string | undefined;
|
|
116
|
+
/**
|
|
117
|
+
* File encoding
|
|
118
|
+
*/
|
|
119
|
+
readonly encoding?: BufferEncoding;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Ensure file is present/absent with content initialized or modified with `update
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* await file({
|
|
127
|
+
* path: 'foo/bar',
|
|
128
|
+
* state: 'present',
|
|
129
|
+
* update: (content) => content + '_test', // This will append '_test' after current content
|
|
130
|
+
* })
|
|
131
|
+
* ```
|
|
132
|
+
*
|
|
133
|
+
* @param options
|
|
134
|
+
*/
|
|
135
|
+
declare function file(options: FileOptions): Promise<void>;
|
|
136
|
+
/**
|
|
137
|
+
* Ensure file is present/absent with content initialized or modified with `update
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* fileSync({
|
|
142
|
+
* path: 'foo/bar',
|
|
143
|
+
* state: 'present',
|
|
144
|
+
* update: (content) => content + '_test', // This will append '_test' after current content
|
|
145
|
+
* })
|
|
146
|
+
* ```
|
|
147
|
+
*
|
|
148
|
+
* @param options
|
|
149
|
+
*/
|
|
150
|
+
declare function fileSync(options: FileOptions): void;
|
|
151
|
+
|
|
152
|
+
type JSONValue = null | number | string | boolean | JSONValue[] | {
|
|
153
|
+
[key: string]: JSONValue;
|
|
154
|
+
};
|
|
155
|
+
interface JSONOption<V = JSONValue> {
|
|
156
|
+
/**
|
|
157
|
+
* File path
|
|
158
|
+
*/
|
|
159
|
+
readonly path: string;
|
|
160
|
+
/**
|
|
161
|
+
* File target state
|
|
162
|
+
*/
|
|
163
|
+
readonly state: 'present' | 'absent';
|
|
164
|
+
/**
|
|
165
|
+
* File content mapping function
|
|
166
|
+
*
|
|
167
|
+
* @param content
|
|
168
|
+
*/
|
|
169
|
+
readonly update?: (content: V | undefined) => V | undefined;
|
|
170
|
+
/**
|
|
171
|
+
* File encoding
|
|
172
|
+
*/
|
|
173
|
+
readonly encoding?: BufferEncoding;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Ensure file is present/absent asynchronously with content value initialized or modified with `update`
|
|
177
|
+
*
|
|
178
|
+
* @param options
|
|
179
|
+
*/
|
|
180
|
+
declare function json<Value>(options: JSONOption<Value>): Promise<void>;
|
|
181
|
+
/**
|
|
182
|
+
* Ensure file is present/absent synchronously with content value initialized or modified with `update`
|
|
183
|
+
*
|
|
184
|
+
* @param options
|
|
185
|
+
*/
|
|
186
|
+
declare function jsonSync<Value>(options: JSONOption<Value>): void;
|
|
187
|
+
|
|
188
|
+
declare namespace Project {
|
|
189
|
+
/**
|
|
190
|
+
* A type of a file extension
|
|
191
|
+
*/
|
|
192
|
+
type Extension = `.${string}`;
|
|
193
|
+
/**
|
|
194
|
+
* Object hash of all well-known file extension category to file extensions mapping
|
|
195
|
+
*/
|
|
196
|
+
interface ExtensionRegistry {
|
|
197
|
+
graphql: readonly Extension[];
|
|
198
|
+
jpeg: readonly Extension[];
|
|
199
|
+
javascript: readonly Extension[];
|
|
200
|
+
javascriptreact: readonly Extension[];
|
|
201
|
+
typescript: readonly Extension[];
|
|
202
|
+
typescriptreact: readonly Extension[];
|
|
203
|
+
yaml: readonly Extension[];
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* A list of "vscode-like" language identifiers (i.e. "javascript", "javascriptreact")
|
|
207
|
+
*/
|
|
208
|
+
type LanguageId = keyof ExtensionRegistry;
|
|
209
|
+
/**
|
|
210
|
+
* Supported ECMA version
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```ts
|
|
214
|
+
* Project.ecmaVersion() // 2022
|
|
215
|
+
* ```
|
|
216
|
+
*/
|
|
217
|
+
function ecmaVersion(): 2022;
|
|
218
|
+
/**
|
|
219
|
+
* Return a list of extensions
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```ts
|
|
223
|
+
* Project.queryExtensions(['javascript']); // ['.js', '.cjs', ...]
|
|
224
|
+
* Project.queryExtensions(['typescript', 'typescriptreact']); // ['.ts', '.mts', ..., '.tsx']
|
|
225
|
+
* ```
|
|
226
|
+
*
|
|
227
|
+
* @param languages
|
|
228
|
+
*/
|
|
229
|
+
function queryExtensions(languages: LanguageId[]): readonly Extension[];
|
|
230
|
+
/**
|
|
231
|
+
* Supported file extensions
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```ts
|
|
235
|
+
* Project.sourceExtensions() // ['.ts', '.js', ...]
|
|
236
|
+
* ```
|
|
237
|
+
*/
|
|
238
|
+
function sourceExtensions(): readonly `.${string}`[];
|
|
239
|
+
/**
|
|
240
|
+
* Resource file extensions
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
* ```ts
|
|
244
|
+
* Project.resourceExtensions() // ['.css', '.sass', ...]
|
|
245
|
+
* ```
|
|
246
|
+
*/
|
|
247
|
+
function resourceExtensions(): readonly `.${string}`[];
|
|
248
|
+
/**
|
|
249
|
+
* Files and folders to always ignore
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* ```ts
|
|
253
|
+
* IGNORED // ['node_modules/', 'build/', ...]
|
|
254
|
+
* ```
|
|
255
|
+
*/
|
|
256
|
+
function ignored(): readonly string[];
|
|
257
|
+
/**
|
|
258
|
+
* Return a RegExp that will match any list of extensions
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```ts
|
|
262
|
+
* Project.extensionsToMatcher(['.js', '.ts']) // RegExp = /(\.js|\.ts)$/
|
|
263
|
+
* ```
|
|
264
|
+
*/
|
|
265
|
+
function extensionsToMatcher(extensions: readonly Extension[]): RegExp;
|
|
266
|
+
/**
|
|
267
|
+
* Return a glob matcher that will match any list of extensions
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* ```ts
|
|
271
|
+
* Project.extensionsToGlob(['.js', '.ts']) // '*.+(js|ts)'
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
274
|
+
function extensionsToGlob(extensions: readonly Extension[]): string;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Project common scripts
|
|
279
|
+
*/
|
|
280
|
+
declare const ProjectScript: {
|
|
281
|
+
readonly Build: "build";
|
|
282
|
+
readonly Clean: "clean";
|
|
283
|
+
readonly CodeAnalysis: "code-analysis";
|
|
284
|
+
readonly Coverage: "coverage";
|
|
285
|
+
readonly Develop: "develop";
|
|
286
|
+
readonly Docs: "docs";
|
|
287
|
+
readonly Format: "format";
|
|
288
|
+
readonly Install: "install";
|
|
289
|
+
readonly Lint: "lint";
|
|
290
|
+
readonly Prepare: "prepare";
|
|
291
|
+
readonly Release: "release";
|
|
292
|
+
readonly Rescue: "rescue";
|
|
293
|
+
readonly Spellcheck: "spellcheck";
|
|
294
|
+
readonly Test: "test";
|
|
295
|
+
readonly Validate: "validate";
|
|
296
|
+
};
|
|
297
|
+
type ProjectScript = (typeof ProjectScript)[keyof typeof ProjectScript];
|
|
298
|
+
|
|
299
|
+
export { type BlockOptions, type DirectoryOptions, ESLintConfig, type FileOptions, type JSONOption, type JSONValue, Project, ProjectScript, block, blockSync, directory, directorySync, file, fileSync, json, jsonSync };
|
package/dist/index.js
CHANGED
|
@@ -1,24 +1,322 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { existsSync, mkdirSync, rmSync, readFileSync, writeFileSync, constants as constants$1, accessSync } from 'node:fs';
|
|
2
|
+
import { mkdir, rm, readFile, writeFile, access, constants } from 'node:fs/promises';
|
|
3
|
+
|
|
4
|
+
// src/directory.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
|
+
async function directory(options) {
|
|
14
|
+
const { path, state } = options;
|
|
15
|
+
const isPresent = await exists(path);
|
|
16
|
+
if (state === "present") {
|
|
17
|
+
if (!isPresent) {
|
|
18
|
+
await mkdir(path, { recursive: true });
|
|
19
|
+
}
|
|
20
|
+
} else if (isPresent) {
|
|
21
|
+
await rm(path, { recursive: true });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function directorySync(options) {
|
|
25
|
+
const { path, state } = options;
|
|
26
|
+
const isPresent = existsSync(path);
|
|
27
|
+
if (state === "present") {
|
|
28
|
+
if (!isPresent) {
|
|
29
|
+
mkdirSync(path, { recursive: true });
|
|
30
|
+
}
|
|
31
|
+
} else if (isPresent) {
|
|
32
|
+
rmSync(path, { recursive: true });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// src/eslint.ts
|
|
37
|
+
function toArray(value) {
|
|
38
|
+
if (value == null) {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
if (Array.isArray(value)) {
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
return [value];
|
|
45
|
+
}
|
|
46
|
+
function concatArray(left, right) {
|
|
47
|
+
return toArray(left).concat(toArray(right));
|
|
48
|
+
}
|
|
49
|
+
var ESLintConfig;
|
|
50
|
+
((ESLintConfig2) => {
|
|
51
|
+
function concat(...configs) {
|
|
52
|
+
return configs.reduce(
|
|
53
|
+
(returnValue, config) => ({
|
|
54
|
+
...returnValue,
|
|
55
|
+
...config,
|
|
56
|
+
env: { ...returnValue.env, ...config.env },
|
|
57
|
+
extends: concatArray(returnValue.extends, config.extends),
|
|
58
|
+
globals: { ...returnValue.globals, ...config.globals },
|
|
59
|
+
overrides: concatArray(returnValue.overrides, config.overrides),
|
|
60
|
+
parserOptions: { ...returnValue.parserOptions, ...config.parserOptions },
|
|
61
|
+
plugins: concatArray(returnValue.plugins, config.plugins),
|
|
62
|
+
rules: { ...returnValue.rules, ...config.rules },
|
|
63
|
+
settings: { ...returnValue.settings, ...config.settings }
|
|
64
|
+
}),
|
|
65
|
+
{
|
|
66
|
+
env: {},
|
|
67
|
+
extends: [],
|
|
68
|
+
globals: {},
|
|
69
|
+
overrides: [],
|
|
70
|
+
parserOptions: {},
|
|
71
|
+
plugins: [],
|
|
72
|
+
rules: {},
|
|
73
|
+
settings: {}
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
ESLintConfig2.concat = concat;
|
|
78
|
+
function fixme(_status) {
|
|
79
|
+
return "off";
|
|
80
|
+
}
|
|
81
|
+
ESLintConfig2.fixme = fixme;
|
|
82
|
+
})(ESLintConfig || (ESLintConfig = {}));
|
|
83
|
+
async function exists2(path) {
|
|
84
|
+
try {
|
|
85
|
+
await access(path, constants$1.F_OK);
|
|
86
|
+
return true;
|
|
87
|
+
} catch {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function existsSync2(path) {
|
|
92
|
+
try {
|
|
93
|
+
accessSync(path, constants$1.F_OK);
|
|
94
|
+
return true;
|
|
95
|
+
} catch {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async function file(options) {
|
|
100
|
+
const { path, state, update, encoding = "utf8" } = options;
|
|
101
|
+
if (state === "present") {
|
|
102
|
+
const isPresent = await exists2(path);
|
|
103
|
+
const previousContent = isPresent ? await readFile(path, encoding) : "";
|
|
104
|
+
const newContent = update == null ? "" : update(previousContent);
|
|
105
|
+
if (newContent != null) {
|
|
106
|
+
await writeFile(path, newContent, encoding);
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
await rm(path, { force: true });
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function fileSync(options) {
|
|
113
|
+
const { path, state, update, encoding = "utf8" } = options;
|
|
114
|
+
if (state === "present") {
|
|
115
|
+
const isPresent = existsSync2(path);
|
|
116
|
+
const previousContent = isPresent ? readFileSync(path, encoding) : "";
|
|
117
|
+
const newContent = update == null ? "" : update(previousContent);
|
|
118
|
+
if (newContent != null) {
|
|
119
|
+
writeFileSync(path, newContent, encoding);
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
rmSync(path, { force: true });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// src/block.ts
|
|
127
|
+
var EOF = "EndOfFile";
|
|
128
|
+
var BOF = "BeginningOfFile";
|
|
129
|
+
var insertAt = (str, index, toInsert) => str.slice(0, index) + toInsert + str.slice(index);
|
|
130
|
+
var matchLast = (string, regexp) => {
|
|
131
|
+
const matcher = new RegExp(regexp.source, `${regexp.flags}g`);
|
|
132
|
+
let firstIndex = -1;
|
|
133
|
+
let lastIndex = -1;
|
|
134
|
+
let matches;
|
|
135
|
+
while (true) {
|
|
136
|
+
matches = matcher.exec(string);
|
|
137
|
+
if (matches == null) {
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
firstIndex = matches.index;
|
|
141
|
+
lastIndex = matcher.lastIndex;
|
|
142
|
+
}
|
|
143
|
+
return { firstIndex, lastIndex };
|
|
144
|
+
};
|
|
145
|
+
function toFileOptions(options) {
|
|
146
|
+
const {
|
|
147
|
+
marker = (mark) => `# ${mark.toUpperCase()} MANAGED BLOCK`,
|
|
148
|
+
path,
|
|
149
|
+
block: blockName,
|
|
150
|
+
insertPosition = ["after", EOF],
|
|
151
|
+
state = "present"
|
|
152
|
+
} = options;
|
|
153
|
+
const EOL = "\n";
|
|
154
|
+
const beginBlock = marker("Begin");
|
|
155
|
+
const endBlock = marker("End");
|
|
156
|
+
function findBlock(content) {
|
|
157
|
+
const startIndex = content.indexOf(beginBlock);
|
|
158
|
+
const endIndex = content.indexOf(endBlock) + endBlock.length;
|
|
159
|
+
return {
|
|
160
|
+
endIndex,
|
|
161
|
+
exists: startIndex >= 0 && endIndex >= 0,
|
|
162
|
+
startIndex
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function apply(fullContent, blockContent) {
|
|
166
|
+
const found = findBlock(fullContent);
|
|
167
|
+
const remove = state === "absent";
|
|
168
|
+
const replaceBlock = remove ? "" : beginBlock + EOL + blockContent + EOL + endBlock;
|
|
169
|
+
const [positionDirection, positionAnchor] = insertPosition;
|
|
170
|
+
if (found.exists) {
|
|
171
|
+
return fullContent.slice(0, found.startIndex) + replaceBlock + fullContent.slice(found.endIndex);
|
|
172
|
+
}
|
|
173
|
+
if (remove) {
|
|
174
|
+
return fullContent;
|
|
175
|
+
}
|
|
176
|
+
switch (positionDirection) {
|
|
177
|
+
case "before": {
|
|
178
|
+
if (positionAnchor !== BOF) {
|
|
179
|
+
const { firstIndex } = matchLast(fullContent, positionAnchor);
|
|
180
|
+
if (firstIndex >= 0) {
|
|
181
|
+
return insertAt(fullContent, firstIndex, replaceBlock + EOL);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return replaceBlock + EOL + fullContent;
|
|
185
|
+
}
|
|
186
|
+
case "after": {
|
|
187
|
+
if (positionAnchor !== EOF) {
|
|
188
|
+
const { lastIndex } = matchLast(fullContent, positionAnchor);
|
|
189
|
+
if (lastIndex >= 0) {
|
|
190
|
+
return insertAt(fullContent, lastIndex, EOL + replaceBlock);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return fullContent + EOL + replaceBlock;
|
|
194
|
+
}
|
|
195
|
+
default: {
|
|
196
|
+
throw new Error(`Unsupported position ${String(positionDirection)}`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
path,
|
|
202
|
+
state: "present",
|
|
203
|
+
update: (sourceContent) => apply(sourceContent, blockName)
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
function block(options) {
|
|
207
|
+
return file(toFileOptions(options));
|
|
208
|
+
}
|
|
209
|
+
function blockSync(options) {
|
|
210
|
+
return fileSync(toFileOptions(options));
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// src/json.ts
|
|
214
|
+
function toFileOption({ update, ...otherOptions }) {
|
|
215
|
+
return {
|
|
216
|
+
...otherOptions,
|
|
217
|
+
update: update == null ? update : (content) => {
|
|
218
|
+
const jsonValue = content === "" ? void 0 : JSON.parse(content);
|
|
219
|
+
return JSON.stringify(update(jsonValue));
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
async function json(options) {
|
|
224
|
+
return file(toFileOption(options));
|
|
225
|
+
}
|
|
226
|
+
function jsonSync(options) {
|
|
227
|
+
return fileSync(toFileOption(options));
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// src/project.ts
|
|
231
|
+
function escapeRegExp(value) {
|
|
232
|
+
return value.replaceAll(/[$()*+.?[\\\]^{|}]/g, "\\$&");
|
|
233
|
+
}
|
|
234
|
+
var Project;
|
|
235
|
+
((Project2) => {
|
|
236
|
+
function ecmaVersion() {
|
|
237
|
+
return 2022;
|
|
238
|
+
}
|
|
239
|
+
Project2.ecmaVersion = ecmaVersion;
|
|
240
|
+
const registry = {
|
|
241
|
+
graphql: [".gql", ".graphql"],
|
|
242
|
+
jpeg: [".jpg", ".jpeg"],
|
|
243
|
+
javascript: [".js", ".cjs", ".mjs"],
|
|
244
|
+
javascriptreact: [".jsx"],
|
|
245
|
+
typescript: [".ts", ".cts", ".mts"],
|
|
246
|
+
typescriptreact: [".tsx"],
|
|
247
|
+
yaml: [".yaml", ".yml"]
|
|
248
|
+
};
|
|
249
|
+
function queryExtensions(languages) {
|
|
250
|
+
return languages.reduce(
|
|
251
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
252
|
+
(previousValue, currentValue) => previousValue.concat(registry[currentValue] ?? []),
|
|
253
|
+
[]
|
|
254
|
+
).sort();
|
|
255
|
+
}
|
|
256
|
+
Project2.queryExtensions = queryExtensions;
|
|
257
|
+
function sourceExtensions() {
|
|
258
|
+
return queryExtensions(["javascript", "javascriptreact", "typescript", "typescriptreact"]);
|
|
259
|
+
}
|
|
260
|
+
Project2.sourceExtensions = sourceExtensions;
|
|
261
|
+
const RESOURCE_EXTENSIONS = Object.freeze([
|
|
262
|
+
".css",
|
|
263
|
+
".sass",
|
|
264
|
+
".scss",
|
|
265
|
+
".less",
|
|
266
|
+
".gif",
|
|
267
|
+
".png",
|
|
268
|
+
".svg",
|
|
269
|
+
...queryExtensions(["graphql", "jpeg", "yaml"])
|
|
270
|
+
]);
|
|
271
|
+
function resourceExtensions() {
|
|
272
|
+
return RESOURCE_EXTENSIONS;
|
|
273
|
+
}
|
|
274
|
+
Project2.resourceExtensions = resourceExtensions;
|
|
275
|
+
const IGNORED = Object.freeze([
|
|
276
|
+
"node_modules/",
|
|
277
|
+
"build/",
|
|
278
|
+
"cjs/",
|
|
279
|
+
"coverage/",
|
|
280
|
+
"dist/",
|
|
281
|
+
"dts/",
|
|
282
|
+
"esm/",
|
|
283
|
+
"lib/",
|
|
284
|
+
"mjs/",
|
|
285
|
+
"umd/"
|
|
286
|
+
]);
|
|
287
|
+
function ignored() {
|
|
288
|
+
return IGNORED;
|
|
289
|
+
}
|
|
290
|
+
Project2.ignored = ignored;
|
|
291
|
+
function extensionsToMatcher(extensions) {
|
|
292
|
+
return new RegExp(`(${extensions.map(escapeRegExp).join("|")})$`);
|
|
293
|
+
}
|
|
294
|
+
Project2.extensionsToMatcher = extensionsToMatcher;
|
|
295
|
+
function extensionsToGlob(extensions) {
|
|
296
|
+
return `*.+(${extensions.map((_) => _.replace(/^\./, "")).join("|")})`;
|
|
297
|
+
}
|
|
298
|
+
Project2.extensionsToGlob = extensionsToGlob;
|
|
299
|
+
})(Project || (Project = {}));
|
|
300
|
+
|
|
301
|
+
// src/projectScript.ts
|
|
302
|
+
var ProjectScript = {
|
|
303
|
+
Build: "build",
|
|
304
|
+
Clean: "clean",
|
|
305
|
+
CodeAnalysis: "code-analysis",
|
|
306
|
+
Coverage: "coverage",
|
|
307
|
+
Develop: "develop",
|
|
308
|
+
Docs: "docs",
|
|
309
|
+
Format: "format",
|
|
310
|
+
Install: "install",
|
|
311
|
+
Lint: "lint",
|
|
312
|
+
Prepare: "prepare",
|
|
313
|
+
Release: "release",
|
|
314
|
+
Rescue: "rescue",
|
|
315
|
+
Spellcheck: "spellcheck",
|
|
316
|
+
Test: "test",
|
|
317
|
+
Validate: "validate"
|
|
15
318
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
__exportStar(require("./block.js"), exports);
|
|
20
|
-
__exportStar(require("./file.js"), exports);
|
|
21
|
-
__exportStar(require("./json.js"), exports);
|
|
22
|
-
__exportStar(require("./project.js"), exports);
|
|
23
|
-
__exportStar(require("./projectScript.js"), exports);
|
|
319
|
+
|
|
320
|
+
export { ESLintConfig, Project, ProjectScript, block, blockSync, directory, directorySync, file, fileSync, json, jsonSync };
|
|
321
|
+
//# sourceMappingURL=index.js.map
|
|
24
322
|
//# sourceMappingURL=index.js.map
|