Skip to content

Commit

Permalink
add uno include statement to client components
Browse files Browse the repository at this point in the history
  • Loading branch information
a-type committed Jun 29, 2024
1 parent b9e1569 commit f34d713
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
}
},
"scripts": {
"build": "tsc",
"build": "pnpm run build:transpile && pnpm run build:prefix",
"build:transpile": "tsc",
"build:prefix": "node ./scripts/addUnoInclude.mjs",
"dev": "tsc --watch"
},
"type": "module",
Expand Down
38 changes: 38 additions & 0 deletions packages/client/scripts/addUnoInclude.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// adds "// @unocss-include" to the top of every file in dist
// this is used to tell unocss to include the file in the build
// files are nested in dist, so we need to recursively add the include

import fs from 'fs';
import path from 'path';

const distDir = path.join(process.cwd(), 'dist/components');

const addInclude = (dir) => {
const files = fs.readdirSync(dir);

files.forEach((file) => {
const filePath = path.join(dir, file);
const stat = fs.statSync(filePath);

if (stat.isDirectory()) {
addInclude(filePath);
// only .js files
} else if (filePath.endsWith('.d.ts')) {
// do nothing
} else if (
path.extname(filePath) === '.js' ||
path.extname(filePath) === '.mjs' ||
path.extname(filePath) === '.cjs' ||
path.extname(filePath) === '.ts'
) {
const fileContents = fs.readFileSync(filePath, 'utf8');
const lines = fileContents.split('\n');
lines.splice(0, 0, '// @unocss-include');
fs.writeFileSync(filePath, lines.join('\n'));
}
});
};

addInclude(distDir);

console.log('Added @unocss-include to all files in dist');

0 comments on commit f34d713

Please sign in to comment.