@sapphire-sh/utils 2.15.0 → 3.1.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.
@@ -8,8 +8,12 @@ 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', 'shared-config-update.yml')]);
12
- const obsoleteFiles = new Set([join('.github', 'workflows', 'utils-update.yml')]);
11
+ const selfSkipped = new Set([join('.github', 'workflows', 'node-shared-config-update.yml')]);
12
+ const obsoleteFiles = new Set([
13
+ join('.github', 'workflows', 'utils-update.yml'),
14
+ join('.github', 'workflows', 'npm-audit-fix.yml'),
15
+ join('.github', 'workflows', 'shared-config-update.yml'),
16
+ ]);
13
17
 
14
18
  const workflowsDir = join('.github', 'workflows');
15
19
  const workflowValuesPath = join('.github', 'sapphire-workflows.json');
@@ -17,7 +21,10 @@ const withLinePattern = /^\s*with:\s*$/m;
17
21
  const pathsIgnoreLinePattern = /^\s*paths-ignore:\s*$/m;
18
22
  const pushBlockPattern = /^on:\n(?:[ \t].*\n|\n)*? {2}push:\n((?: {4}.*\n|\n)*)/m;
19
23
  const branchesListPattern = /^ {2}push:\n {4}branches:\n(?: {6}- .*\n)*/m;
24
+ const entryKeys = new Set(['push', 'with']);
25
+ const pushKeys = new Set(['paths', 'paths-ignore']);
20
26
  const requiredFiles = new Map([[join(workflowsDir, 'docker-publish.yml'), 'Dockerfile']]);
27
+ const entryRequiredFiles = new Set([join(workflowsDir, 'userscript-publish.yml')]);
21
28
 
22
29
  const sectioned = new Set(['.gitignore', '.prettierignore']);
