diff --git a/.gitignore b/.gitignore index 8eb508a..f7fcda0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ node_modules /dist -yarn.lock \ No newline at end of file +yarn.lock +gh-release \ No newline at end of file diff --git a/build.mjs b/build.mjs index d45c13c..f93879b 100644 --- a/build.mjs +++ b/build.mjs @@ -7,7 +7,8 @@ import CleanCSS from 'clean-css'; $.verbose = true; // some useful variables -var isWin = process.platform === "win32"; +const version = JSON.parse(fs.readFileSync('./package.json')).version; +var isWin = process.platform === "win32"; // if on windows, force zx to use cmd.exe (otherwise it will use wsl) if(isWin) { @@ -46,5 +47,28 @@ const minified = new CleanCSS().minify(style); if(minified.errors?.length) console.warn(chalk.yellow(`[!] CSS errors: ${minified.errors.join(', ')}`)); fs.writeFileSync('./dist/template.css', minified.styles); +// Create releases +console.log(chalk.green(`» Creating releases...`)); +await fs.mkdir('./gh-release', { recursive: true }); + +// read all the .__ignore files +const alwaysIgnore = ['gh-release', 'node_modules', '.git']; +const gitIgnore = fs.readFileSync('./.gitignore', 'utf8').split('\n').map(e => e.trim()).filter(e => !alwaysIgnore.includes(e) && e); +const npmIgnore = fs.readFileSync('.npmignore', 'utf8') .split('\n').map(e => e.trim()).filter(e => !alwaysIgnore.includes(e) && e); + +// before each element in the array add a "-x" element +const excludeFlag = isWin ? '--exclude' : '-x'; +const alwaysIgnoreCLIFlags = alwaysIgnore.map(x => [excludeFlag, x]).flat(); +const gitIgnoreCLIFlags = gitIgnore .map(x => [excludeFlag, x]).flat(); +const npmIgnoreCLIFlags = npmIgnore .map(x => [excludeFlag, x]).flat(); + +// dist zip +if(isWin) await $`tar.exe -c ${alwaysIgnoreCLIFlags} ${npmIgnoreCLIFlags} -a -f ./gh-release/dist-${version}.zip .` +else await $`zip ${alwaysIgnoreCLIFlags} ${npmIgnoreCLIFlags} -r ./gh-release/dist-${version}.zip .`; + +// source zip +if(isWin) await $`tar.exe -c ${alwaysIgnoreCLIFlags} ${gitIgnoreCLIFlags} -a -f ./gh-release/source-${version}.zip .` +else await $`zip ${alwaysIgnoreCLIFlags} ${gitIgnoreCLIFlags} -r ./gh-release/source-${version}.zip .`; + // thats it for now! console.log(chalk.green(`» Done!`)); \ No newline at end of file