astro-parcel
Version:
Build and optimize your Astro project using Parcel
101 lines (94 loc) • 3.18 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.filterParcelBuildArgs = exports.help = exports.parseOption = exports.cliOptionsKeys = exports.optionsDefaults = void 0;
const mri_1 = __importDefault(require("mri"));
const lib_1 = require("./lib");
exports.optionsDefaults = {
parcelDist: "./dist",
astroDist: "./dist",
publicDir: "./public",
srcDir: "./src",
nodeBin: process.argv[0],
astroJs: (0, lib_1.getAstroBinPath)(),
parcelJs: (0, lib_1.getParcelBinPath)(),
extraArgs: [],
};
exports.cliOptionsKeys = [
"parcelDist",
"astroDist",
"publicDir",
"srcDir",
"parcelJs",
"astroJs",
"nodeBin",
"help",
"_",
];
function parseOption(args) {
const options = (0, mri_1.default)(args, {
boolean: ["help"],
alias: { h: "help" },
string: ["parcelDist", "astroDist", "publicDir", "srcDir", "parcelJs", "astroJs", "nodeBin"],
default: exports.optionsDefaults,
});
const extraArgs = Object.entries(options)
.filter(([arg, _value]) => !exports.cliOptionsKeys.includes(arg))
.map(([arg, value]) => {
if (value === true) {
return `--${arg}`;
}
return `--${arg} ${value}`;
});
options.extraArgs = extraArgs;
return options;
}
exports.parseOption = parseOption;
function help() {
return `
astro-parcel <command> [options]
Build and optimize your astro project using Parcel
Commands
build
dev
serve
Options
--astroDist <string = "./dist"> the directory that astro writes the build result to
--parcelDist <string = "./dist"> the directory to output the parcel result
--publicDir <string = "./public"> the public folder path. The files that are directly copied to parcelDist folder
--srcDir <string = "./src"> the src folder. This path is used to search for the files that are not present in astroDist folder
Extra arguments are directly passed to Astro and then Parcel
Advanced Options
--astroJs <string = resolved> the astro cli js path
--parcelJs <string = resolved> the parcel cli js path
--nodeBin <string = current node> the node bin path
Examples
astro-parcel build
astro-parcel build --astroDist "./dist" --parcelDist "./parcel-dist"
astro-parcel build --astroDist "./dist" --parcelDist "./parcel-dist" --parcelJs "./node_modules/parcel/lib/bin.js" --astroJs "./node_modules/astro/dist/cli/index.js"
`;
}
exports.help = help;
const parcelBuildOptions = [
"--no-optimize",
"--no-scope-hoist",
"--public-url",
"--no-content-hash",
"--no-cache",
"--config",
"--cache-dir",
"--no-source-maps",
"--target",
"--log-level",
"--no-autoinstall",
"--profile",
"--detailed-report",
"--reporter",
];
function filterParcelBuildArgs(extraArgs) {
return extraArgs.filter((extraArg) => parcelBuildOptions.some((parcelArg) => extraArg.startsWith(parcelArg)));
}
exports.filterParcelBuildArgs = filterParcelBuildArgs;
//# sourceMappingURL=options.js.map