Skip to content

Commit

Permalink
Merge branch 'next'
Browse files Browse the repository at this point in the history
  • Loading branch information
Amphiluke committed Jun 30, 2019
2 parents b42b115 + 22bf630 commit 26834de
Show file tree
Hide file tree
Showing 25 changed files with 1,296 additions and 23 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
.eslint*
rollup.config.js
test
*.tgz
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ lessCompileRoots.compileRoots({
sourceMap: {sourceMapFileInline: true}
}
})
.then(() => {
console.log("All done");
.then(rootEntries => {
console.log("Compiled root files:");
console.log(rootEntries.join("\n"));
})
.catch(reason => {
console.error(reason);
Expand All @@ -43,7 +44,7 @@ The following methods are exported by the `less-compile-roots` module:

### `compileRoots(options)`

The method picks out the root Less files from all files matching the provided glob pattern (`options.pattern`), and compiles them with the Less pre-processor. It returns a Promise that resolves once all these root files have been successfully compiled.
The method picks out the root Less files from all files matching the provided glob pattern (`options.pattern`), and compiles them with the Less pre-processor. It returns a Promise that resolves once all these root files have been successfully compiled. The list of compiled entries is the value the promise resolves to.

The supported options are:

Expand Down Expand Up @@ -71,8 +72,8 @@ Available options:

* `--pattern=<glob>`: a glob pattern (or several comma-separated patterns) matching your source Less files;
* `--config=<path>`: path to a config module;
* `--help`: print CLI usage info;
* `--version`: print the installed package version.
* `-h`, `--help`: print CLI usage info;
* `-v`, `--version`: print the installed package version.

Note that you cannot use the options `--pattern` and `--config` together. Specifying the `--pattern` option makes the module compile Less files using all default parameters. If you need to customize the parameters, create a config file and specify the path to it through the `--config` option (or just use the module [programmatically](#api) rather than in command line). Here is an example of such config file:

Expand Down
8 changes: 4 additions & 4 deletions bin/less-compile-roots.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Usage:
Options:
--pattern=<glob> Glob pattern (or several comma-separated patterns)
--config=<path> Use config from the specified file
--help Display usage info
--version Print the installed package version`);
-h, --help Display usage info
-v, --version Print the installed package version`);
},

version() {
Expand Down Expand Up @@ -53,12 +53,12 @@ function getArg(name) {
}

(() => {
if (getArg("--help")) {
if (getArg("--help") || getArg("-h")) {
handlers.help();
return;
}

if (getArg("--version")) {
if (getArg("--version") || getArg("-v")) {
handlers.version();
return;
}
Expand Down
5 changes: 3 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ let flat = Array.prototype.flat ? list => list.flat() : list => [].concat(...lis

async function getImports(entries) {
let commentRE = /\/\*[\s\S]*?\*\/|\/\/\s*@import[^;]+;/g;
let importRE = /(?<=@import[^"']+["']).+?(?=['"]\s*;)/g;
let importRE = /(?<=@import\s[^"']*["']).+?(?=['"]\s*;)/g;
let promises = entries.map(entry =>
readFile(entry)
.then(data => {
Expand Down Expand Up @@ -87,7 +87,8 @@ async function getRoots({pattern, globOptions = {}}) {

async function compileRoots({pattern, lessOptions = {}, globOptions = {}}) {
let rootEntries = await getRoots({pattern, globOptions});
return compile(rootEntries, lessOptions);
await compile(rootEntries, lessOptions);
return rootEntries;
}

exports.compileRoots = compileRoots;
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "less-compile-roots",
"version": "0.2.2",
"version": "0.2.3",
"description": "Tool for extracting and compiling root Less files",
"main": "dist/index.js",
"module": "src/index.mjs",
Expand All @@ -26,11 +26,11 @@
},
"homepage": "https://github.com/Amphiluke/less-compile-roots#readme",
"dependencies": {
"fast-glob": "^3.0.2"
"fast-glob": "^3.0.3"
},
"devDependencies": {
"eslint": "^6.0.1",
"rollup": "^1.16.2"
"rollup": "^1.16.3"
},
"peerDependencies": {
"less": ">=2.0.0"
Expand Down
5 changes: 3 additions & 2 deletions src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let flat = Array.prototype.flat ? list => list.flat() : list => [].concat(...lis

async function getImports(entries) {
let commentRE = /\/\*[\s\S]*?\*\/|\/\/\s*@import[^;]+;/g;
let importRE = /(?<=@import[^"']+["']).+?(?=['"]\s*;)/g;
let importRE = /(?<=@import\s[^"']*["']).+?(?=['"]\s*;)/g;
let promises = entries.map(entry =>
readFile(entry)
.then(data => {
Expand Down Expand Up @@ -55,5 +55,6 @@ export async function getRoots({pattern, globOptions = {}}) {

export async function compileRoots({pattern, lessOptions = {}, globOptions = {}}) {
let rootEntries = await getRoots({pattern, globOptions});
return compile(rootEntries, lessOptions);
await compile(rootEntries, lessOptions);
return rootEntries;
}
1 change: 1 addition & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.css
1 change: 1 addition & 0 deletions test/less/child-01.less
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* child-01 */
1 change: 1 addition & 0 deletions test/less/child-02-1.less
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* child-02-1 */
1 change: 1 addition & 0 deletions test/less/child-02-2.less
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* child-02-2 */
1 change: 1 addition & 0 deletions test/less/child-02.less
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* child-02 */
1 change: 1 addition & 0 deletions test/less/child-03.less
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* child-03 */
1 change: 1 addition & 0 deletions test/less/child-04-1.less
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* child-04-1 */
1 change: 1 addition & 0 deletions test/less/child-04.less
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* child-04 */
1 change: 1 addition & 0 deletions test/less/child-05-1.less
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* child-05-1 */
1 change: 1 addition & 0 deletions test/less/child-05.less
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* child-05 */
19 changes: 19 additions & 0 deletions test/less/root-01.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
body {
background:#000;
}

// Test skipping commented out imports
// @import "root-02";
//@import "root-03";

/*
a {
color:#0a0;
}
@import "root-04";
some text
*/

/*@import "root-05";*/

@import "child-01";
7 changes: 7 additions & 0 deletions test/less/root-02.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Test extraction of imports placed in one line
@import "child-02"; @import "child-02-1";@import "child-02-2";

body {
background:#000;
}

6 changes: 6 additions & 0 deletions test/less/root-03.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
body {
background:#000;
}

// Test extraction of imports with extension specified
@import "./child-03.less";
20 changes: 20 additions & 0 deletions test/less/root-04.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Test some “quirky” cases

// With line breaks
@import
"child-04";

@import

"child-04-1"

;

@import (reference) "child-04";

// Variable name includes substring “import”
@import01: "root-01";

body {
background:#000;
}
8 changes: 8 additions & 0 deletions test/less/root-05.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Test imports with options

@import (reference) "child-05";
@import (less) "child-05-1.less";

body {
background:#000;
}
Loading

0 comments on commit 26834de

Please sign in to comment.