compile-less-cli
Advanced tools
Comparing version 1.8.10 to 1.8.11
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
@@ -59,8 +60,13 @@ __assign = Object.assign || function(t) { | ||
}; | ||
import path from 'path'; | ||
import fs from 'fs-extra'; | ||
import readPkgUp from 'read-pkg-up'; | ||
import { getLessFiles } from './getLessFiles'; | ||
import { executeLess } from './executeLess'; | ||
export default function compile(dir, option) { | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.log = exports.outputFile = void 0; | ||
var path_1 = __importDefault(require("path")); | ||
var fs_extra_1 = __importDefault(require("fs-extra")); | ||
var read_pkg_up_1 = __importDefault(require("read-pkg-up")); | ||
var getLessFiles_1 = require("./getLessFiles"); | ||
var executeLess_1 = require("./executeLess"); | ||
function compile(dir, option) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -73,11 +79,11 @@ var _a, excludeCss, rmGlobal, combine, out, otherOpts, inputDir, pkg, projectName, files, lessSource, outputCssFile, cssStr, outputDir_1, error_1; | ||
_a = option || {}, excludeCss = _a.excludeCss, rmGlobal = _a.rmGlobal, combine = _a.combine, out = _a.out, otherOpts = __rest(_a, ["excludeCss", "rmGlobal", "combine", "out"]); | ||
inputDir = path.join(process.cwd(), dir); | ||
inputDir = path_1.default.join(process.cwd(), dir); | ||
_b.label = 1; | ||
case 1: | ||
_b.trys.push([1, 12, , 13]); | ||
return [4 /*yield*/, readPkgUp()]; | ||
return [4 /*yield*/, (0, read_pkg_up_1.default)()]; | ||
case 2: | ||
pkg = _b.sent(); | ||
projectName = pkg ? pkg === null || pkg === void 0 ? void 0 : pkg.packageJson.name : ''; | ||
return [4 /*yield*/, getLessFiles(inputDir, excludeCss ? /\.(less)$/ : undefined)]; | ||
return [4 /*yield*/, (0, getLessFiles_1.getLessFiles)(inputDir, excludeCss ? /\.(less)$/ : undefined)]; | ||
case 3: | ||
@@ -87,3 +93,3 @@ files = _b.sent(); | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, executeLess(lessPath, __assign({ rmGlobal: rmGlobal }, otherOpts))]; | ||
return [2 /*return*/, (0, executeLess_1.executeLess)(lessPath, __assign({ rmGlobal: rmGlobal }, otherOpts))]; | ||
}); | ||
@@ -94,9 +100,9 @@ }); }))]; | ||
if (!combine) return [3 /*break*/, 9]; | ||
outputCssFile = path.join(process.cwd(), combine); | ||
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.outputFile(outputCssFile, cssStr.join(''))]; | ||
return [4 /*yield*/, fs_extra_1.default.outputFile(outputCssFile, cssStr.join(''))]; | ||
case 5: | ||
_b.sent(); | ||
return [4 /*yield*/, log(path.relative(process.cwd(), outputCssFile))]; | ||
return [4 /*yield*/, log(path_1.default.relative(process.cwd(), outputCssFile))]; | ||
case 6: | ||
@@ -110,3 +116,3 @@ _b.sent(); | ||
case 9: | ||
outputDir_1 = path.join(process.cwd(), out); | ||
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 () { | ||
@@ -130,3 +136,4 @@ return __generator(this, function (_a) { | ||
} | ||
export function outputFile(data, inputDir, outputDir) { | ||
exports.default = compile; | ||
function outputFile(data, inputDir, outputDir) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -138,9 +145,9 @@ var logPathIn, logPathOut, error_2; | ||
_a.trys.push([0, 3, , 4]); | ||
logPathIn = path.relative(process.cwd(), data.path); | ||
logPathIn = path_1.default.relative(process.cwd(), data.path); | ||
data.path = data.path.replace(inputDir, outputDir).replace(/.less$/, '.css'); | ||
logPathOut = path.relative(process.cwd(), data.path); | ||
logPathOut = path_1.default.relative(process.cwd(), data.path); | ||
return [4 /*yield*/, log(logPathOut, logPathIn)]; | ||
case 1: | ||
_a.sent(); | ||
return [4 /*yield*/, fs.outputFile(data.path, data.css)]; | ||
return [4 /*yield*/, fs_extra_1.default.outputFile(data.path, data.css)]; | ||
case 2: | ||
@@ -160,3 +167,4 @@ _a.sent(); | ||
} | ||
export function log(output, input) { | ||
exports.outputFile = outputFile; | ||
function log(output, input) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -166,3 +174,3 @@ var pkg, projectName; | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, readPkgUp()]; | ||
case 0: return [4 /*yield*/, (0, read_pkg_up_1.default)()]; | ||
case 1: | ||
@@ -182,1 +190,2 @@ pkg = _a.sent(); | ||
} | ||
exports.log = log; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
@@ -23,8 +24,13 @@ __assign = Object.assign || function(t) { | ||
}; | ||
import fs from 'fs-extra'; | ||
import less from 'less'; | ||
import { spawn } from 'child_process'; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
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"); | ||
// @ts-ignore | ||
import LessPluginAutoPrefix from 'less-plugin-autoprefix'; | ||
var autoprefixPlugin = new LessPluginAutoPrefix({ | ||
var less_plugin_autoprefix_1 = __importDefault(require("less-plugin-autoprefix")); | ||
var autoprefixPlugin = new less_plugin_autoprefix_1.default({ | ||
browsers: [ | ||
@@ -37,5 +43,5 @@ ">0.2%", | ||
}); | ||
export function execute(command) { | ||
function execute(command) { | ||
return new Promise(function (resolve, reject) { | ||
var subProcess = spawn('bash'); | ||
var subProcess = (0, child_process_1.spawn)('bash'); | ||
function onData(data) { | ||
@@ -56,4 +62,5 @@ process.stdout.write(data); | ||
} | ||
export function executeLess(lessPath, options) { | ||
var lessStr = fs.readFileSync(lessPath); | ||
exports.execute = execute; | ||
function executeLess(lessPath, options) { | ||
var lessStr = fs_extra_1.default.readFileSync(lessPath); | ||
var _a = options || {}, rmGlobal = _a.rmGlobal, other = __rest(_a, ["rmGlobal"]); | ||
@@ -66,3 +73,3 @@ return new Promise(function (resolve, reject) { | ||
} | ||
less.render(lessStrTo, options).then(function (output) { | ||
less_1.default.render(lessStrTo, options).then(function (output) { | ||
if (rmGlobal) { | ||
@@ -78,1 +85,2 @@ output.css = output.css.replace(/:global\s+\{([\s\S]*?)(\s.+)?\}/g, '') | ||
} | ||
exports.executeLess = executeLess; |
@@ -1,7 +0,13 @@ | ||
import dirTree from 'directory-tree'; | ||
export function getLessFiles(folder, reg) { | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
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 = []; | ||
dirTree(folder, { | ||
(0, directory_tree_1.default)(folder, { | ||
extensions: reg | ||
@@ -14,1 +20,2 @@ }, function (item) { | ||
} | ||
exports.getLessFiles = getLessFiles; |
#!/usr/bin/env node | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -38,7 +58,11 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
import minimist from 'minimist'; | ||
import path from 'path'; | ||
import chokidar from 'chokidar'; | ||
import { executeLess } from './executeLess'; | ||
import compile, { outputFile } from './compile'; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
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")); | ||
function outputHelp() { | ||
@@ -58,3 +82,3 @@ console.log('\n Usage: compile-less [options] [--help|h] [--version|v]'); | ||
} | ||
var argvs = minimist(process.argv.slice(2)); | ||
var argvs = (0, minimist_1.default)(process.argv.slice(2)); | ||
if (argvs.h || argvs.help) { | ||
@@ -85,6 +109,6 @@ outputHelp(); | ||
_a.trys.push([0, 4, , 5]); | ||
inputDir = path.resolve(argvs.dir); | ||
inputDir = path_1.default.resolve(argvs.dir); | ||
if (!argvs.watch) return [3 /*break*/, 1]; | ||
chokidar.watch(inputDir).on('all', chokidarWatch).on('ready', function () { | ||
compile(argvs.dir, { | ||
chokidar_1.default.watch(inputDir).on('all', chokidarWatch).on('ready', function () { | ||
(0, compile_1.default)(argvs.dir, { | ||
out: argvs.out, | ||
@@ -97,3 +121,3 @@ combine: argvs.combine, | ||
return [3 /*break*/, 3]; | ||
case 1: return [4 /*yield*/, compile(argvs.dir, { | ||
case 1: return [4 /*yield*/, (0, compile_1.default)(argvs.dir, { | ||
out: argvs.out, | ||
@@ -138,3 +162,3 @@ combine: argvs.combine, | ||
if (argvs.combine) { | ||
return [2 /*return*/, compile(argvs.dir, { | ||
return [2 /*return*/, (0, compile_1.default)(argvs.dir, { | ||
out: argvs.out, | ||
@@ -145,6 +169,6 @@ combine: argvs.combine, | ||
} | ||
return [4 /*yield*/, executeLess(changePath, { rmGlobal: argvs['rm-global'] })]; | ||
return [4 /*yield*/, (0, executeLess_1.executeLess)(changePath, { rmGlobal: argvs['rm-global'] })]; | ||
case 1: | ||
lessSource = _a.sent(); | ||
outputFile(lessSource, path.join(process.cwd(), argvs.dir), path.join(process.cwd(), argvs.out)); | ||
(0, compile_1.outputFile)(lessSource, path_1.default.join(process.cwd(), argvs.dir), path_1.default.join(process.cwd(), argvs.out)); | ||
_a.label = 2; | ||
@@ -151,0 +175,0 @@ case 2: return [3 /*break*/, 4]; |
{ | ||
"name": "compile-less-cli", | ||
"version": "1.8.10", | ||
"version": "1.8.11", | ||
"description": "All `.less` files are compiled into `.css` files.", | ||
@@ -5,0 +5,0 @@ "main": "lib/compile.js", |
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
36432
733