@sapphire-sh/utils 2.10.0 → 2.12.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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { basename, dirname, join } from 'node:path';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
6
|
|
|
@@ -8,11 +8,15 @@ const START_MARKER = '# @sapphire-sh/utils:start';
|
|
|
8
8
|
const END_MARKER = '# @sapphire-sh/utils:end';
|
|
9
9
|
|
|
10
10
|
const selfPackageName = '@sapphire-sh/utils';
|
|
11
|
-
const selfSkipped = new Set([join('.github', 'workflows', '
|
|
11
|
+
const selfSkipped = new Set([join('.github', 'workflows', 'shared-config-update.yml')]);
|
|
12
|
+
const obsoleteFiles = new Set([join('.github', 'workflows', 'utils-update.yml')]);
|
|
12
13
|
|
|
13
14
|
const workflowsDir = join('.github', 'workflows');
|
|
14
15
|
const workflowValuesPath = join('.github', 'sapphire-workflows.json');
|
|
15
16
|
const withLinePattern = /^\s*with:\s*$/m;
|
|
17
|
+
const pathsIgnoreLinePattern = /^\s*paths-ignore:\s*$/m;
|
|
18
|
+
const pushBlockPattern = /^on:\n(?:[ \t].*\n|\n)*? {2}push:\n((?: {4}.*\n|\n)*)/m;
|
|
19
|
+
const branchesListPattern = /^ {2}push:\n {4}branches:\n(?: {6}- .*\n)*/m;
|
|
16
20
|
const requiredFiles = new Map([[join(workflowsDir, 'docker-publish.yml'), 'Dockerfile']]);
|
|
17
21
|
|
|
18
22
|
const sectioned = new Set(['.gitignore', '.prettierignore']);
|
|
@@ -88,15 +92,33 @@ const writeWorkflow = (outputName, template) => {
|
|
|
88
92
|
console.log(`warning: ${outputName} had with: values that are not in ${workflowValuesPath}`);
|
|
89
93
|
}
|
|
90
94
|
} else {
|
|
95
|
+
const { 'paths-ignore': pathsIgnore, ...withValues } = values;
|
|
96
|
+
|
|
97
|
+
if (pathsIgnore !== undefined) {
|
|
98
|
+
const pathsIgnoreLines = pathsIgnore.map((value) => ` - ${JSON.stringify(value)}\n`).join('');
|
|
99
|
+
content = content.replace(
|
|
100
|
+
branchesListPattern,
|
|
101
|
+
(branchesList) => `${branchesList} paths-ignore:\n${pathsIgnoreLines}`,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
91
105
|
if (withLinePattern.test(template) === false) {
|
|
92
106
|
content += ' with:\n';
|
|
93
107
|
}
|
|
94
108
|
|
|
95
|
-
for (const [key, value] of Object.entries(
|
|
109
|
+
for (const [key, value] of Object.entries(withValues)) {
|
|
96
110
|
content += ` ${key}: ${JSON.stringify(value)}\n`;
|
|
97
111
|
}
|
|
98
112
|
}
|
|
99
113
|
|
|
114
|
+
if (
|
|
115
|
+
(values === undefined || Object.hasOwn(values, 'paths-ignore') === false) &&
|
|
116
|
+
existsSync(filepath) &&
|
|
117
|
+
pathsIgnoreLinePattern.test(readFileSync(filepath, 'utf-8'))
|
|
118
|
+
) {
|
|
119
|
+
console.log(`warning: ${outputName} had paths-ignore values that are not in ${workflowValuesPath}`);
|
|
120
|
+
}
|
|
121
|
+
|
|
100
122
|
mkdirSync(dirname(filepath), { recursive: true });
|
|
101
123
|
writeFileSync(filepath, content);
|
|
102
124
|
console.log(`wrote ${outputName}`);
|
|
@@ -118,6 +140,23 @@ const collectTemplates = (directory, prefix) => {
|
|
|
118
140
|
return relativePaths;
|
|
119
141
|
};
|
|
120
142
|
|
|
143
|
+
for (const [name, values] of Object.entries(workflowValues)) {
|
|
144
|
+
const callerPath = join(workflowsDir, `${name}.yml`);
|
|
145
|
+
|
|
146
|
+
if (Object.hasOwn(values, 'paths-ignore') === false) {
|
|
147
|
+
continue;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const pushBlock = pushBlockPattern.exec(readFileSync(join(templatesDir, callerPath), 'utf-8'));
|
|
151
|
+
|
|
152
|
+
if (pushBlock === null || /^ {4}paths:/m.test(pushBlock[1])) {
|
|
153
|
+
console.error(
|
|
154
|
+
`error: ${workflowValuesPath} sets paths-ignore for ${callerPath}, whose template has no push trigger without paths`,
|
|
155
|
+
);
|
|
156
|
+
process.exit(1);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
121
160
|
for (const relativePath of collectTemplates(templatesDir, '')) {
|
|
122
161
|
const outputName = renameMap.get(relativePath) ?? relativePath;
|
|
123
162
|
const outputPath = join(cwd, outputName);
|
|
@@ -143,3 +182,12 @@ for (const relativePath of collectTemplates(templatesDir, '')) {
|
|
|
143
182
|
console.log(`wrote ${outputName}`);
|
|
144
183
|
}
|
|
145
184
|
}
|
|
185
|
+
|
|
186
|
+
for (const relativePath of obsoleteFiles) {
|
|
187
|
+
const filepath = join(cwd, relativePath);
|
|
188
|
+
|
|
189
|
+
if (existsSync(filepath)) {
|
|
190
|
+
rmSync(filepath);
|
|
191
|
+
console.log(`removed ${relativePath}`);
|
|
192
|
+
}
|
|
193
|
+
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
version: 2
|
|
2
|
+
updates:
|
|
3
|
+
- package-ecosystem: npm
|
|
4
|
+
directory: /
|
|
5
|
+
schedule:
|
|
6
|
+
interval: cron
|
|
7
|
+
cronjob: '0 0 * * *'
|
|
8
|
+
groups:
|
|
9
|
+
dependencies:
|
|
10
|
+
patterns:
|
|
11
|
+
- '*'
|
|
12
|
+
exclude-patterns:
|
|
13
|
+
- '@sapphire-sh/utils'
|
|
14
|
+
- package-ecosystem: github-actions
|
|
15
|
+
directory: /
|
|
16
|
+
schedule:
|
|
17
|
+
interval: cron
|
|
18
|
+
cronjob: '0 0 * * *'
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
name: shared-config-update
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
paths:
|
|
8
|
+
- package-lock.json
|
|
9
|
+
workflow_dispatch:
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
update:
|
|
13
|
+
uses: sapphire-sh/github-actions/.github/workflows/shared-config-update-template.yml@main
|
|
14
|
+
permissions:
|
|
15
|
+
contents: write
|
|
16
|
+
issues: write
|
|
17
|
+
pull-requests: write
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
name: utils-update
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
schedule:
|
|
5
|
-
- cron: '0 0 * * *'
|
|
6
|
-
workflow_dispatch:
|
|
7
|
-
|
|
8
|
-
jobs:
|
|
9
|
-
update:
|
|
10
|
-
uses: sapphire-sh/github-actions/.github/workflows/utils-update-template.yml@main
|
|
11
|
-
permissions:
|
|
12
|
-
contents: write
|
|
13
|
-
issues: write
|
|
14
|
-
pull-requests: write
|