Socket
Socket
Sign inDemoInstall

compile-less-cli

Package Overview
Dependencies
51
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.4.0 to 1.5.0

LICENSE

61

lib/cli.js

@@ -6,3 +6,6 @@ #!/usr/bin/env node

var commander_1 = tslib_1.__importDefault(require("commander"));
var compile_1 = tslib_1.__importDefault(require("./compile"));
var path_1 = tslib_1.__importDefault(require("path"));
var chokidar_1 = tslib_1.__importDefault(require("chokidar"));
var executeLess_1 = require("./executeLess");
var compile_1 = tslib_1.__importStar(require("./compile"));
var logs = console.log;

@@ -17,2 +20,4 @@ commander_1.default

.option('-c, --combine <file-name>', 'Combine CSS files.')
.option('-w, --watch', 'Watch and compile CSS files.')
.option('--exclude-css', 'Exclude CSS file compilation.')
.option('-r, --rm-global', 'Remove ":global" and ":global(className)".');

@@ -23,2 +28,4 @@ commander_1.default.on('--help', function () {

logs(' $ compile-less -d src -o css');
logs(' $ compile-less -d src -o css --watch');
logs(' $ compile-less -d src -o css --watch --exclude-css');
logs(' $ compile-less -d src -o out --combine out/dist.css');

@@ -33,7 +40,51 @@ logs();

else {
compile_1.default(commander_1.default.dir, {
out: commander_1.default.out,
combine: commander_1.default.combine,
rmGlobal: commander_1.default.rmGlobal,
var inputDir = path_1.default.join(process.cwd(), commander_1.default.dir);
if (commander_1.default.watch) {
chokidar_1.default.watch(inputDir).on('all', chokidarWatch).on('ready', function () {
compile_1.default(commander_1.default.dir, {
out: commander_1.default.out,
combine: commander_1.default.combine,
rmGlobal: commander_1.default.rmGlobal,
});
console.log('Watching for file changes....');
});
}
else {
compile_1.default(commander_1.default.dir, {
out: commander_1.default.out,
combine: commander_1.default.combine,
rmGlobal: commander_1.default.rmGlobal,
});
}
}
function chokidarWatch(eventName, changePath, stats) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var reg, lessSource, error_1;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 3, , 4]);
reg = commander_1.default.excludeCss ? /\.(less)$/ : /\.(less|css)$/;
if (!(eventName === 'change' && reg.test(changePath))) return [3, 2];
if (commander_1.default.combine) {
return [2, compile_1.default(commander_1.default.dir, {
out: commander_1.default.out,
combine: commander_1.default.combine,
rmGlobal: commander_1.default.rmGlobal,
})];
}
return [4, executeLess_1.executeLess(changePath, commander_1.default.rmGlobal)];
case 1:
lessSource = _a.sent();
compile_1.outputFile(lessSource, path_1.default.join(process.cwd(), commander_1.default.dir), path_1.default.join(process.cwd(), commander_1.default.out));
_a.label = 2;
case 2: return [3, 4];
case 3:
error_1 = _a.sent();
console.log('CLI:ERR:', error_1);
return [3, 4];
case 4: return [2];
}
});
});
}

@@ -0,1 +1,2 @@

import { IOutputFile } from './executeLess';
export interface ICompileOtion {

@@ -5,3 +6,5 @@ out: string;

rmGlobal?: boolean;
excludeCss?: boolean;
}
export default function compile(dir: string, option: ICompileOtion): Promise<void>;
export declare function outputFile(data: IOutputFile, inputDir: string, outputDir: string): Promise<void>;

46

lib/compile.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.outputFile = void 0;
var tslib_1 = require("tslib");

@@ -19,3 +20,3 @@ var path_1 = tslib_1.__importDefault(require("path"));

_a.trys.push([1, 8, , 9]);
return [4, getLessFiles_1.getLessFiles(inputDir)];
return [4, getLessFiles_1.getLessFiles(inputDir, option.excludeCss ? /\.(less)$/ : undefined)];
case 2:

@@ -41,18 +42,4 @@ files = _a.sent();

return [4, 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_1).replace(/.less$/, '.css');
logPathOut = item.path.replace(process.cwd(), '');
console.log('log:', logPathIn, '->', logPathOut);
return [4, 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, item];
}
return [2, outputFile(item, inputDir, outputDir_1)];
});

@@ -74,1 +61,28 @@ }); }))];

