-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add uno include statement to client components
- Loading branch information
Showing
2 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |