123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- import * as path from 'path'
- import * as fs from 'fs';
- import { log } from 'console';
- const assetsPath = 'assets';
- const tsPath = './libs';
- const tsAssetsPath = path.join(tsPath, assetsPath);
- fs.readdir(assetsPath, (err, files) => {
- if (err) {
- console.error(err);
- return;
- }
-
- files.forEach((file) => {
- const filePath = path.join(assetsPath, file);
- const stat = fs.statSync(filePath);
- if (stat.isDirectory()) {
- console.log(`dir: ${filePath}`);
- } else if (stat.isFile()) {
-
-
- const fileName = path.basename(file, path.extname(file)).replace(/-([a-z])/g, (_, letter) => letter.toUpperCase())
- const tsFileName = fileName + '.ts';
- const tsFilePath = path.join(tsAssetsPath, tsFileName);
- console.log()
- console.log('tsName:' + tsFileName)
-
- let tsFileContent = `import ${fileName} from '../../assets/${path.basename(file).toString()}' \n export default ${fileName}`;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- fs.writeFileSync(tsFilePath, tsFileContent);
- console.log(`ts file ${tsFileName} created!`);
- }
- });
- });
|