Skip to content

Instantly share code, notes, and snippets.

@Dragod
Created January 7, 2021 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dragod/de478e913b632d53f3dd6d801235e41d to your computer and use it in GitHub Desktop.
Save Dragod/de478e913b632d53f3dd6d801235e41d to your computer and use it in GitHub Desktop.
build-skin with node
// Script to build unity skins via nodejs and override main.css with current skin.
// Need execSync to execute command in nodejs.
const execSync = require('child_process').execSync;
// Default value `amazon-site-lite` if no args provided via CLI.
const skin = process.argv[2] || 'amazon-site-lite';
// Work with file system.
const fs = require('fs');
// Sass path
const sassPath = "sass/skins/"
// Main css path
const mainPath = "css/main.css"
// Wrap node-sass command and override main.css.
function runNodeSass(skin)
{
// Run node-sass
execSync(`node-sass --source-map true ${sassPath}${skin}/${skin}.scss assets/${skin}/css/${skin}.css`, { stdio: [0, 1, 2] });
// Print a message when skin task is completed.
console.log(`\n\nBuild skin: ${skin} completed`);
// Override main.css with the current skin file.
fs.writeFileSync(`${mainPath}`, `@import url("app.css"); @import url("login.css"); @import url("../assets/${skin}/css/${skin}.css");`, { encoding: 'utf8', flag: 'w' });
// Print a message when main.css override is completed.
console.log(`Update main.css with ${skin} skin: @import url("../assets/${skin}/css/${skin}.css")`)
}
// Check if skin folder passed via argument exist, then run node-sass.
if (fs.existsSync(`sass/skins/${skin}/`)) {
runNodeSass(skin)
}
// If skin file does not exist, log an error message.
else if(!fs.existsSync(`sass/skins/${skin}/`))
{
console.log("The skin you're trying to build does not exist.\nIf you need a new skin, create a new folder inside \"sass\" and then add a new file with the skin name.\nEx: \"skinName.scss\"");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment