Created
January 7, 2021 10:11
-
-
Save Dragod/de478e913b632d53f3dd6d801235e41d to your computer and use it in GitHub Desktop.
build-skin with node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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