@sapphire-sh/utils 1.74.0 → 1.75.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,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import { copyFileSync, existsSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
4
- import { join } from 'node:path';
3
+ import { copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
4
+ import { dirname, join } from 'node:path';
5
5
  import { fileURLToPath } from 'node:url';
6
6
 
7
7
  const START_MARKER = '# @sapphire-sh/utils:start';
@@ -42,13 +42,31 @@ const writeSectioned = (outputName, content) => {
42
42
  console.log(`wrote ${outputName}`);
43
43
  };
44
44
 
45
- for (const filename of readdirSync(templatesDir)) {
46
- const outputName = renameMap.get(filename) ?? filename;
45
+ const collectTemplates = (directory, prefix) => {
46
+ const relativePaths = [];
47
+
48
+ for (const entry of readdirSync(directory, { withFileTypes: true })) {
49
+ const relativePath = prefix === '' ? entry.name : join(prefix, entry.name);
50
+
51
+ if (entry.isDirectory()) {
52
+ relativePaths.push(...collectTemplates(join(directory, entry.name), relativePath));
53
+ } else {
54
+ relativePaths.push(relativePath);
55
+ }
56
+ }
57
+
58
+ return relativePaths;
59
+ };
60
+
61
+ for (const relativePath of collectTemplates(templatesDir, '')) {
62
+ const outputName = renameMap.get(relativePath) ?? relativePath;
47
63
  if (sectioned.has(outputName)) {
48
- const content = readFileSync(join(templatesDir, filename), 'utf-8');
64
+ const content = readFileSync(join(templatesDir, relativePath), 'utf-8');
49
65
  writeSectioned(outputName, content);
50
66
  } else {
51
- copyFileSync(join(templatesDir, filename), join(cwd, outputName));
67
+ const outputPath = join(cwd, outputName);
68
+ mkdirSync(dirname(outputPath), { recursive: true });
69
+ copyFileSync(join(templatesDir, relativePath), outputPath);
52
70
  console.log(`wrote ${outputName}`);
53
71
  }
54
72
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sapphire-sh/utils",
3
- "version": "1.74.0",
3
+ "version": "1.75.0",
4
4
  "description": "@sapphire-sh/utils",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -0,0 +1,13 @@
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
+ pull-requests: write