-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
199 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/usr/bin/env node | ||
|
||
let lessCompileRoots = require("less-compile-roots"); | ||
let {name, version, description, homepage} = require("../package.json"); | ||
|
||
let handlers = { | ||
help() { | ||
console.info(` | ||
${name} v${version} | ||
${description} | ||
${homepage} | ||
Usage: | ||
less-compile-roots --pattern=<glob> | ||
less-compile-roots --config=<path> | ||
less-compile-roots --help | ||
less-compile-roots --version | ||
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`); | ||
}, | ||
|
||
version() { | ||
console.info(version); | ||
}, | ||
|
||
compile(config) { | ||
console.info("Compiling, please wait..."); | ||
lessCompileRoots.compileRoots(config) | ||
.then(() => { | ||
console.info("Done!"); | ||
}) | ||
.catch(reason => { | ||
console.error(reason); | ||
}); | ||
} | ||
}; | ||
|
||
let [,, ...args] = process.argv; | ||
function getArg(name) { | ||
for (let arg of args) { | ||
if (arg === name) { | ||
return true; | ||
} | ||
if (arg.startsWith(name + "=")) { | ||
return arg.slice(name.length + 1); | ||
} | ||
} | ||
return undefined; | ||
} | ||
|
||
(() => { | ||
if (getArg("--help")) { | ||
handlers.help(); | ||
return; | ||
} | ||
|
||
if (getArg("--version")) { | ||
handlers.version(); | ||
return; | ||
} | ||
|
||
let pattern = getArg("--pattern"); | ||
let configPath = getArg("--config"); | ||
if (pattern) { | ||
if (configPath) { | ||
console.warn("The ‘--config’ option is ignored when the ‘--pattern’ option is present!"); | ||
} | ||
handlers.compile({pattern: pattern.split(",")}); | ||
} else if (configPath) { | ||
let path = require("path"); | ||
configPath = path.join(process.cwd(), configPath); | ||
handlers.compile(require(configPath)); | ||
} else { | ||
console.error("You must either specify the file pattern or provide the config file path"); | ||
console.info("Run ‘less-compile-roots --help’ to get usage info"); | ||
process.exitCode = 1; | ||
} | ||
})(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.