23
30
  const renameMap = new Map([
@@ -95,27 +102,26 @@ const writeWorkflow = (outputName, template) => {
95
102
  console.log(`warning: ${outputName} had with: values that are not in ${workflowValuesPath}`);
96
103
  }
97
104
  } else {
98
- const { 'paths-ignore': pathsIgnore, ...withValues } = values;
99
-
100
- if (pathsIgnore !== undefined) {
101
- const pathsIgnoreLines = pathsIgnore.map((value) => ` - ${formatYamlValue(value)}\n`).join('');
102
- content = content.replace(
103
- branchesListPattern,
104
- (branchesList) => `${branchesList} paths-ignore:\n${pathsIgnoreLines}`,
105
- );
106
- }
105
+ const { push = {}, with: withValues } = values;
107
106
 
108
- if (withLinePattern.test(template) === false) {
109
- content += ' with:\n';
107
+ for (const [key, patterns] of Object.entries(push)) {
108
+ const patternLines = patterns.map((value) => ` - ${formatYamlValue(value)}\n`).join('');
109
+ content = content.replace(branchesListPattern, (branchesList) => `${branchesList} ${key}:\n${patternLines}`);
110
110
  }
111
111
 
112
- for (const [key, value] of Object.entries(withValues)) {
113
- content += ` ${key}: ${formatYamlValue(value)}\n`;
112
+ if (withValues !== undefined) {
113
+ if (withLinePattern.test(template) === false) {
114
+ content += ' with:\n';
115
+ }
116
+
117
+ for (const [key, value] of Object.entries(withValues)) {
118
+ content += ` ${key}: ${formatYamlValue(value)}\n`;
119
+ }
114
120
  }
115
121
  }
116
122
 
117
123
  if (
118
- (values === undefined || Object.hasOwn(values, 'paths-ignore') === false) &&
124
+ (values?.push === undefined || Object.hasOwn(values.push, 'paths-ignore') === false) &&
119
125
  existsSync(filepath) &&
120
126
  pathsIgnoreLinePattern.test(readFileSync(filepath, 'utf-8'))
121
127
  ) {
@@ -146,15 +152,49 @@ const collectTemplates = (directory, prefix) => {
146
152
  for (const [name, values] of Object.entries(workflowValues)) {
147
153
  const callerPath = join(workflowsDir, `${name}.yml`);
148
154
 
149
- if (Object.hasOwn(values, 'paths-ignore') === false) {
155
+ if (existsSync(join(templatesDir, callerPath)) === false) {
156
+ console.error(`error: ${workflowValuesPath} ${name} names no workflow template`);
157
+ process.exit(1);
158
+ }
159
+
160
+ for (const key of Object.keys(values)) {
161
+ if (entryKeys.has(key) === false) {
162
+ console.error(`error: ${workflowValuesPath} ${name} has unknown key ${key}`);
163
+ process.exit(1);
164
+ }
165
+ }
166
+
167
+ if (name === 'userscript-publish' && values.with?.assets === undefined) {
168
+ console.error(`error: ${workflowValuesPath} userscript-publish has no with.assets`);
169
+ process.exit(1);
170
+ }
171
+
172
+ if (values.push === undefined) {
150
173
  continue;
151
174
  }
152
175
 
176
+ for (const key of Object.keys(values.push)) {
177
+ if (pushKeys.has(key) === false) {
178
+ console.error(`error: ${workflowValuesPath} ${name}.push has unknown key ${key}`);
179
+ process.exit(1);
180
+ }
181
+ }
182
+
183
+ if (Object.hasOwn(values.push, 'paths') && Object.hasOwn(values.push, 'paths-ignore')) {
184
+ console.error(`error: ${workflowValuesPath} ${name}.push sets both paths and paths-ignore`);
185
+ process.exit(1);
186
+ }
187
+
188
+ if (Object.keys(values.push).length === 0) {
189
+ continue;
190
+ }
191
+
192
+ const [pushKey] = Object.keys(values.push);
153
193
  const pushBlock = pushBlockPattern.exec(readFileSync(join(templatesDir, callerPath), 'utf-8'));
154
194
 
155
195
  if (pushBlock === null || /^ {4}paths:/m.test(pushBlock[1])) {
156
196
  console.error(
157
- `error: ${workflowValuesPath} sets paths-ignore for ${callerPath}, whose template has no push trigger without paths`,
197
+ `error: ${workflowValuesPath} sets push.${pushKey} for ${callerPath}, whose template has no push trigger without paths`,
158
198
  );
159
199
  process.exit(1);
160
200
  }
@@ -174,6 +214,11 @@ for (const relativePath of collectTemplates(templatesDir, '')) {
174
214
  continue;
175
215
  }
176
216
 
217
+ if (entryRequiredFiles.has(outputName) && Object.hasOwn(workflowValues, basename(outputName, '.yml')) === false) {
218
+ console.log(`skipped ${outputName}`);
219
+ continue;
220
+ }
221
+
177
222
  if (dirname(outputName) === workflowsDir) {
178
223
  writeWorkflow(outputName, readFileSync(join(templatesDir, relativePath), 'utf-8'));
179
224
  } else if (sectioned.has(outputName)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sapphire-sh/utils",
3
- "version": "2.15.0",
3
+ "version": "3.1.0",
4
4
  "description": "@sapphire-sh/utils",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -137,5 +137,9 @@
137
137
  "typescript": "npm:@typescript/typescript6@^6.0.2",
138
138
  "typescript-eslint": "^8.29.1",
139
139
  "vitest": "^5.0.1"
140
+ },
141
+ "allowScripts": {
142
+ "fsevents@2.3.3": true,
143
+ "unrs-resolver@1.12.2": true
140
144
  }
141
145
  }
@@ -12,7 +12,7 @@ concurrency:
12
12
 
13
13
  jobs:
14
14
  call-shared-ci:
15
- uses: sapphire-sh/github-actions/.github/workflows/docker-ci-template.yml@main
15
+ uses: sapphire-sh/github-actions/.github/workflows/docker-publish-template.yml@main
16
16
  secrets: inherit
17
17
  with:
18
18
  image_name: ${{ github.event.repository.name }}
@@ -1,4 +1,4 @@
1
- name: npm-audit-fix
1
+ name: node-audit-fix
2
2
 
3
3
  on:
4
4
  schedule:
@@ -7,7 +7,7 @@ on:
7
7
 
8
8
  jobs:
9
9
  fix:
10
- uses: sapphire-sh/github-actions/.github/workflows/npm-audit-fix-template.yml@main
10
+ uses: sapphire-sh/github-actions/.github/workflows/node-audit-fix-template.yml@main
11
11
  permissions:
12
12
  contents: write
13
13
  issues: write
@@ -1,4 +1,4 @@
1
- name: shared-config-update
1
+ name: node-shared-config-update
2
2
 
3
3
  on:
4
4
  push:
@@ -10,7 +10,7 @@ on:
10
10
 
11
11
  jobs:
12
12
  update:
13
- uses: sapphire-sh/github-actions/.github/workflows/shared-config-update-template.yml@main
13
+ uses: sapphire-sh/github-actions/.github/workflows/node-shared-config-update-template.yml@main
14
14
  permissions:
15
15
  contents: write
16
16
  issues: write
@@ -0,0 +1,18 @@
1
+ name: Publish Userscript
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+
9
+ concurrency:
10
+ group: ${{ github.workflow }}-${{ github.ref }}
11
+ cancel-in-progress: true
12
+
13
+ jobs:
14
+ call-shared-publish:
15
+ uses: sapphire-sh/github-actions/.github/workflows/userscript-publish-template.yml@main
16
+ permissions:
17
+ contents: write
18
+ secrets: inherit