aboutsummaryrefslogtreecommitdiff
path: root/packages/assets
diff options
context:
space:
mode:
authorPauline <git@ethanlibs.co>2023-10-14 22:27:27 -0400
committerPauline <git@ethanlibs.co>2023-10-14 22:27:27 -0400
commit2582162cea2b3a59cd21c78f8b73cb03d0acad40 (patch)
tree432057475f3b51850a85e2cba9969bcb79f3a8e6 /packages/assets
parent06f51ccdc496a6581d098edc424f3973e550221d (diff)
downloadNexus-2582162cea2b3a59cd21c78f8b73cb03d0acad40.tar.gz
Nexus-2582162cea2b3a59cd21c78f8b73cb03d0acad40.tar.bz2
Nexus-2582162cea2b3a59cd21c78f8b73cb03d0acad40.zip
refactor(trunk): refactor the entire project idk
Diffstat (limited to 'packages/assets')
-rw-r--r--packages/assets/README.md3
-rw-r--r--packages/assets/package.json8
-rw-r--r--packages/assets/scripts/generate.mjs62
3 files changed, 73 insertions, 0 deletions
diff --git a/packages/assets/README.md b/packages/assets/README.md
new file mode 100644
index 0000000..bbe042c
--- /dev/null
+++ b/packages/assets/README.md
@@ -0,0 +1,3 @@
+# shared assets
+
+all svgs and other shared assets put here
diff --git a/packages/assets/package.json b/packages/assets/package.json
new file mode 100644
index 0000000..cc29174
--- /dev/null
+++ b/packages/assets/package.json
@@ -0,0 +1,8 @@
+{
+ "name": "@polyfrost/assets",
+ "version": "0.0.0",
+ "private": true,
+ "scripts": {
+ "gen": "node ./scripts/generate.mjs"
+ }
+}
diff --git a/packages/assets/scripts/generate.mjs b/packages/assets/scripts/generate.mjs
new file mode 100644
index 0000000..44ba4e4
--- /dev/null
+++ b/packages/assets/scripts/generate.mjs
@@ -0,0 +1,62 @@
+import fs from 'node:fs/promises';
+import { dirname, join } from 'node:path';
+import { fileURLToPath } from 'node:url';
+import prettier from 'prettier';
+
+const assetFolders = ['icons', 'images', 'svgs/brands', 'svgs/ext/Extras', 'svgs/ext/Code'];
+
+const __filename = fileURLToPath(import.meta.url);
+const __dirname = dirname(__filename);
+
+prettier.resolveConfig(join(__dirname, '..', '..', '..', '.prettierrc.js')).then((options) =>
+ Promise.all(
+ assetFolders.map(async (folder) => {
+ const indexFilePath = join(__dirname, '..', folder, 'index.ts');
+ const assetsFolderPath = join(__dirname, '..', folder);
+
+ if (
+ await fs.access(indexFilePath).then(
+ () => true,
+ () => false
+ )
+ ) {
+ await fs.unlink(indexFilePath);
+ }
+
+ const fileNames = await fs.readdir(assetsFolderPath);
+
+ const assetImports = fileNames
+ .filter((fileName) => fileName !== 'index.ts' && !/(^|\/)\.[^\/\.]/g.test(fileName))
+ .map((fileName) => {
+ const variableName = fileName.split('.')[0].replace(/-/g, '');
+ if (folder.startsWith('svgs')) {
+ return `import { ReactComponent as ${variableName} } from './${fileName}';`;
+ }
+ return `import ${variableName} from './${fileName}';`;
+ })
+ .join('\n');
+
+ const assetExports = fileNames
+ .filter((fileName) => fileName !== 'index.ts' && !/(^|\/)\.[^\/\.]/g.test(fileName))
+ .map((fileName) => `${fileName.split('.')[0].replace(/-/g, '')}`)
+ .join(',\n');
+
+ const indexFileContent = await prettier.format(
+ `
+ /*
+ * This file was automatically generated by a script.
+ * To regenerate this file, run: pnpm assets gen
+ */
+
+ ${assetImports}
+
+ export {
+ ${assetExports}
+ };`,
+ { ...options, parser: 'typescript' }
+ );
+
+ await fs.writeFile(indexFilePath, indexFileContent);
+ })
+ )
+);