@sapphire-sh/utils 2.9.0 → 2.11.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/bin/sapphire-bootstrap.js +56 -10
- package/package.json +1 -1
- package/templates/.github/dependabot.yml +18 -0
- package/templates/.github/workflows/docker-publish.yml +17 -0
- package/templates/.github/workflows/npm-audit-fix.yml +1 -0
- package/templates/.github/workflows/shared-config-update.yml +17 -0
- package/templates/.github/workflows/utils-update.yml +0 -13
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
|
|
4
|
-
import { dirname, join } from 'node:path';
|
|
3
|
+
import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { basename, dirname, join } from 'node:path';
|
|
5
5
|
import { fileURLToPath } from 'node:url';
|
|
6
6
|
|
|
7
7
|
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
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
]);
|
|
14
|
+
const workflowsDir = join('.github', 'workflows');
|
|
15
|
+
const workflowValuesPath = join('.github', 'sapphire-workflows.json');
|
|
16
|
+
const withLinePattern = /^\s*with:\s*$/m;
|
|
17
|
+
const requiredFiles = new Map([[join(workflowsDir, 'docker-publish.yml'), 'Dockerfile']]);
|
|
18
18
|
|
|
19
19
|
const sectioned = new Set(['.gitignore', '.prettierignore']);
|
|
20
20
|
const renameMap = new Map([
|
|
@@ -41,7 +41,18 @@ const readPackageName = () => {
|
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
+
const readWorkflowValues = () => {
|
|
45
|
+
const filepath = join(cwd, workflowValuesPath);
|
|
46
|
+
|
|
47
|
+
if (existsSync(filepath) === false) {
|
|
48
|
+
return {};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return JSON.parse(readFileSync(filepath, 'utf-8'));
|
|
52
|
+
};
|
|
53
|
+
|
|
44
54
|
const isSelf = readPackageName() === selfPackageName;
|
|
55
|
+
const workflowValues = readWorkflowValues();
|
|
45
56
|
|
|
46
57
|
const writeSectioned = (outputName, content) => {
|
|
47
58
|
const filepath = join(cwd, outputName);
|
|
@@ -68,6 +79,30 @@ const writeSectioned = (outputName, content) => {
|
|
|
68
79
|
console.log(`wrote ${outputName}`);
|
|
69
80
|
};
|
|
70
81
|
|
|
82
|
+
const writeWorkflow = (outputName, template) => {
|
|
83
|
+
const filepath = join(cwd, outputName);
|
|
84
|
+
const values = workflowValues[basename(outputName, '.yml')];
|
|
85
|
+
let content = template;
|
|
86
|
+
|
|
87
|
+
if (values === undefined) {
|
|
88
|
+
if (existsSync(filepath) && withLinePattern.test(readFileSync(filepath, 'utf-8'))) {
|
|
89
|
+
console.log(`warning: ${outputName} had with: values that are not in ${workflowValuesPath}`);
|
|
90
|
+
}
|
|
91
|
+
} else {
|
|
92
|
+
if (withLinePattern.test(template) === false) {
|
|
93
|
+
content += ' with:\n';
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
for (const [key, value] of Object.entries(values)) {
|
|
97
|
+
content += ` ${key}: ${JSON.stringify(value)}\n`;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
mkdirSync(dirname(filepath), { recursive: true });
|
|
102
|
+
writeFileSync(filepath, content);
|
|
103
|
+
console.log(`wrote ${outputName}`);
|
|
104
|
+
};
|
|
105
|
+
|
|
71
106
|
const collectTemplates = (directory, prefix) => {
|
|
72
107
|
const relativePaths = [];
|
|
73
108
|
|
|
@@ -93,12 +128,14 @@ for (const relativePath of collectTemplates(templatesDir, '')) {
|
|
|
93
128
|
continue;
|
|
94
129
|
}
|
|
95
130
|
|
|
96
|
-
if (
|
|
131
|
+
if (requiredFiles.has(outputName) && existsSync(join(cwd, requiredFiles.get(outputName))) === false) {
|
|
97
132
|
console.log(`skipped ${outputName}`);
|
|
98
133
|
continue;
|
|
99
134
|
}
|
|
100
135
|
|
|
101
|
-
if (
|
|
136
|
+
if (dirname(outputName) === workflowsDir) {
|
|
137
|
+
writeWorkflow(outputName, readFileSync(join(templatesDir, relativePath), 'utf-8'));
|
|
138
|
+
} else if (sectioned.has(outputName)) {
|
|
102
139
|
const content = readFileSync(join(templatesDir, relativePath), 'utf-8');
|
|
103
140
|
writeSectioned(outputName, content);
|
|
104
141
|
} else {
|
|
@@ -107,3 +144,12 @@ for (const relativePath of collectTemplates(templatesDir, '')) {
|
|
|
107
144
|
console.log(`wrote ${outputName}`);
|
|
108
145
|
}
|
|
109
146
|
}
|
|
147
|
+
|
|
148
|
+
for (const relativePath of obsoleteFiles) {
|
|
149
|
+
const filepath = join(cwd, relativePath);
|
|
150
|
+
|
|
151
|
+
if (existsSync(filepath)) {
|
|
152
|
+
rmSync(filepath);
|
|
153
|
+
console.log(`removed ${relativePath}`);
|
|
154
|
+
}
|
|
155
|
+
}
|
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: Build and Push Docker Image
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
|
|
8
|
+
concurrency:
|
|
9
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
10
|
+
cancel-in-progress: true
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
call-shared-ci:
|
|
14
|
+
uses: sapphire-sh/github-actions/.github/workflows/docker-ci-template.yml@main
|
|
15
|
+
secrets: inherit
|
|
16
|
+
with:
|
|
17
|
+
image_name: ${{ github.event.repository.name }}
|
|
@@ -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
|