@lcap/builder
Version:
lcap builder utils
70 lines (69 loc) • 3.32 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const lcap_theme_code_1 = __importDefault(require("./lcap-theme-code"));
const lcap_build_1 = __importDefault(require("./lcap-build"));
const lcap_default_config_1 = __importDefault(require("./lcap-default-config"));
const lcap_use_nasl_ui_1 = __importDefault(require("./lcap-use-nasl-ui"));
const utils_1 = require("../utils");
const DEFAULT_THEME_OPTIONS = {
findThemeType: 'theme',
themeVarCssPath: './src/theme/vars.css',
themeComponentFolder: './src/theme/components',
themePreviewEntry: './src/theme/index',
previewPages: [
{
name: 'dashboard',
title: 'Dashboard',
},
{
name: 'form',
title: '表单页',
},
],
};
const EXTENSION_DEFAULT_THEME_OPTIONS = {
findThemeType: 'component',
themeVarCssPath: '',
themeComponentFolder: './src/components',
themePreviewEntry: '',
previewPages: [],
};
exports.default = (options = {}) => {
var _a;
const cwd = process.cwd();
const isExtension = options.type && options.type === 'extension';
const defaultPublicPath = isExtension ? 'https://static-vusion.163yun.com/packages/extension' : 'https://static-vusion.163yun.com/packages';
const defaultThemeOptions = isExtension ? EXTENSION_DEFAULT_THEME_OPTIONS : DEFAULT_THEME_OPTIONS;
const pluginOption = Object.assign(Object.assign({ rootPath: cwd, type: 'nasl.ui', framework: 'react', assetsPublicPath: defaultPublicPath, destDir: 'dist-theme' }, options), { theme: Object.assign(Object.assign({}, defaultThemeOptions), (options.theme || {})) });
if (pluginOption.type === 'extension' && pluginOption.theme) {
pluginOption.theme.previewPages = [];
}
if (pluginOption.theme) {
pluginOption.theme.themeVarCssPath = pluginOption.theme.themeVarCssPath ? path_1.default.resolve(cwd, pluginOption.theme.themeVarCssPath || '') : '';
pluginOption.theme.themeComponentFolder = path_1.default.resolve(cwd, pluginOption.theme.themeComponentFolder || '');
}
if (!pluginOption.components || pluginOption.components.length === 0) {
pluginOption.components = (0, utils_1.getConfigComponents)(cwd);
}
return [
(0, lcap_default_config_1.default)({
framework: pluginOption.framework,
destDir: pluginOption.destDir,
type: pluginOption.type,
rootPath: pluginOption.rootPath,
}),
(0, lcap_use_nasl_ui_1.default)({
framework: pluginOption.framework,
destDir: pluginOption.destDir,
type: pluginOption.type,
rootPath: pluginOption.rootPath,
lcapUIExternal: (_a = pluginOption.lcapUIExternal) !== null && _a !== void 0 ? _a : (pluginOption.framework !== 'vue2' ? true : 'auto'),
}),
(0, lcap_theme_code_1.default)(Object.assign(Object.assign({}, pluginOption.theme), { framework: pluginOption.framework, type: pluginOption.type, dependencies: options.dependencies })),
(0, lcap_build_1.default)(pluginOption),
];
};