133 lines
4.3 KiB
JavaScript
133 lines
4.3 KiB
JavaScript
var __create = Object.create;
|
|
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __getProtoOf = Object.getPrototypeOf;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __export = (target, all) => {
|
|
for (var name in all)
|
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
};
|
|
var __copyProps = (to, from, except, desc) => {
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
for (let key of __getOwnPropNames(from))
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
}
|
|
return to;
|
|
};
|
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
mod
|
|
));
|
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
var cli_exports = {};
|
|
__export(cli_exports, {
|
|
cli: () => cli,
|
|
parseArgs: () => parseArgs
|
|
});
|
|
module.exports = __toCommonJS(cli_exports);
|
|
var import_fs = __toESM(require("fs"));
|
|
var import_path = __toESM(require("path"));
|
|
var import_yargs_parser = __toESM(require("yargs-parser"));
|
|
var commands = __toESM(require("./commands"));
|
|
var import_validate_params = require("./validate-params");
|
|
var import_config = require("../config");
|
|
var import_utils = require("../utils");
|
|
const VERSION = JSON.parse(import_fs.default.readFileSync(import_path.default.resolve(__dirname, "../../package.json"), "utf8")).version;
|
|
const ARGS_PARSER_OPTIONS = {
|
|
alias: {
|
|
"f": "file",
|
|
"s": "source",
|
|
"g": "glob",
|
|
"d": "out-file",
|
|
"o": "out-dir",
|
|
"t": "transformer",
|
|
"c": "config"
|
|
},
|
|
string: ["file", "source", "glob", "out-file", "out-dir", "transformer", "config"],
|
|
boolean: ["debug"]
|
|
};
|
|
function cli() {
|
|
import_utils.logger.time("cli:start");
|
|
const argv = (0, import_yargs_parser.default)(process.argv.slice(2), ARGS_PARSER_OPTIONS);
|
|
const { error, version, commandName, params, config } = parseArgs(argv);
|
|
if (error) {
|
|
(0, import_utils.exit)(1, "error", "cli", error.message);
|
|
}
|
|
if (version) {
|
|
process.stdout.write(`${VERSION}
|
|
`);
|
|
process.exit(0);
|
|
}
|
|
if (commandName) {
|
|
commands.get(commandName)(params);
|
|
exitSuccess();
|
|
}
|
|
if (config !== void 0) {
|
|
(0, import_config.processConfigFile)(config);
|
|
exitSuccess();
|
|
}
|
|
process.stdout.write("No command passed and no default config found!\n");
|
|
process.exit(0);
|
|
}
|
|
function parseArgs(argv) {
|
|
try {
|
|
(0, import_validate_params.validateParams)(argv, ARGS_PARSER_OPTIONS);
|
|
} catch (error) {
|
|
return { error };
|
|
}
|
|
const {
|
|
_: _commandList,
|
|
file,
|
|
source,
|
|
glob,
|
|
outFile,
|
|
outDir,
|
|
transformer,
|
|
config,
|
|
debug,
|
|
version
|
|
} = argv;
|
|
const commandList = _commandList || [];
|
|
const commandName = commandList[0];
|
|
const command = commands.get(commandName);
|
|
const params = { file, source, glob, outFile, outDir, transformer };
|
|
if (version) {
|
|
return { version };
|
|
}
|
|
if (debug) {
|
|
import_utils.logger.level = "debug";
|
|
import_utils.logger.silly("cli", "Starting in debug mode.");
|
|
}
|
|
if (commandName && command) {
|
|
import_utils.logger.silly("cli", "Command is: %s", commandName);
|
|
return { commandName, params };
|
|
}
|
|
import_utils.logger.silly("cli", "No command passed.");
|
|
if (config) {
|
|
import_utils.logger.silly("cli", "Config passed: %s", config);
|
|
return { config };
|
|
}
|
|
import_utils.logger.silly("cli", "No config passed.");
|
|
const hasParams = Object.values(params).filter((item) => item !== void 0).length > 0;
|
|
const hasConfig = import_fs.default.existsSync("sass.config.js");
|
|
if (hasParams) {
|
|
import_utils.logger.silly("cli", "Attempting build command with cli parameters");
|
|
return { commandName: "build", params };
|
|
}
|
|
if (hasConfig) {
|
|
import_utils.logger.silly("cli", "Attempting to process default config");
|
|
return { config: null };
|
|
}
|
|
return {};
|
|
}
|
|
function exitSuccess() {
|
|
(0, import_utils.exit)(0, "silly", "cli", `Finished after ${import_utils.logger.timeEnd("cli:start")}`);
|
|
}
|
|
// Annotate the CommonJS export names for ESM import in node:
|
|
0 && (module.exports = {
|
|
cli,
|
|
parseArgs
|
|
});
|