Updates
This commit is contained in:
parent
e6e2fa65cb
commit
de8191edca
8
dist/index.d.ts
vendored
Normal file
8
dist/index.d.ts
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
export type LessCssWatcherConfigObject = {
|
||||||
|
src?: string | string[];
|
||||||
|
dst?: string | string[];
|
||||||
|
srcDst?: {
|
||||||
|
src?: string;
|
||||||
|
dst?: string;
|
||||||
|
}[];
|
||||||
|
};
|
32
dist/index.js
vendored
32
dist/index.js
vendored
@ -1,4 +1,3 @@
|
|||||||
#! /usr/bin/env node
|
|
||||||
"use strict";
|
"use strict";
|
||||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||||
@ -74,6 +73,9 @@ const grabSrcDisStrings = () => {
|
|||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
return {
|
return {
|
||||||
sourceFile: srcArray.join(","),
|
sourceFile: srcArray.join(","),
|
||||||
destinationFile: dstArray.join(","),
|
destinationFile: dstArray.join(","),
|
||||||
@ -83,11 +85,20 @@ const { sourceFile, destinationFile } = grabSrcDisStrings();
|
|||||||
if (sourceFile && destinationFile) {
|
if (sourceFile && destinationFile) {
|
||||||
process.argv.push("--src", sourceFile, "--dst", destinationFile);
|
process.argv.push("--src", sourceFile, "--dst", destinationFile);
|
||||||
}
|
}
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
console.log("- \x1b[35mStart:\x1b[0m Running Less compiler ...");
|
console.log("- \x1b[35mStart:\x1b[0m Running Less compiler ...");
|
||||||
if (!sourceFile || !destinationFile) {
|
if (!sourceFile || !destinationFile) {
|
||||||
console.log("- \x1b[31mERROR:\x1b[0m => Missing source or destination file");
|
console.log("- \x1b[31mERROR:\x1b[0m => Missing source or destination file");
|
||||||
process.exit();
|
process.exit();
|
||||||
}
|
}
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
/**
|
||||||
|
* Loop through source files and destination files and run the compile function
|
||||||
|
*/
|
||||||
function traverseFiles(src, dst) {
|
function traverseFiles(src, dst) {
|
||||||
var _a;
|
var _a;
|
||||||
const sourceFiles = src.split(",");
|
const sourceFiles = src.split(",");
|
||||||
@ -196,6 +207,16 @@ function traverseFiles(src, dst) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
traverseFiles(sourceFile, destinationFile);
|
traverseFiles(sourceFile, destinationFile);
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
/**
|
||||||
|
* Compile less file to css function
|
||||||
|
* @param fileName - less file path or folder path
|
||||||
|
* @param dst - destination file path or folder path
|
||||||
|
* @param evtType - event type (change, rename, etc.) or null
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
function compile(fileName, dst, evtType) {
|
function compile(fileName, dst, evtType) {
|
||||||
if ((fileName === null || fileName === void 0 ? void 0 : fileName.match(/\(/)) ||
|
if ((fileName === null || fileName === void 0 ? void 0 : fileName.match(/\(/)) ||
|
||||||
(fileName.match(/\.[\/]$/) && !(fileName === null || fileName === void 0 ? void 0 : fileName.match(/\.less$/i)))) {
|
(fileName.match(/\.[\/]$/) && !(fileName === null || fileName === void 0 ? void 0 : fileName.match(/\.less$/i)))) {
|
||||||
@ -220,8 +241,9 @@ function compile(fileName, dst, evtType) {
|
|||||||
finalSrcPath = fileName;
|
finalSrcPath = fileName;
|
||||||
finalDstPath = targetDstFilePath;
|
finalDstPath = targetDstFilePath;
|
||||||
}
|
}
|
||||||
const executionCmd = `lessc ${finalSrcPath} ${finalDstPath}`;
|
const executionCmd = `npx lessc ${finalSrcPath} ${finalDstPath}`;
|
||||||
(0, child_process_1.exec)(executionCmd, (error, stdout, stderr) => {
|
(0, child_process_1.exec)(executionCmd, (error, stdout, stderr) => {
|
||||||
|
/** @type {Error} */
|
||||||
if (error) {
|
if (error) {
|
||||||
console.log("- \x1b[33mWarn:\x1b[0m Compilation didn't run successfully. ERROR =>", error.message);
|
console.log("- \x1b[33mWarn:\x1b[0m Compilation didn't run successfully. ERROR =>", error.message);
|
||||||
if (!(evtType === null || evtType === void 0 ? void 0 : evtType.match(/change/i)) &&
|
if (!(evtType === null || evtType === void 0 ? void 0 : evtType.match(/change/i)) &&
|
||||||
@ -234,6 +256,12 @@ function compile(fileName, dst, evtType) {
|
|||||||
console.log("- \x1b[32mCompiled:\x1b[0m Less Compilation Successful!");
|
console.log("- \x1b[32mCompiled:\x1b[0m Less Compilation Successful!");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
/**
|
||||||
|
* watch for changes to the config file
|
||||||
|
*/
|
||||||
if (fs_1.default.existsSync("./lesscw.config.json")) {
|
if (fs_1.default.existsSync("./lesscw.config.json")) {
|
||||||
fs_1.default.watchFile("./lesscw.config.json", { interval: 500 }, (evtType, fileName) => {
|
fs_1.default.watchFile("./lesscw.config.json", { interval: 500 }, (evtType, fileName) => {
|
||||||
console.log("- \x1b[34mInfo:\x1b[0m Restarting process...");
|
console.log("- \x1b[34mInfo:\x1b[0m Restarting process...");
|
||||||
|
1
dist/tsconfig.tsbuildinfo
vendored
Normal file
1
dist/tsconfig.tsbuildinfo
vendored
Normal file
File diff suppressed because one or more lines are too long
57
package.json
57
package.json
@ -1,30 +1,31 @@
|
|||||||
{
|
{
|
||||||
"name": "lessc-watcher",
|
"name": "@moduletrace/less-watcher",
|
||||||
"version": "1.2.2",
|
"version": "1.0.1",
|
||||||
"description": "A minimal package to watch less files and compile them to css",
|
"description": "A minimal package to watch less files and compile them to css",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
"lessc-watcher": "./dist/index.js"
|
"lessc-watcher": "dist/index.js",
|
||||||
},
|
"less-watcher": "dist/index.js"
|
||||||
"repository": {
|
},
|
||||||
"type": "git",
|
"repository": {
|
||||||
"url": "git+https://github.com/BenjaminToby/less-watcher.git"
|
"type": "git",
|
||||||
},
|
"url": "https://git.tben.me/Moduletrace/less-watcher.git"
|
||||||
"keywords": [
|
},
|
||||||
"less",
|
"keywords": [
|
||||||
"watcher",
|
"less",
|
||||||
"css"
|
"watcher",
|
||||||
],
|
"css"
|
||||||
"author": "Benjamin Toby",
|
],
|
||||||
"license": "MIT",
|
"author": "Benjamin Toby",
|
||||||
"devDependencies": {
|
"license": "MIT",
|
||||||
"@types/node": "^20.4.5",
|
"devDependencies": {
|
||||||
"@types/bun": "latest"
|
"@types/node": "^20.4.5",
|
||||||
},
|
"@types/bun": "latest"
|
||||||
"dependencies": {
|
},
|
||||||
"less": "^4.2.0"
|
"dependencies": {
|
||||||
},
|
"less": "^4.2.0"
|
||||||
"peerDependencies": {
|
},
|
||||||
"typescript": "^5.0.0"
|
"peerDependencies": {
|
||||||
}
|
"typescript": "^5.0.0"
|
||||||
|
}
|
||||||
}
|
}
|
0
publish.sh
Normal file → Executable file
0
publish.sh
Normal file → Executable file
Loading…
Reference in New Issue
Block a user