|
|
|
@@ -7,6 +7,7 @@ const glob = require('glob');
|
|
|
|
|
const resolve = require('@~local/config/resolve');
|
|
|
|
|
const defaultOptions = require('./defaultOptions');
|
|
|
|
|
const pipelineDefault = require('./pipeline.default');
|
|
|
|
|
const rollupPluginClean = require('./plugins/clean');
|
|
|
|
|
|
|
|
|
|
const workspaceRoot = path.dirname(execSync('npm root').toString());
|
|
|
|
|
const pkg = require(`${workspaceRoot}/package.json`);
|
|
|
|
@@ -30,6 +31,7 @@ const resolvePath = (basePath, pathToResolve, appendExt) => {
|
|
|
|
|
|
|
|
|
|
const mergeAndResolveOptions = (userOptions) => {
|
|
|
|
|
const {
|
|
|
|
|
clean: defaultClean,
|
|
|
|
|
outDir: defaultOutDir,
|
|
|
|
|
paths: defaultPaths,
|
|
|
|
|
versions: defaultVersions,
|
|
|
|
@@ -44,6 +46,7 @@ const mergeAndResolveOptions = (userOptions) => {
|
|
|
|
|
} = defaultOptions;
|
|
|
|
|
const {
|
|
|
|
|
project,
|
|
|
|
|
clean: rawClean,
|
|
|
|
|
outDir: rawOutDir,
|
|
|
|
|
paths: rawPaths = {},
|
|
|
|
|
alias: rawAlias = {},
|
|
|
|
@@ -56,12 +59,13 @@ const mergeAndResolveOptions = (userOptions) => {
|
|
|
|
|
banner: rawBanner,
|
|
|
|
|
useEsbuild: rawUseEsbuild,
|
|
|
|
|
} = userOptions;
|
|
|
|
|
const projectPath = process.cwd();
|
|
|
|
|
const projectDir = process.cwd();
|
|
|
|
|
const workspaces = pkg.workspaces
|
|
|
|
|
.map((pattern) => glob.sync(pattern, { cwd: workspaceRoot }))
|
|
|
|
|
.flat();
|
|
|
|
|
const mergedOptions = {
|
|
|
|
|
project: project || path.basename(projectPath),
|
|
|
|
|
project: project || path.basename(projectDir),
|
|
|
|
|
projectDir,
|
|
|
|
|
extractStyles: rawExtractStyles ?? defaultExtractStyles,
|
|
|
|
|
extractTypes: rawExtractTypes ?? defaultExtractTypes,
|
|
|
|
|
extractPackageJson: rawExtractPackageJson ?? defaultExtractPackageJson,
|
|
|
|
@@ -69,6 +73,7 @@ const mergeAndResolveOptions = (userOptions) => {
|
|
|
|
|
banner: rawBanner ?? defaultBanner,
|
|
|
|
|
versions: rawVersions ?? defaultVersions,
|
|
|
|
|
useEsbuild: rawUseEsbuild ?? defaultUseEsbuild,
|
|
|
|
|
clean: rawClean ?? defaultClean,
|
|
|
|
|
outDir: rawOutDir ?? defaultOutDir,
|
|
|
|
|
paths: {
|
|
|
|
|
...defaultPaths,
|
|
|
|
@@ -94,12 +99,12 @@ const mergeAndResolveOptions = (userOptions) => {
|
|
|
|
|
const pluginFromFn = (plugin) =>
|
|
|
|
|
typeof plugin === 'function' ? plugin(mergedOptions, workspaceRoot, workspaces) : plugin;
|
|
|
|
|
|
|
|
|
|
paths.js = resolvePath(projectPath, path.join(outDir, js));
|
|
|
|
|
paths.types = resolvePath(projectPath, path.join(outDir, types));
|
|
|
|
|
paths.styles = resolvePath(projectPath, path.join(outDir, styles));
|
|
|
|
|
paths.js = resolvePath(projectDir, path.join(outDir, js));
|
|
|
|
|
paths.types = resolvePath(projectDir, path.join(outDir, types));
|
|
|
|
|
paths.styles = resolvePath(projectDir, path.join(outDir, styles));
|
|
|
|
|
|
|
|
|
|
mergedOptions.outDir = resolvePath(projectPath, outDir);
|
|
|
|
|
mergedOptions.rollup.input = resolvePath(projectPath, mergedOptions.rollup.input, true);
|
|
|
|
|
mergedOptions.outDir = resolvePath(projectDir, outDir);
|
|
|
|
|
mergedOptions.rollup.input = resolvePath(projectDir, mergedOptions.rollup.input, true);
|
|
|
|
|
mergedOptions.rollup.output = {
|
|
|
|
|
...(mergedOptions.rollup.output || {}),
|
|
|
|
|
name: mergedOptions.rollup.output?.name || mergedOptions.project,
|
|
|
|
@@ -115,15 +120,15 @@ const mergeAndResolveOptions = (userOptions) => {
|
|
|
|
|
|
|
|
|
|
const createConfig = (userOptions = {}) => {
|
|
|
|
|
const options = mergeAndResolveOptions(userOptions);
|
|
|
|
|
const { project, useEsbuild, verbose } = options;
|
|
|
|
|
const { project, useEsbuild, verbose, clean, outDir, projectDir } = options;
|
|
|
|
|
const result = pipelineDefault(resolve, options, useEsbuild);
|
|
|
|
|
const resultArr = Array.isArray(result) ? result : [result];
|
|
|
|
|
const prePlugins = !Array.isArray(resultArr[0].plugins) ? [] : resultArr[0].plugins;
|
|
|
|
|
|
|
|
|
|
resultArr[0].plugins = prePlugins;
|
|
|
|
|
|
|
|
|
|
if (verbose) {
|
|
|
|
|
if (!Array.isArray(resultArr[0].plugins)) {
|
|
|
|
|
resultArr[0].plugins = [];
|
|
|
|
|
}
|
|
|
|
|
resultArr[0].plugins.push({
|
|
|
|
|
prePlugins.push({
|
|
|
|
|
name: 'PROJECT',
|
|
|
|
|
buildStart() {
|
|
|
|
|
console.log('');
|
|
|
|
@@ -132,6 +137,9 @@ const createConfig = (userOptions = {}) => {
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (clean && outDir !== projectDir) {
|
|
|
|
|
prePlugins.push(rollupPluginClean({ paths: [outDir], verbose }));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return resultArr;
|
|
|
|
|
};
|
|
|
|
|