compile-less-cli
Advanced tools
Comparing version 1.8.13 to 1.8.14
import { IOutputFile } from './executeLess'; | ||
export interface ICompileOtion { | ||
export interface ICompileOption { | ||
out: string; | ||
@@ -9,4 +9,4 @@ combine?: string; | ||
export declare function getProjectName(): Promise<string>; | ||
export default function compile(dir: string, option: ICompileOtion): Promise<void>; | ||
export default function compile(dir: string, option: ICompileOption): Promise<void>; | ||
export declare function outputFile(data: IOutputFile, inputDir: string, outputDir: string): Promise<void>; | ||
export declare function log(output: string, input?: string): Promise<void>; |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -65,135 +7,74 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
exports.log = exports.outputFile = exports.getProjectName = void 0; | ||
var path_1 = __importDefault(require("path")); | ||
var fs_extra_1 = __importDefault(require("fs-extra")); | ||
var getLessFiles_1 = require("./getLessFiles"); | ||
var executeLess_1 = require("./executeLess"); | ||
function getProjectName() { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var pkgPath, projectName, pkg; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
pkgPath = path_1.default.resolve(process.cwd(), 'package.json'); | ||
projectName = ''; | ||
if (!fs_extra_1.default.existsSync(pkgPath)) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, fs_extra_1.default.readJSON(pkgPath)]; | ||
case 1: | ||
pkg = _a.sent(); | ||
projectName = pkg.name; | ||
_a.label = 2; | ||
case 2: return [2 /*return*/, projectName]; | ||
} | ||
}); | ||
}); | ||
const path_1 = __importDefault(require("path")); | ||
const fs_extra_1 = __importDefault(require("fs-extra")); | ||
const getLessFiles_1 = require("./getLessFiles"); | ||
const executeLess_1 = require("./executeLess"); | ||
async function getProjectName() { | ||
const pkgPath = path_1.default.resolve(process.cwd(), 'package.json'); | ||
let projectName = ''; | ||
if (fs_extra_1.default.existsSync(pkgPath)) { | ||
const pkg = await fs_extra_1.default.readJSON(pkgPath); | ||
projectName = pkg.name; | ||
} | ||
return projectName; | ||
} | ||
exports.getProjectName = getProjectName; | ||
function compile(dir, option) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _a, excludeCss, rmGlobal, combine, out, otherOpts, inputDir, projectName, files, lessSource, outputCssFile, cssStr, outputDir_1, error_1; | ||
var _this = this; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
_a = option || {}, excludeCss = _a.excludeCss, rmGlobal = _a.rmGlobal, combine = _a.combine, out = _a.out, otherOpts = __rest(_a, ["excludeCss", "rmGlobal", "combine", "out"]); | ||
inputDir = path_1.default.join(process.cwd(), dir); | ||
_b.label = 1; | ||
case 1: | ||
_b.trys.push([1, 12, , 13]); | ||
return [4 /*yield*/, getProjectName()]; | ||
case 2: | ||
projectName = _b.sent(); | ||
return [4 /*yield*/, (0, getLessFiles_1.getLessFiles)(inputDir, excludeCss ? /\.(less)$/ : undefined)]; | ||
case 3: | ||
files = _b.sent(); | ||
return [4 /*yield*/, Promise.all(files.map(function (lessPath) { return __awaiter(_this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, (0, executeLess_1.executeLess)(lessPath, __assign({ rmGlobal: rmGlobal }, otherOpts))]; | ||
}); | ||
}); }))]; | ||
case 4: | ||
lessSource = _b.sent(); | ||
if (!combine) return [3 /*break*/, 9]; | ||
outputCssFile = path_1.default.join(process.cwd(), combine); | ||
cssStr = lessSource.map(function (item) { return item.css; }); | ||
if (!!!cssStr.join('').trim()) return [3 /*break*/, 7]; | ||
return [4 /*yield*/, fs_extra_1.default.outputFile(outputCssFile, cssStr.join(''))]; | ||
case 5: | ||
_b.sent(); | ||
return [4 /*yield*/, log(path_1.default.relative(process.cwd(), outputCssFile))]; | ||
case 6: | ||
_b.sent(); | ||
return [3 /*break*/, 8]; | ||
case 7: | ||
console.log("\uD83D\uDEA7 \u001B[35m".concat(projectName, "\u001B[0m =>\u001B[33m No content is output.\u001B[0m")); | ||
_b.label = 8; | ||
case 8: return [3 /*break*/, 11]; | ||
case 9: | ||
outputDir_1 = path_1.default.join(process.cwd(), out); | ||
return [4 /*yield*/, Promise.all(lessSource.map(function (item) { return __awaiter(_this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, outputFile(item, inputDir, outputDir_1)]; | ||
}); | ||
}); }))]; | ||
case 10: | ||
_b.sent(); | ||
_b.label = 11; | ||
case 11: return [3 /*break*/, 13]; | ||
case 12: | ||
error_1 = _b.sent(); | ||
console.log('error:', error_1); | ||
return [3 /*break*/, 13]; | ||
case 13: return [2 /*return*/]; | ||
async function compile(dir, option) { | ||
const { excludeCss, rmGlobal, combine, out, ...otherOpts } = option || {}; | ||
const inputDir = path_1.default.join(process.cwd(), dir); | ||
try { | ||
const projectName = await getProjectName(); | ||
const files = await (0, getLessFiles_1.getLessFiles)(inputDir, excludeCss ? /\.(less)$/ : undefined); | ||
const lessSource = await Promise.all(files.map(async (lessPath) => { | ||
return (0, executeLess_1.executeLess)(lessPath, { rmGlobal, ...otherOpts }); | ||
})); | ||
if (combine) { | ||
const outputCssFile = path_1.default.join(process.cwd(), combine); | ||
const cssStr = lessSource.map((item) => item.css); | ||
if (!!cssStr.join('').trim()) { | ||
await fs_extra_1.default.outputFile(outputCssFile, cssStr.join('')); | ||
await log(path_1.default.relative(process.cwd(), outputCssFile)); | ||
} | ||
}); | ||
}); | ||
else { | ||
console.log(`🚧 \x1b[35m${projectName}\x1b[0m =>\x1b[33m No content is output.\x1b[0m`); | ||
} | ||
} | ||
else { | ||
const outputDir = path_1.default.join(process.cwd(), out); | ||
await Promise.all(lessSource.map(async (item) => { | ||
return outputFile(item, inputDir, outputDir); | ||
})); | ||
} | ||
} | ||
catch (error) { | ||
console.log('error:', error); | ||
} | ||
} | ||
exports.default = compile; | ||
function outputFile(data, inputDir, outputDir) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var logPathIn, logPathOut, error_2; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 3, , 4]); | ||
logPathIn = path_1.default.relative(process.cwd(), data.path); | ||
data.path = data.path.replace(inputDir, outputDir).replace(/.less$/, '.css'); | ||
logPathOut = path_1.default.relative(process.cwd(), data.path); | ||
return [4 /*yield*/, log(logPathOut, logPathIn)]; | ||
case 1: | ||
_a.sent(); | ||
return [4 /*yield*/, fs_extra_1.default.outputFile(data.path, data.css)]; | ||
case 2: | ||
_a.sent(); | ||
if (data.imports && data.imports.length > 0) { | ||
// console.log('\x1b[35m imports-> \x1b[0m:', data.imports); | ||
} | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
error_2 = _a.sent(); | ||
throw error_2; | ||
case 4: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
async function outputFile(data, inputDir, outputDir) { | ||
try { | ||
const logPathIn = path_1.default.relative(process.cwd(), data.path); | ||
data.path = data.path.replace(inputDir, outputDir).replace(/.less$/, '.css'); | ||
const logPathOut = path_1.default.relative(process.cwd(), data.path); | ||
await log(logPathOut, logPathIn); | ||
await fs_extra_1.default.outputFile(data.path, data.css); | ||
if (data.imports && data.imports.length > 0) { | ||
// console.log('\x1b[35m imports-> \x1b[0m:', data.imports); | ||
} | ||
} | ||
catch (error) { | ||
throw error; | ||
} | ||
} | ||
exports.outputFile = outputFile; | ||
function log(output, input) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var projectName; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, getProjectName()]; | ||
case 1: | ||
projectName = _a.sent(); | ||
if (input) { | ||
console.log("\u267B\uFE0F \u001B[32m ".concat(projectName, "\u001B[0m: ").concat(input, " \u2508> ").concat(output)); | ||
} | ||
else { | ||
console.log("\u267B\uFE0F \u001B[32m ".concat(projectName, "\u001B[0m: Output one file: \u2508> ").concat(output)); | ||
} | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
async function log(output, input) { | ||
const projectName = await getProjectName(); | ||
if (input) { | ||
console.log(`♻️ \x1b[32m ${projectName}\x1b[0m: ${input} ┈> ${output}`); | ||
} | ||
else { | ||
console.log(`♻️ \x1b[32m ${projectName}\x1b[0m: Output one file: ┈> ${output}`); | ||
} | ||
} | ||
exports.log = log; | ||
//# sourceMappingURL=compile.js.map |
@@ -7,5 +7,5 @@ /// <reference types="less" /> | ||
export declare function execute(command: string): Promise<unknown>; | ||
export declare type ExecuteLessOptions = Less.Options & { | ||
export type ExecuteLessOptions = Less.Options & { | ||
rmGlobal?: boolean; | ||
}; | ||
export declare function executeLess(lessPath: string, options?: ExecuteLessOptions): Promise<IOutputFile>; |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -29,8 +7,8 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
exports.executeLess = exports.execute = void 0; | ||
var fs_extra_1 = __importDefault(require("fs-extra")); | ||
var less_1 = __importDefault(require("less")); | ||
var child_process_1 = require("child_process"); | ||
const fs_extra_1 = __importDefault(require("fs-extra")); | ||
const less_1 = __importDefault(require("less")); | ||
const child_process_1 = require("child_process"); | ||
// @ts-ignore | ||
var less_plugin_autoprefix_1 = __importDefault(require("less-plugin-autoprefix")); | ||
var autoprefixPlugin = new less_plugin_autoprefix_1.default({ | ||
const less_plugin_autoprefix_1 = __importDefault(require("less-plugin-autoprefix")); | ||
const autoprefixPlugin = new less_plugin_autoprefix_1.default({ | ||
browsers: [ | ||
@@ -44,16 +22,16 @@ ">0.2%", | ||
function execute(command) { | ||
return new Promise(function (resolve, reject) { | ||
var subProcess = (0, child_process_1.spawn)('bash'); | ||
return new Promise((resolve, reject) => { | ||
const subProcess = (0, child_process_1.spawn)('bash'); | ||
function onData(data) { | ||
process.stdout.write(data); | ||
} | ||
subProcess.on('error', function (error) { | ||
reject(new Error("command failed: ".concat(command, "; ").concat(error.message ? error.message : ''))); | ||
subProcess.on('error', (error) => { | ||
reject(new Error(`command failed: ${command}; ${error.message ? error.message : ''}`)); | ||
}); | ||
subProcess.stdout.on('data', onData); | ||
subProcess.stderr.on('data', onData); | ||
subProcess.on('close', function (code) { | ||
subProcess.on('close', (code) => { | ||
resolve(code); | ||
}); | ||
subProcess.stdin.write("".concat(command, " \n")); | ||
subProcess.stdin.write(`${command} \n`); | ||
subProcess.stdin.end(); | ||
@@ -64,11 +42,18 @@ }); | ||
function executeLess(lessPath, options) { | ||
var lessStr = fs_extra_1.default.readFileSync(lessPath); | ||
var _a = options || {}, rmGlobal = _a.rmGlobal, other = __rest(_a, ["rmGlobal"]); | ||
return new Promise(function (resolve, reject) { | ||
var options = __assign(__assign({ depends: false, compress: false, lint: false, plugins: [autoprefixPlugin] }, other), { filename: lessPath }); | ||
var lessStrTo = lessStr.toString(); | ||
const lessStr = fs_extra_1.default.readFileSync(lessPath); | ||
const { rmGlobal, ...other } = options || {}; | ||
return new Promise((resolve, reject) => { | ||
const options = { | ||
depends: false, | ||
compress: false, | ||
lint: false, | ||
plugins: [autoprefixPlugin], | ||
...other, | ||
filename: lessPath, | ||
}; | ||
let lessStrTo = lessStr.toString(); | ||
if (rmGlobal) { | ||
lessStrTo = lessStrTo.replace(/:global\((.*)\)/g, '$1'); | ||
} | ||
less_1.default.render(lessStrTo, options).then(function (output) { | ||
less_1.default.render(lessStrTo, options).then((output) => { | ||
if (rmGlobal) { | ||
@@ -78,4 +63,11 @@ output.css = output.css.replace(/:global\s+\{([\s\S]*?)(\s.+)?\}/g, '') | ||
} | ||
resolve(__assign({ less: lessStr.toString(), path: lessPath }, output)); | ||
}).catch(function (e) { | ||
resolve({ | ||
less: lessStr.toString(), | ||
path: lessPath, | ||
// css: '', | ||
// map: 'string', | ||
// imports: [], | ||
...output, | ||
}); | ||
}).catch((e) => { | ||
reject(e); | ||
@@ -86,1 +78,2 @@ }); | ||
exports.executeLess = executeLess; | ||
//# sourceMappingURL=executeLess.js.map |
@@ -7,10 +7,9 @@ "use strict"; | ||
exports.getLessFiles = void 0; | ||
var directory_tree_1 = __importDefault(require("directory-tree")); | ||
function getLessFiles(folder, reg) { | ||
if (reg === void 0) { reg = /\.(less|css)$/; } | ||
return new Promise(function (resolve, reject) { | ||
var lessPaths = []; | ||
const directory_tree_1 = __importDefault(require("directory-tree")); | ||
function getLessFiles(folder, reg = /\.(less|css)$/) { | ||
return new Promise((resolve, reject) => { | ||
const lessPaths = []; | ||
(0, directory_tree_1.default)(folder, { | ||
extensions: reg | ||
}, function (item) { | ||
}, (item) => { | ||
lessPaths.push(item.path); | ||
@@ -22,1 +21,2 @@ }); | ||
exports.getLessFiles = getLessFiles; | ||
//# sourceMappingURL=getLessFiles.js.map |
158
lib/index.js
@@ -26,38 +26,2 @@ #!/usr/bin/env node | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -67,7 +31,7 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var minimist_1 = __importDefault(require("minimist")); | ||
var path_1 = __importDefault(require("path")); | ||
var chokidar_1 = __importDefault(require("chokidar")); | ||
var executeLess_1 = require("./executeLess"); | ||
var compile_1 = __importStar(require("./compile")); | ||
const minimist_1 = __importDefault(require("minimist")); | ||
const path_1 = __importDefault(require("path")); | ||
const chokidar_1 = __importDefault(require("chokidar")); | ||
const executeLess_1 = require("./executeLess"); | ||
const compile_1 = __importStar(require("./compile")); | ||
function outputHelp() { | ||
@@ -87,3 +51,3 @@ console.log('\n Usage: compile-less [options] [--help|h] [--version|v]'); | ||
} | ||
var argvs = (0, minimist_1.default)(process.argv.slice(2)); | ||
const argvs = (0, minimist_1.default)(process.argv.slice(2)); | ||
if (argvs.h || argvs.help) { | ||
@@ -93,5 +57,5 @@ outputHelp(); | ||
} | ||
var version = require('../package.json').version; | ||
const { version } = require('../package.json'); | ||
if (argvs.v || argvs.version) { | ||
console.log("\n compile-less v".concat(version, "\n")); | ||
console.log(`\n compile-less v${version}\n`); | ||
process.exit(0); | ||
@@ -109,40 +73,31 @@ } | ||
; | ||
(function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var inputDir, error_1; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 4, , 5]); | ||
inputDir = path_1.default.resolve(argvs.dir); | ||
if (!argvs.watch) return [3 /*break*/, 1]; | ||
chokidar_1.default.watch(inputDir).on('all', chokidarWatch).on('ready', function () { | ||
(0, compile_1.default)(argvs.dir, { | ||
out: argvs.out, | ||
combine: argvs.combine, | ||
rmGlobal: argvs['rm-global'], | ||
}); | ||
console.log('Watching for file changes....'); | ||
}); | ||
return [3 /*break*/, 3]; | ||
case 1: return [4 /*yield*/, (0, compile_1.default)(argvs.dir, { | ||
(async () => { | ||
try { | ||
const inputDir = path_1.default.resolve(argvs.dir); | ||
if (argvs.watch) { | ||
chokidar_1.default.watch(inputDir).on('all', chokidarWatch).on('ready', () => { | ||
(0, compile_1.default)(argvs.dir, { | ||
out: argvs.out, | ||
combine: argvs.combine, | ||
rmGlobal: argvs['rm-global'], | ||
})]; | ||
case 2: | ||
_a.sent(); | ||
_a.label = 3; | ||
case 3: return [3 /*break*/, 5]; | ||
case 4: | ||
error_1 = _a.sent(); | ||
if (error_1 instanceof TypeError) { | ||
console.log("compile-less: \u001B[31m".concat(error_1.message, "\u001B[0m")); | ||
} | ||
console.log(error_1); | ||
process.exit(1); | ||
return [3 /*break*/, 5]; | ||
case 5: return [2 /*return*/]; | ||
}); | ||
console.log('Watching for file changes....'); | ||
}); | ||
} | ||
}); | ||
}); })(); | ||
else { | ||
await (0, compile_1.default)(argvs.dir, { | ||
out: argvs.out, | ||
combine: argvs.combine, | ||
rmGlobal: argvs['rm-global'], | ||
}); | ||
} | ||
} | ||
catch (error) { | ||
if (error instanceof TypeError) { | ||
console.log(`compile-less: \x1b[31m${error.message}\x1b[0m`); | ||
} | ||
console.log(error); | ||
process.exit(1); | ||
} | ||
})(); | ||
function exampleHelp() { | ||
@@ -159,32 +114,21 @@ console.log('\n Example:'); | ||
} | ||
function chokidarWatch(eventName, changePath, stats) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var reg, lessSource, error_2; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 3, , 4]); | ||
reg = argvs.excludeCss ? /\.(less)$/ : /\.(less|css)$/; | ||
if (!(eventName === 'change' && reg.test(changePath))) return [3 /*break*/, 2]; | ||
if (argvs.combine) { | ||
return [2 /*return*/, (0, compile_1.default)(argvs.dir, { | ||
out: argvs.out, | ||
combine: argvs.combine, | ||
rmGlobal: argvs['rm-global'], | ||
})]; | ||
} | ||
return [4 /*yield*/, (0, executeLess_1.executeLess)(changePath, { rmGlobal: argvs['rm-global'] })]; | ||
case 1: | ||
lessSource = _a.sent(); | ||
(0, compile_1.outputFile)(lessSource, path_1.default.join(process.cwd(), argvs.dir), path_1.default.join(process.cwd(), argvs.out)); | ||
_a.label = 2; | ||
case 2: return [3 /*break*/, 4]; | ||
case 3: | ||
error_2 = _a.sent(); | ||
console.log('\x1b[31m COMPILE-LESS:CLI:ERR:\x1b[0m', error_2); | ||
return [3 /*break*/, 4]; | ||
case 4: return [2 /*return*/]; | ||
async function chokidarWatch(eventName, changePath, stats) { | ||
try { | ||
const reg = argvs.excludeCss ? /\.(less)$/ : /\.(less|css)$/; | ||
if (eventName === 'change' && reg.test(changePath)) { | ||
if (argvs.combine) { | ||
return (0, compile_1.default)(argvs.dir, { | ||
out: argvs.out, | ||
combine: argvs.combine, | ||
rmGlobal: argvs['rm-global'], | ||
}); | ||
} | ||
}); | ||
}); | ||
const lessSource = await (0, executeLess_1.executeLess)(changePath, { rmGlobal: argvs['rm-global'] }); | ||
(0, compile_1.outputFile)(lessSource, path_1.default.join(process.cwd(), argvs.dir), path_1.default.join(process.cwd(), argvs.out)); | ||
} | ||
} | ||
catch (error) { | ||
console.log('\x1b[31m COMPILE-LESS:CLI:ERR:\x1b[0m', error); | ||
} | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "compile-less-cli", | ||
"version": "1.8.13", | ||
"version": "1.8.14", | ||
"description": "All `.less` files are compiled into `.css` files.", | ||
"main": "lib/compile.js", | ||
"main": "./lib/compile.js", | ||
"types": "./lib/compile.d.ts", | ||
"bin": { | ||
@@ -11,4 +12,4 @@ "compile-less": "lib/index.js" | ||
"prepare": "npm run build", | ||
"watch": "tsbb watch --disable-babel --no-esm", | ||
"build": "tsbb build --disable-babel --no-esm", | ||
"watch": "tsbb watch", | ||
"build": "tsbb build", | ||
"test": "npm run build && tsbb test", | ||
@@ -42,18 +43,18 @@ "coverage": "npm run build && tsbb test --coverage", | ||
"devDependencies": { | ||
"tsbb": "^3.7.2" | ||
"tsbb": "^4.0.5" | ||
}, | ||
"dependencies": { | ||
"@types/fs-extra": "~9.0.13", | ||
"@types/fs-extra": "^11.0.1", | ||
"@types/less": "~3.0.3", | ||
"@types/minimist": "~1.2.2", | ||
"@types/node": "~17.0.6", | ||
"autoprefixer": "~10.4.1", | ||
"chokidar": "~3.5.2", | ||
"directory-tree": "~3.2.2", | ||
"fs-extra": "~10.0.1", | ||
"postcss": "~8.4.5", | ||
"less": "~4.1.2", | ||
"@types/node": "^18.15.11", | ||
"autoprefixer": "~10.4.14", | ||
"chokidar": "~3.5.3", | ||
"directory-tree": "^3.5.1", | ||
"fs-extra": "^11.1.1", | ||
"postcss": "~8.4.21", | ||
"less": "~4.1.3", | ||
"less-plugin-autoprefix": "~2.0.0", | ||
"minimist": "~1.2.5" | ||
"minimist": "~1.2.8" | ||
} | ||
} |
compile-less | ||
=== | ||
![Build compile-less](https://github.com/jaywcjlove/compile-less/workflows/Build%20compile-less/badge.svg) | ||
[![CI](https://github.com/jaywcjlove/compile-less/actions/workflows/ci.yml/badge.svg)](https://github.com/jaywcjlove/compile-less/actions/workflows/ci.yml) | ||
[![npm download](https://img.shields.io/npm/dm/compile-less-cli.svg?style=flat)](https://www.npmjs.com/package/compile-less-cli) | ||
@@ -6,0 +6,0 @@ [![releases version](https://img.shields.io/github/release/jaywcjlove/compile-less)](https://github.com/jaywcjlove/compile-less/releases) |
@@ -6,3 +6,3 @@ import path from 'path'; | ||
export interface ICompileOtion { | ||
export interface ICompileOption { | ||
out: string; | ||
@@ -24,3 +24,3 @@ combine?: string; | ||
export default async function compile(dir: string, option: ICompileOtion) { | ||
export default async function compile(dir: string, option: ICompileOption) { | ||
const { excludeCss, rmGlobal, combine, out, ...otherOpts } = option || {}; | ||
@@ -27,0 +27,0 @@ const inputDir = path.join(process.cwd(), dir); |
AI detected security risk
Supply chain riskAI has determined that this package may contain potential security issues or vulnerabilities.
Found 1 instance in 1 package
19
35455
572
2
+ Added@types/fs-extra@11.0.4(transitive)
+ Added@types/jsonfile@6.1.4(transitive)
+ Added@types/node@18.19.31(transitive)
+ Addedcaniuse-lite@1.0.30001614(transitive)
+ Addeddirectory-tree@3.5.1(transitive)
+ Addedelectron-to-chromium@1.4.750(transitive)
+ Addedfs-extra@11.2.0(transitive)
+ Addedundici-types@5.26.5(transitive)
- Removed@types/fs-extra@9.0.13(transitive)
- Removed@types/node@17.0.45(transitive)
- Removedcaniuse-lite@1.0.30001612(transitive)
- Removeddirectory-tree@3.2.2(transitive)
- Removedelectron-to-chromium@1.4.749(transitive)
- Removedfs-extra@10.0.1(transitive)
Updated@types/fs-extra@^11.0.1
Updated@types/node@^18.15.11
Updatedautoprefixer@~10.4.14
Updatedchokidar@~3.5.3
Updateddirectory-tree@^3.5.1
Updatedfs-extra@^11.1.1
Updatedless@~4.1.3
Updatedminimist@~1.2.8
Updatedpostcss@~8.4.21