-
Notifications
You must be signed in to change notification settings - Fork 15
/
compile.js
47 lines (41 loc) · 1.56 KB
/
compile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Navbar.js | Compile SCSS Script
// Build script to compile and minify the CSS file from SCSS folder
// Usage: npm run compile-scss
const fs = require('fs');
const writeFileSync = fs.writeFileSync;
const sass = require('sass');
const pkg = require('./package.json');
const year = (new Date).getFullYear();
const args = {};
process.argv.map((x) => {const [name, value] = x.split(':'); args[name] = value; });
let banner = args.MIN === 'true'
? `/* Navbar.js v${pkg.version} | ${pkg.author} © ${year} | ${pkg.license}-License */`
: `/*!
* Navbar.js v${pkg.version} (${pkg.homepage})
* Copyright 2016-${year} © ${pkg.author}
* Licensed under MIT (https://github.com/thednp/navbar.js/blob/master/LICENSE)
*/`;
let INPUTFILE = args.INPUTFILE ? args.INPUTFILE : './src/scss/navbar.scss'
let OUTPUTFILE = args.OUTPUTFILE ? args.OUTPUTFILE : `./dist/css/navbar${(args.MIN?'.min':'')}.css`
let COMPRESS = args.MIN === 'true' ? 'compressed' : 'expanded'
let COPY = args.COPY === 'true' || false
// Helper Functions
function compile(inputPath, writePath, compressType) {
const result = sass.compile(inputPath, {
style: compressType,
loadPaths: ["src/scss"]
})
writeFileSync(writePath, `${banner}\n` + result.css.toString())
console.log(`✅ Compiled ${inputPath} to ${writePath}.`)
}
function copy(input,output) {
fs.copyFile(input, output, (err) => {
if (err) throw err;
console.log(`✅ Copied ${input} to ${output}`);
});
}
if (COPY) {
copy(INPUTFILE, OUTPUTFILE)
} else {
compile(INPUTFILE,OUTPUTFILE,COMPRESS)
}