@ankhorage/devtools 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +146 -99
- package/dist/cli/commands.d.ts +2 -2
- package/dist/cli/commands.js +31 -75
- package/dist/cli/index.d.ts +2 -2
- package/dist/cli/index.js +19 -0
- package/dist/cli/runRepositoryCommand.js +40 -27
- package/dist/internal/readmeDocs.js +10 -0
- package/dist/tools/eslint/index.d.ts +1 -1
- package/dist/tools/eslint/index.js +151 -66
- package/dist/tools/eslint/managed.d.ts +10 -0
- package/dist/tools/eslint/managed.js +44 -0
- package/dist/tools/eslint/profile.d.ts +4 -0
- package/dist/tools/eslint/profile.js +81 -0
- package/dist/tools/eslint/types.d.ts +5 -1
- package/dist/tools/knip/index.d.ts +13 -0
- package/dist/tools/knip/managed.d.ts +5 -0
- package/dist/tools/knip/managed.js +11 -0
- package/dist/tools/package/index.d.ts +8 -0
- package/dist/tools/package/index.js +152 -0
- package/dist/tools/prettier/managed.d.ts +6 -0
- package/dist/tools/prettier/managed.js +34 -0
- package/dist/tools/shared/managedFiles.d.ts +6 -1
- package/dist/tools/shared/managedFiles.js +44 -33
- package/package.json +17 -2
|
@@ -16,10 +16,13 @@ export async function resolveManagedTargetDirectory(cwd, requestedPath) {
|
|
|
16
16
|
}
|
|
17
17
|
export async function inspectManagedFiles(targetDirectory, definitions) {
|
|
18
18
|
return await Promise.all(definitions.map(async (definition) => {
|
|
19
|
-
const canonicalContents = await readCanonicalContents(definition);
|
|
20
19
|
const targetPath = resolve(targetDirectory, definition.relativePath);
|
|
21
20
|
try {
|
|
22
21
|
const targetContents = await readFile(targetPath, 'utf8');
|
|
22
|
+
if ((definition.mode ?? 'replace') === 'create-only') {
|
|
23
|
+
return { relativePath: definition.relativePath, state: 'current' };
|
|
24
|
+
}
|
|
25
|
+
const canonicalContents = await readCanonicalContents(definition, targetDirectory);
|
|
23
26
|
return {
|
|
24
27
|
relativePath: definition.relativePath,
|
|
25
28
|
state: targetContents === canonicalContents ? 'current' : 'outdated',
|
|
@@ -27,10 +30,7 @@ export async function inspectManagedFiles(targetDirectory, definitions) {
|
|
|
27
30
|
}
|
|
28
31
|
catch (error) {
|
|
29
32
|
if (isMissingFileError(error)) {
|
|
30
|
-
return {
|
|
31
|
-
relativePath: definition.relativePath,
|
|
32
|
-
state: 'missing',
|
|
33
|
-
};
|
|
33
|
+
return { relativePath: definition.relativePath, state: 'missing' };
|
|
34
34
|
}
|
|
35
35
|
throw new Error(`Failed to inspect managed file: ${targetPath}`, { cause: error });
|
|
36
36
|
}
|
|
@@ -41,39 +41,50 @@ export async function syncManagedFiles(targetDirectory, definitions, options) {
|
|
|
41
41
|
const definitionsByPath = new Map(definitions.map((definition) => [definition.relativePath, definition]));
|
|
42
42
|
const results = [];
|
|
43
43
|
for (const status of statuses) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
48
|
-
const definition = definitionsByPath.get(status.relativePath);
|
|
49
|
-
if (definition === undefined) {
|
|
50
|
-
throw new Error(`Missing managed file definition for ${status.relativePath}.`);
|
|
51
|
-
}
|
|
52
|
-
if (options.dryRun) {
|
|
53
|
-
results.push({
|
|
54
|
-
relativePath: status.relativePath,
|
|
55
|
-
action: status.state === 'missing' ? 'would-create' : 'would-update',
|
|
56
|
-
});
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
const targetPath = resolve(targetDirectory, definition.relativePath);
|
|
60
|
-
await mkdir(dirname(targetPath), { recursive: true });
|
|
61
|
-
await writeFile(targetPath, await readCanonicalContents(definition), 'utf8');
|
|
62
|
-
results.push({
|
|
63
|
-
relativePath: status.relativePath,
|
|
64
|
-
action: status.state === 'missing' ? 'created' : 'updated',
|
|
65
|
-
});
|
|
44
|
+
const result = await syncManagedFile(targetDirectory, status, definitionsByPath, options);
|
|
45
|
+
results.push(result);
|
|
66
46
|
}
|
|
67
47
|
return results;
|
|
68
48
|
}
|
|
69
|
-
async function
|
|
70
|
-
|
|
49
|
+
async function syncManagedFile(targetDirectory, status, definitionsByPath, options) {
|
|
50
|
+
if (status.state === 'current') {
|
|
51
|
+
return { relativePath: status.relativePath, action: 'unchanged' };
|
|
52
|
+
}
|
|
53
|
+
const definition = definitionsByPath.get(status.relativePath);
|
|
54
|
+
if (definition === undefined) {
|
|
55
|
+
throw new Error(`Missing managed file definition for ${status.relativePath}.`);
|
|
56
|
+
}
|
|
57
|
+
if (options.dryRun) {
|
|
58
|
+
return {
|
|
59
|
+
relativePath: status.relativePath,
|
|
60
|
+
action: status.state === 'missing' ? 'would-create' : 'would-update',
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const targetPath = resolve(targetDirectory, definition.relativePath);
|
|
64
|
+
await mkdir(dirname(targetPath), { recursive: true });
|
|
65
|
+
await writeFile(targetPath, await readCanonicalContents(definition, targetDirectory), 'utf8');
|
|
66
|
+
return {
|
|
67
|
+
relativePath: status.relativePath,
|
|
68
|
+
action: status.state === 'missing' ? 'created' : 'updated',
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
async function readCanonicalContents(definition, targetDirectory) {
|
|
72
|
+
assertSingleContentSource(definition);
|
|
73
|
+
if (definition.sourceUrl !== undefined) {
|
|
71
74
|
return await readFile(definition.sourceUrl, 'utf8');
|
|
72
75
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
76
|
+
if (definition.contents !== undefined) {
|
|
77
|
+
return definition.contents;
|
|
78
|
+
}
|
|
79
|
+
if (definition.render !== undefined) {
|
|
80
|
+
return await definition.render(targetDirectory);
|
|
81
|
+
}
|
|
82
|
+
throw new Error(`Managed file has no content source: ${definition.relativePath}`);
|
|
83
|
+
}
|
|
84
|
+
function assertSingleContentSource(definition) {
|
|
85
|
+
const sourceCount = [definition.sourceUrl, definition.contents, definition.render].filter((value) => value !== undefined).length;
|
|
86
|
+
if (sourceCount !== 1) {
|
|
87
|
+
throw new Error(`Managed file must define exactly one content source: ${definition.relativePath}`);
|
|
77
88
|
}
|
|
78
89
|
}
|
|
79
90
|
function isMissingFileError(error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ankhorage/devtools",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Shared development tools and repository standards for Ankhorage",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/ankhorage/devtools#readme",
|
|
@@ -24,6 +24,14 @@
|
|
|
24
24
|
"devtools.knip",
|
|
25
25
|
"devtools.sync",
|
|
26
26
|
"devtools.status",
|
|
27
|
+
"devtools.eslint.sync",
|
|
28
|
+
"devtools.eslint.status",
|
|
29
|
+
"devtools.prettier.sync",
|
|
30
|
+
"devtools.prettier.status",
|
|
31
|
+
"devtools.knip.sync",
|
|
32
|
+
"devtools.knip.status",
|
|
33
|
+
"devtools.package.sync",
|
|
34
|
+
"devtools.package.status",
|
|
27
35
|
"devtools.workflows.sync",
|
|
28
36
|
"devtools.workflows.status",
|
|
29
37
|
"devtools.vscode.sync",
|
|
@@ -59,7 +67,9 @@
|
|
|
59
67
|
"import": "./dist/tools/knip/index.js"
|
|
60
68
|
},
|
|
61
69
|
"./prettier": {
|
|
62
|
-
"
|
|
70
|
+
"import": "./dist/tools/prettier/index.cjs",
|
|
71
|
+
"require": "./dist/tools/prettier/index.cjs",
|
|
72
|
+
"default": "./dist/tools/prettier/index.cjs"
|
|
63
73
|
}
|
|
64
74
|
},
|
|
65
75
|
"files": [
|
|
@@ -85,11 +95,16 @@
|
|
|
85
95
|
"version-packages": "changeset version"
|
|
86
96
|
},
|
|
87
97
|
"dependencies": {
|
|
98
|
+
"@ankhorage/utility": "^0.1.1",
|
|
88
99
|
"@eslint/js": "^10.0.1",
|
|
89
100
|
"eslint": "^10.2.0",
|
|
90
101
|
"eslint-config-prettier": "^10.1.8",
|
|
91
102
|
"eslint-plugin-import": "^2.32.0",
|
|
92
103
|
"eslint-plugin-prettier": "^5.5.5",
|
|
104
|
+
"eslint-plugin-react": "^7.37.5",
|
|
105
|
+
"eslint-plugin-react-hooks": "^7.1.1",
|
|
106
|
+
"eslint-plugin-react-native": "^5.0.0",
|
|
107
|
+
"eslint-plugin-security": "^4.0.1",
|
|
93
108
|
"eslint-plugin-simple-import-sort": "^12.1.1",
|
|
94
109
|
"eslint-plugin-unused-imports": "^4.4.1",
|
|
95
110
|
"knip": "^6.12.2",
|