Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fs = require("fs");
- var accord = require('accord');
- var assign = require('object-assign');
- var path = require('path');
- var replaceExt = require('replace-ext');
- const readlineSync = require('readline-sync');
- var less = accord.load('less');
- var options = {}
- var _id = process.argv.indexOf("--src")+1;
- if (_id) console.time('Time');
- var opts = assign({}, {
- compress: false,
- paths: []
- }, options);
- var render = function (str, opts){
- less.render(str, opts).then(function(res) {
- var file = {}
- file.contents = Buffer.from(res.result);
- file.path = replaceExt(opts.filename, '.css');
- return file;
- }).then(function(file) {
- fs.writeFileSync(file.path, file.contents)
- console.log('compilled successfull')
- console.timeEnd('Time');
- }).catch(function(err) {
- // Convert the keys so PluginError can read them
- err.lineNumber = err.line;
- err.fileName = err.filename;
- // Add a better error message
- err.message = err.message + ' in file ' + err.fileName + ' line no. ' + err.lineNumber;
- console.log(err.message)
- });
- }
- var start = async function (){
- var flag = true;
- do{
- if (!_id){
- opts.filename = readlineSync.question('listening ');
- console.time('Time');
- }
- else{
- opts.filename = process.argv[_id];
- }
- if (!fs.existsSync(opts.filename)) {
- break;
- }
- var str = fs.readFileSync(opts.filename, "utf8");
- await render(str, opts);
- }while(flag);
- console.log('exit');
- }
- start();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement