forked from thednp/navbar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile.js
52 lines (45 loc) · 1.63 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
48
49
50
51
52
// 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'),
writeFileSync = fs.writeFileSync,
sass = require('sass'),
pkg = require('./package.json'),
year = (new Date).getFullYear(),
args = {};
process.argv.map((x) => {let y=x.split(':'); args[y[0]] = y[1]; });
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) {
// console.log(`Compiling ${inputPath} - ${pkg.version}..`);
let result = sass.renderSync({
file: inputPath,
// sourceMap: true,
outFile: writePath,
outputStyle: compressType,
includePaths: ["src/scss"]
})
writeFileSync(writePath, `${banner}\n` + result.css.toString())
console.log(`Compiled ${inputPath} - ${pkg.version} to ${writePath}.`)
}
function copy(input,output) {
fs.copyFile(input, output, (err) => {
if (err) throw err;
console.log(`${input} was copied to ${output}`);
});
}
if (COPY) {
copy(INPUTFILE, OUTPUTFILE)
} else {
compile(INPUTFILE,OUTPUTFILE,COMPRESS)
}