This commit is contained in:
Tben 2023-08-01 04:07:10 +01:00
parent e3498601a1
commit 1ac9bb4fbe
3 changed files with 28 additions and 7 deletions

15
dist/index.js vendored
View File

@ -103,6 +103,14 @@ function traverseFiles(src, dst) {
} }
} }
compile(srcFolder, dstFile, null); compile(srcFolder, dstFile, null);
try {
fs_1.default.readdirSync(srcFolder).forEach((file) => {
if (file === null || file === void 0 ? void 0 : file.match(/^\[.*\.less$/)) {
compile(srcFolder + "/" + file, dstFile, null);
}
});
}
catch (error) { }
if (srcFolder === null || srcFolder === void 0 ? void 0 : srcFolder.match(/\.less$/)) { if (srcFolder === null || srcFolder === void 0 ? void 0 : srcFolder.match(/\.less$/)) {
fs_1.default.watchFile(srcFolder, { interval: 500 }, (current, previous) => { fs_1.default.watchFile(srcFolder, { interval: 500 }, (current, previous) => {
const dstFilePathRoot = (dstFile === null || dstFile === void 0 ? void 0 : dstFile.match(/\.css$/)) ? dstFile : dstFile + "/" + "_main.css"; const dstFilePathRoot = (dstFile === null || dstFile === void 0 ? void 0 : dstFile.match(/\.css$/)) ? dstFile : dstFile + "/" + "_main.css";
@ -132,7 +140,10 @@ function traverseFiles(src, dst) {
try { try {
const currentProcessArgsSrc = process.argv[process.argv.indexOf("--src") + 1]; const currentProcessArgsSrc = process.argv[process.argv.indexOf("--src") + 1];
const activeSourceFiles = currentProcessArgsSrc.split(","); const activeSourceFiles = currentProcessArgsSrc.split(",");
if (activeSourceFiles.includes(srcFilePathRoot)) { if (fileName === null || fileName === void 0 ? void 0 : fileName.match(/^\[/)) {
compile(srcFolder + "/" + fileName, dstFile, evtType);
}
else if ((fileName === null || fileName === void 0 ? void 0 : fileName.match(/^\(/)) || activeSourceFiles.includes(srcFilePathRoot)) {
return; return;
} }
else { else {
@ -167,7 +178,7 @@ function compile(fileName, dst, evtType) {
const targetPath = targetPathFull.replace(/\[|\]/g, "").replace(/\.less/, ""); const targetPath = targetPathFull.replace(/\[|\]/g, "").replace(/\.less/, "");
const destinationFileParentFolder = dst.replace(/\/[^\/]+\.css$/, ""); const destinationFileParentFolder = dst.replace(/\/[^\/]+\.css$/, "");
const targetDstFilePath = `${destinationFileParentFolder}/${targetPath}.css`; const targetDstFilePath = `${destinationFileParentFolder}/${targetPath}.css`;
finalSrcPath = `${fileName}/${targetPathFull}`; finalSrcPath = fileName;
finalDstPath = targetDstFilePath; finalDstPath = targetDstFilePath;
} }
const executionCmd = `lessc ${finalSrcPath} ${finalDstPath}`; const executionCmd = `lessc ${finalSrcPath} ${finalDstPath}`;

View File

@ -1,6 +1,6 @@
{ {
"name": "lessc-watcher", "name": "lessc-watcher",
"version": "1.1.7", "version": "1.1.8",
"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": {

View File

@ -1,7 +1,7 @@
#! /usr/bin/env node #! /usr/bin/env node
import fs, { watch } from "fs"; import fs from "fs";
import { exec, spawn } from "child_process"; import { exec } from "child_process";
import { LessCssWatcherConfigObject } from "./index.d"; import { LessCssWatcherConfigObject } from "./index.d";
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@ -125,6 +125,14 @@ function traverseFiles(src: string, dst: string) {
compile(srcFolder, dstFile, null); compile(srcFolder, dstFile, null);
try {
fs.readdirSync(srcFolder).forEach((file) => {
if (file?.match(/^\[.*\.less$/)) {
compile(srcFolder + "/" + file, dstFile, null);
}
});
} catch (error) {}
if (srcFolder?.match(/\.less$/)) { if (srcFolder?.match(/\.less$/)) {
fs.watchFile(srcFolder, { interval: 500 }, (current, previous) => { fs.watchFile(srcFolder, { interval: 500 }, (current, previous) => {
const dstFilePathRoot = dstFile?.match(/\.css$/) ? dstFile : dstFile + "/" + "_main.css"; const dstFilePathRoot = dstFile?.match(/\.css$/) ? dstFile : dstFile + "/" + "_main.css";
@ -156,7 +164,9 @@ function traverseFiles(src: string, dst: string) {
const currentProcessArgsSrc = process.argv[process.argv.indexOf("--src") + 1]; const currentProcessArgsSrc = process.argv[process.argv.indexOf("--src") + 1];
const activeSourceFiles = currentProcessArgsSrc.split(","); const activeSourceFiles = currentProcessArgsSrc.split(",");
if (activeSourceFiles.includes(srcFilePathRoot)) { if (fileName?.match(/^\[/)) {
compile(srcFolder + "/" + fileName, dstFile, evtType);
} else if (fileName?.match(/^\(/) || activeSourceFiles.includes(srcFilePathRoot)) {
return; return;
} else { } else {
compile(srcFilePathRoot, dstFile, evtType); compile(srcFilePathRoot, dstFile, evtType);
@ -207,7 +217,7 @@ function compile(fileName: string, dst: string, evtType: string | null) {
const targetDstFilePath = `${destinationFileParentFolder}/${targetPath}.css`; const targetDstFilePath = `${destinationFileParentFolder}/${targetPath}.css`;
finalSrcPath = `${fileName}/${targetPathFull}`; finalSrcPath = fileName;
finalDstPath = targetDstFilePath; finalDstPath = targetDstFilePath;
} }