{"size": 1439, "ext": "js", "max_stars_repo_path": "buildcss.js", "max_stars_repo_name": "wenjinghuan999/utools-ScriptRunner", "max_stars_repo_stars_event_min_datetime": "2021-11-17T16:19:47.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-17T16:19:47.000Z", "max_issues_repo_path": "buildcss.js", "max_issues_repo_name": "wenjinghuan999/utools-ScriptRunner", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "buildcss.js", "max_forks_repo_name": "wenjinghuan999/utools-ScriptRunner", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 36.8974358974, "max_line_length": 100, "alphanum_fraction": 0.4857539958}
const stylus = require('stylus')
const path = require('path')
const fs = require('fs')
const sourcePath = path.join('src', 'styles', 'src')
const targetPath = path.join('src', 'styles')

fs.readdirSync(sourcePath).forEach(file => {
    const fullFile = path.join(sourcePath, file);
    if (fs.statSync(fullFile).isFile) {
        if (['.css', '.styl'].includes(path.extname(file))) {
            const fullTarget = path.join(targetPath, file.split('.')[0] + '.ts');
            console.log('Rendering ' + file);
            console.log(fullFile + ' => ' + fullTarget);
            const fileContent = fs.readFileSync(fullFile, {encoding: 'utf-8'}).replace(/`/g, '\\`');
            if (path.extname(file) == '.styl') {
                stylus.render(fileContent, (error, result) => {
                    if (error) {
                        console.log(error);
                    }
                    else {
                        fs.writeFileSync(fullTarget, `// language=CSS
export const Css: string = \`
${result.replace(/\n/g, '').trim()}
\``
                            , {encoding: 'utf8', flag: 'w+'});
                    }
                })
            } else {
                const result = fileContent;
                fs.writeFileSync(fullTarget, `// language=CSS
export const Css: string = \`
${result.replace(/\n/g, '').trim()}
\``
                    , {encoding: 'utf8', flag: 'w+'});
            }
        }
    }
});
