@sapphire-sh/utils 3.1.0 → 3.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/bin/sapphire-bootstrap.js +48 -0
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
import { spawnSync } from 'node:child_process';
|
|
3
4
|
import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
5
|
import { basename, dirname, join } from 'node:path';
|
|
5
6
|
import { fileURLToPath } from 'node:url';
|
|
@@ -133,6 +134,51 @@ const writeWorkflow = (outputName, template) => {
|
|
|
133
134
|
console.log(`wrote ${outputName}`);
|
|
134
135
|
};
|
|
135
136
|
|
|
137
|
+
const writeDependabotConfig = (outputName, template) => {
|
|
138
|
+
const filepath = join(cwd, outputName);
|
|
139
|
+
const manifestDirectories = [];
|
|
140
|
+
const trackedFiles = spawnSync('git', ['ls-files'], { cwd, encoding: 'utf-8' });
|
|
141
|
+
|
|
142
|
+
if (trackedFiles.status === 0) {
|
|
143
|
+
for (const path of trackedFiles.stdout.split('\n')) {
|
|
144
|
+
if (basename(path) === 'package.json' && dirname(path) !== '.') {
|
|
145
|
+
manifestDirectories.push(`/${dirname(path)}`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
} else {
|
|
149
|
+
const pendingDirectories = [''];
|
|
150
|
+
|
|
151
|
+
while (pendingDirectories.length > 0) {
|
|
152
|
+
const relativeDirectory = pendingDirectories.pop();
|
|
153
|
+
|
|
154
|
+
for (const entry of readdirSync(join(cwd, relativeDirectory), { withFileTypes: true })) {
|
|
155
|
+
if (entry.isDirectory() && entry.name !== 'node_modules' && entry.name !== '.git') {
|
|
156
|
+
pendingDirectories.push(relativeDirectory === '' ? entry.name : `${relativeDirectory}/${entry.name}`);
|
|
157
|
+
} else if (entry.isFile() && entry.name === 'package.json' && relativeDirectory !== '') {
|
|
158
|
+
manifestDirectories.push(`/${relativeDirectory}`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
let content = template;
|
|
165
|
+
|
|
166
|
+
if (manifestDirectories.length > 0) {
|
|
167
|
+
const directoryLines = ['/', ...manifestDirectories]
|
|
168
|
+
.toSorted()
|
|
169
|
+
.map((directory) => ` - ${formatYamlValue(directory)}\n`)
|
|
170
|
+
.join('');
|
|
171
|
+
content = template.replace(
|
|
172
|
+
' - package-ecosystem: npm\n directory: /\n',
|
|
173
|
+
` - package-ecosystem: npm\n directories:\n${directoryLines}`,
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
mkdirSync(dirname(filepath), { recursive: true });
|
|
178
|
+
writeFileSync(filepath, content);
|
|
179
|
+
console.log(`wrote ${outputName}`);
|
|
180
|
+
};
|
|
181
|
+
|
|
136
182
|
const collectTemplates = (directory, prefix) => {
|
|
137
183
|
const relativePaths = [];
|
|
138
184
|
|
|
@@ -221,6 +267,8 @@ for (const relativePath of collectTemplates(templatesDir, '')) {
|
|
|
221
267
|
|
|
222
268
|
if (dirname(outputName) === workflowsDir) {
|
|
223
269
|
writeWorkflow(outputName, readFileSync(join(templatesDir, relativePath), 'utf-8'));
|
|
270
|
+
} else if (outputName === join('.github', 'dependabot.yml')) {
|
|
271
|
+
writeDependabotConfig(outputName, readFileSync(join(templatesDir, relativePath), 'utf-8'));
|
|
224
272
|
} else if (sectioned.has(outputName)) {
|
|
225
273
|
const content = readFileSync(join(templatesDir, relativePath), 'utf-8');
|
|
226
274
|
writeSectioned(outputName, content);
|