// 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)
}
@@ -156,14 +156,15 @@
 fs')
-, %0A   
+;%0Aconst
  wri
@@ -192,21 +192,23 @@
 FileSync
-,%0A   
+;%0Aconst
  sass = 
@@ -222,21 +222,23 @@
 ('sass')
-,%0A   
+;%0Aconst
  pkg = r
@@ -261,21 +261,23 @@
 e.json')
-,%0A   
+;%0Aconst
  year = 
@@ -300,21 +300,23 @@
 llYear()
-,%0A   
+;%0Aconst
  args = 
@@ -349,14 +349,30 @@
 =%3E %7B
-let y=
+const %5Bname, value%5D = 
 x.sp
@@ -390,26 +390,26 @@
 rgs%5B
-y%5B0%5D%5D = y%5B1%5D
+name%5D = value
 ; %7D);
- 
 %0A%0Ale

update compile script