exports.default = compile;
function outputFile(data, inputDir, outputDir) {
return tslib_1.__awaiter(this, void 0, void 0, function () {
var logPathIn, logPathOut, error_2;
return tslib_1.__generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2, , 3]);
logPathIn = data.path.replace(process.cwd(), '');
data.path = data.path.replace(inputDir, outputDir).replace(/.less$/, '.css');
logPathOut = data.path.replace(process.cwd(), '');
console.log('log:', logPathIn, '->', logPathOut);
return [4, fs_extra_1.default.outputFile(data.path, data.css)];
case 1:
_a.sent();
if (data.imports && data.imports.length > 0) {
console.log('imports:', data.imports);
}
return [3, 3];
case 2:
error_2 = _a.sent();
throw error_2;
case 3: return [2];
}
});
});
}
exports.outputFile = outputFile;

@@ -8,2 +8,2 @@ export interface IOutputFile {

export declare function execute(command: string): Promise<unknown>;
export declare function executeLess(lessPath: string, rmGlobal?: boolean): Promise<unknown>;
export declare function executeLess(lessPath: string, rmGlobal?: boolean): Promise<IOutputFile>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.executeLess = exports.execute = void 0;
var tslib_1 = require("tslib");

@@ -4,0 +5,0 @@ var fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));

@@ -1,1 +0,1 @@

export declare function getLessFiles(folder: string): Promise<string[]>;
export declare function getLessFiles(folder: string, reg?: RegExp): Promise<string[]>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getLessFiles = void 0;
var tslib_1 = require("tslib");
var directory_tree_1 = tslib_1.__importDefault(require("directory-tree"));
function getLessFiles(folder) {
function getLessFiles(folder, reg) {
if (reg === void 0) { reg = /\.(less|css)$/; }
return new Promise(function (resolve, reject) {
var lessPaths = [];
directory_tree_1.default(folder, {
extensions: /\.(less)$/
extensions: reg
}, function (item) {

@@ -11,0 +13,0 @@ lessPaths.push(item.path);

{
"name": "compile-less-cli",
"version": "1.4.0",
"version": "1.5.0",
"description": "compile less",

@@ -10,6 +10,8 @@ "main": "lib/compile.js",

"scripts": {
"prepack": "npm run start",
"dev": "npm run start -- --watch",
"start": "tsc --removeComments",
"test": "node ./lib/cli.js -d test/src -o test/out --combine test/out/dist.css"
"prepack": "npm run build",
"start": "npm run build -- --watch",
"build": "tsc --removeComments",
"test": "node ./lib/cli.js -d test/src -o test/out",
"test:watch": "node ./lib/cli.js -d test/src -o test/out --combine test/out/dist.css --watch",
"test:watch2": "node ./lib/cli.js -d test/src -o test/out --watch --exclude-css"
},

@@ -33,16 +35,21 @@ "repository": {

],
"files": [
"lib",
"src"
],
"devDependencies": {
"@types/fs-extra": "5.0.5",
"@types/less": "^3.0.1",
"@types/node": "11.13.0",
"typescript": "^3.8.3"
"@types/fs-extra": "9.0.1",
"@types/less": "3.0.1",
"@types/node": "14.6.0",
"typescript": "4.0.2"
},
"dependencies": {
"commander": "^4.1.1",
"chokidar": "3.4.2",
"commander": "^6.0.0",
"directory-tree": "^2.2.4",
"fs-extra": "^8.1.0",
"less": "^3.11.1",
"fs-extra": "^9.0.1",
"less": "^3.12.2",
"less-plugin-autoprefix": "2.0.0",
"tslib": "^1.11.1"
"tslib": "^2.0.1"
}
}

@@ -37,9 +37,12 @@ compile-less

-c, --combine <file-name> Combine CSS files.
-w, --watch Watch and compile CSS files.
--exclude-css Exclude CSS file compilation.
-r, --rm-global Remove ":global" and ":global(className)".
-h, --help output usage information
-h, --help display help for command
Examples:
Examples:
$ compile-less -d src -o out
$ compile-less -d src -o out --rm-global
$ compile-less -d src -o css
$ compile-less -d src -o css --watch
$ compile-less -d src -o css --watch --exclude-css
$ compile-less -d src -o out --combine out/dist.css

@@ -53,4 +56,4 @@ ```

```bash
npm run dev
npm run compile
npm run start
npm run build
```

@@ -57,0 +60,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc