compile-less-cli
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -1,1 +0,4 @@ | ||
export {}; | ||
export interface ICompileOtion { | ||
out: string; | ||
combine: string; | ||
} |
@@ -8,5 +8,5 @@ "use strict"; | ||
var executeLess_1 = require("./executeLess"); | ||
module.exports = function compile(dir, out) { | ||
module.exports = function compile(dir, option) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var inputDir, outputDir, files, lessSource; | ||
var inputDir, outputDir, files, lessSource, outputCssFile, cssStr; | ||
var _this = this; | ||
@@ -17,3 +17,3 @@ return tslib_1.__generator(this, function (_a) { | ||
inputDir = path_1.default.join(process.cwd(), dir); | ||
outputDir = path_1.default.join(process.cwd(), out); | ||
outputDir = path_1.default.join(process.cwd(), option.out); | ||
return [4 /*yield*/, getLessFiles_1.getLessFiles(inputDir)]; | ||
@@ -29,24 +29,33 @@ case 1: | ||
lessSource = _a.sent(); | ||
return [4 /*yield*/, Promise.all(lessSource.map(function (item) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var logPathIn, logPathOut; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
logPathIn = item.path.replace(process.cwd(), ''); | ||
item.path = item.path.replace(inputDir, outputDir).replace(/.less$/, '.css'); | ||
logPathOut = item.path.replace(process.cwd(), ''); | ||
console.log('log:', logPathIn, '->', logPathOut); | ||
return [4 /*yield*/, fs_extra_1.default.outputFile(item.path, item.css)]; | ||
case 1: | ||
_a.sent(); | ||
if (item.imports && item.imports.length > 0) { | ||
console.log('imports:', item.imports); | ||
} | ||
return [2 /*return*/, item]; | ||
} | ||
}); | ||
}); }))]; | ||
if (!option.combine) return [3 /*break*/, 4]; | ||
outputCssFile = path_1.default.join(process.cwd(), option.combine); | ||
cssStr = lessSource.map(function (item) { return item.css; }); | ||
return [4 /*yield*/, fs_extra_1.default.outputFile(outputCssFile, cssStr.join(''))]; | ||
case 3: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
console.log('log:', 'Output one file: ->', outputCssFile); | ||
return [3 /*break*/, 6]; | ||
case 4: return [4 /*yield*/, Promise.all(lessSource.map(function (item) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var logPathIn, logPathOut; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
logPathIn = item.path.replace(process.cwd(), ''); | ||
item.path = item.path.replace(inputDir, outputDir).replace(/.less$/, '.css'); | ||
logPathOut = item.path.replace(process.cwd(), ''); | ||
console.log('log:', logPathIn, '->', logPathOut); | ||
return [4 /*yield*/, fs_extra_1.default.outputFile(item.path, item.css)]; | ||
case 1: | ||
_a.sent(); | ||
if (item.imports && item.imports.length > 0) { | ||
console.log('imports:', item.imports); | ||
} | ||
return [2 /*return*/, item]; | ||
} | ||
}); | ||
}); }))]; | ||
case 5: | ||
_a.sent(); | ||
_a.label = 6; | ||
case 6: return [2 /*return*/]; | ||
} | ||
@@ -53,0 +62,0 @@ }); |
@@ -11,7 +11,9 @@ var program = require('commander'); | ||
.option('-d, --dir <dir-path>', 'Less file directory', 'src') | ||
.option('-o, --out <dir-path>', 'Output directory.'); | ||
.option('-o, --out <dir-path>', 'Output directory.') | ||
.option('-c, --combine <file-name>', 'Combine CSS files.'); | ||
program.on('--help', function () { | ||
logs('\n Examples:'); | ||
logs(); | ||
logs(" $ compile-less -d src -o css"); | ||
logs(' $ compile-less -d src -o css'); | ||
logs(' $ compile-less -d src -o out --combine out/dist.css'); | ||
logs(); | ||
@@ -25,3 +27,6 @@ logs(); | ||
else { | ||
compile(program.dir, program.out); | ||
compile(program.dir, { | ||
out: program.out, | ||
combine: program.combine, | ||
}); | ||
} |
{ | ||
"name": "compile-less-cli", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "compile less", | ||
@@ -5,0 +5,0 @@ "bin": { |
@@ -6,3 +6,3 @@ compile-less | ||
## Install | ||
### Install | ||
@@ -13,2 +13,15 @@ ```bash | ||
### Basic Usage | ||
```js | ||
const compileLess = require('compile-less-cli'); | ||
compileLess('src', { | ||
out: 'out', // Output directory. | ||
combine: 'dist/uiw.css', // Combine CSS files. | ||
}); | ||
``` | ||
### Command Line | ||
Command help: | ||
@@ -22,6 +35,7 @@ | ||
Options: | ||
-v, --version output the version number | ||
-d, --dir <dir-path> Less file directory (default: "src") | ||
-o, --out <dir-path> Output directory. | ||
-h, --help output usage information | ||
-v, --version output the version number | ||
-d, --dir <dir-path> Less file directory (default: "src") | ||
-o, --out <dir-path> Output directory. | ||
-c, --combine <file-name> Combine CSS files. | ||
-h, --help output usage information | ||
@@ -33,3 +47,3 @@ Examples: | ||
## Development | ||
### Development | ||
@@ -36,0 +50,0 @@ Listen for files compiled with TypeScript |
8776
56
11
180