Skip to content

Commit

Permalink
add gh releases to build script.
Browse files Browse the repository at this point in the history
  • Loading branch information
ItzDerock committed Jun 1, 2022
1 parent 3bd06cc commit d7302ff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
/dist
yarn.lock
yarn.lock
gh-release
26 changes: 25 additions & 1 deletion build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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!`));

0 comments on commit d7302ff

Please sign in to comment.