Comparing version 0.2.1 to 0.3.0
#!/usr/bin/env node | ||
'use strict'; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }(); | ||
@@ -45,3 +47,4 @@ | ||
_commander2.default.option('-p, --parser [name]', 'Parser name which is already installed as prejss-NAME-parser package'); | ||
_commander2.default.option('-c, --config [value]', 'Parser config passed to postcss', parseConfig); | ||
_commander2.default.option('-c, --config [value]', 'Config values passed to specified or default parser', parseConfig); | ||
_commander2.default.option('-v, --verbose', 'Enabled detailed debug output'); | ||
_commander2.default.option('--pretty', 'Prettify output result'); | ||
@@ -91,2 +94,3 @@ | ||
var config = _commander2.default['config']; | ||
var verbose = _commander2.default['verbose'] || false; | ||
@@ -107,6 +111,9 @@ if (errors.length > 0) { | ||
pretty: pretty, | ||
config: config | ||
config: config, | ||
verbose: verbose | ||
}; | ||
console.log('DEBUG: ', { options: options }); | ||
if (options.verbose) { | ||
console.log('Calculated options: ', { options: options }); | ||
} | ||
@@ -118,3 +125,3 @@ sourceFiles.forEach(function (name) { | ||
var finalPath = _path2.default.join(name, fileInDir); | ||
(0, _processFile2.default)(finalPath, options); | ||
(0, _processFile2.default)(finalPath, _extends({}, options, { sourceDir: name })); | ||
}); | ||
@@ -121,0 +128,0 @@ } else { |
@@ -26,2 +26,3 @@ 'use strict'; | ||
exports.default = function (file, options) { | ||
var code = _fs2.default.readFileSync(file, 'utf-8'); | ||
@@ -35,11 +36,45 @@ var parser = require(options.parser); | ||
var name = (0, _getNameWithoutExt2.default)(source.pop()); | ||
var format = options.format === 'json' ? 'json' : 'js'; | ||
var parsed = parser(code, { config: options.config }); | ||
var finalName = name + '.' + format; | ||
if (options.outDir) { | ||
source.shift(); | ||
source.unshift(options.outDir); | ||
var outExt = options.format === 'json' ? 'json' : 'js'; | ||
var outName = name + '.' + outExt; | ||
var outDir = void 0; | ||
if (options.sourceDir) { | ||
// When we have a basic directory, e.g: ./examples/src | ||
var subDir = _path2.default.relative(options.sourceDir, source.join(_path2.default.sep)); | ||
if (options.verbose) { | ||
console.log('Found source directory', { | ||
subDir: subDir, | ||
outDir: _path2.default.join(options.outDir || options.sourceDir, subDir) | ||
}); | ||
} | ||
outDir = _path2.default.join(options.outDir || options.sourceDir, subDir); | ||
} else if (options.outDir) { | ||
// When we have a output directory only, e.g. ./examples/dist | ||
if (options.verbose) { | ||
console.log('Found output directory only', { | ||
outDir: options.outDir | ||
}); | ||
} | ||
outDir = options.outDir; | ||
} else { | ||
// When we have to place output file in the same directory, e.g. ./examples/src | ||
if (options.verbose) { | ||
console.log('No source and output directory found', { | ||
outDir: source.join(_path2.default.sep) | ||
}); | ||
} | ||
outDir = source.join(_path2.default.sep); | ||
} | ||
source.push(finalName); | ||
var finalPath = source.join(_path2.default.sep); | ||
// source.push(finalName) | ||
// const finalPath = source.join(path.sep) | ||
var output = JSON.stringify(parsed, null, options.pretty ? 2 : 0); | ||
@@ -54,4 +89,6 @@ switch (options.format) { | ||
} | ||
(0, _outputFileSync2.default)(finalPath, output); | ||
console.log('Process: ' + name + ' -> ' + finalPath); | ||
var finalFile = _path2.default.join(outDir, outName); | ||
console.log('Process: ' + name + ' -> ' + finalFile); | ||
(0, _outputFileSync2.default)(finalFile, output); | ||
}; |
{ | ||
"name": "prejss-cli", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "Get ES6 or CommonJS modules from CSS/SCSS/LESS styles using PreJSS", | ||
@@ -12,2 +12,5 @@ "main": "lib/index.js", | ||
"build:lib": "babel src --out-dir lib", | ||
"build:examples-js": "./lib/cli.js ./examples/src --out-dir ./examples/dist --config plugins=postcss-import,postcss-simple-vars,postcss-sassy-mixins", | ||
"build:examples-json": "./lib/cli.js ./examples/src -f json --pretty --out-dir ./examples/dist --config plugins=postcss-import,postcss-simple-vars,postcss-sassy-mixins", | ||
"build:examples": "npm run build:examples-js && npm run build:examples-json", | ||
"lint": "eslint src", | ||
@@ -18,3 +21,3 @@ "flow": "flow check src", | ||
"test:clean": "rm -rf ./tests/.tmp", | ||
"build": "npm run build:lib && chmod u+x lib/cli.js", | ||
"build": "npm run build:lib && chmod u+x lib/cli.js && npm run build:examples", | ||
"example": "./lib/cli.js -f json examples --pretty --out-dir ./dist --config plugins=postcss-import,postcss-simple-vars,postcss-sassy-mixins", | ||
@@ -21,0 +24,0 @@ "prepublish": "npm run clean && npm run build" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
395
19446
16