UNPKG

@tarojs/mini-runner

Version:

Mini app runner for taro

107 lines 4.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateQuickAppManifest = exports.generateQuickAppUx = exports.getImportTaroSelfComponents = exports.getTaroJsQuickAppComponentsPath = void 0; const helper_1 = require("@tarojs/helper"); const path = require("path"); function getTaroJsQuickAppComponentsPath(nodeModulesPath) { const taroJsQuickAppComponentsPkg = (0, helper_1.getInstalledNpmPkgPath)(helper_1.taroJsQuickAppComponents, nodeModulesPath); if (!taroJsQuickAppComponentsPkg) { // printLog(processTypeEnum.ERROR, '包安装', `缺少包 ${taroJsQuickAppComponents},请安装!`) process.exit(0); } return path.join(path.dirname(taroJsQuickAppComponentsPkg), 'src/components'); } exports.getTaroJsQuickAppComponentsPath = getTaroJsQuickAppComponentsPath; function getImportTaroSelfComponents(filePath, nodeModulesPath, outputDir, taroSelfComponents) { const importTaroSelfComponents = new Set(); const taroJsQuickAppComponentsPath = getTaroJsQuickAppComponentsPath(nodeModulesPath); taroSelfComponents.forEach(c => { const cPath = path.join(taroJsQuickAppComponentsPath, c); const cMainPath = path.join(cPath, 'index'); const cRelativePath = (0, helper_1.promoteRelativePath)(path.relative(filePath, cMainPath.replace(nodeModulesPath, path.join(outputDir, 'npm')))); importTaroSelfComponents.add({ path: cRelativePath, name: c }); }); return importTaroSelfComponents; } exports.getImportTaroSelfComponents = getImportTaroSelfComponents; function generateQuickAppUx({ script, template, style, imports }) { let uxTxt = ''; if (imports && imports.size) { imports.forEach(item => { uxTxt += `<import src='${item.path}' name='${item.name}'></import>\n`; }); } if (style) { if (helper_1.REG_STYLE.test(style)) { uxTxt += `<style src="${style}"></style>\n`; } else { uxTxt += `<style>\n${style}\n</style>\n`; } } if (template) { uxTxt += `<template>\n${template}\n</template>\n`; } if (script) { if (helper_1.REG_SCRIPT.test(script)) { uxTxt += `<script src="${script}"></script>\n`; } else { uxTxt += `<script>\n${script}\n</script>\n`; } } return uxTxt; } exports.generateQuickAppUx = generateQuickAppUx; function generateQuickAppManifest({ appConfig, quickappJSON, pageConfigs, designWidth }) { // 生成 router const pages = appConfig.pages.concat(); const routerPages = {}; const customPageConfig = quickappJSON.customPageConfig || {}; pages.forEach(element => { const customConfig = customPageConfig[element]; const pageConf = { component: path.basename(element) }; if (customConfig) { const filter = customConfig.filter; const launchMode = customConfig.launchMode; if (filter) { pageConf.filter = filter; } if (launchMode) { pageConf.launchMode = launchMode; } } routerPages[(0, helper_1.removeHeadSlash)(path.dirname(element))] = pageConf; }); delete quickappJSON.customPageConfig; const routerEntry = pages.shift(); const router = { entry: (0, helper_1.removeHeadSlash)(path.dirname(routerEntry)), pages: routerPages }; // 生成 display const display = JSON.parse(JSON.stringify(appConfig.window || {})); display.pages = {}; pageConfigs.forEach((item, page) => { if (item) { display.pages[(0, helper_1.removeHeadSlash)(path.dirname(page))] = item; } }); quickappJSON.router = router; quickappJSON.display = display; quickappJSON.config = Object.assign({}, quickappJSON.config, { designWidth: designWidth || 750 }); if (appConfig.window && appConfig.window.navigationStyle === 'custom') { quickappJSON.display.titleBar = false; delete quickappJSON.display.navigationStyle; } return quickappJSON; } exports.generateQuickAppManifest = generateQuickAppManifest; //# sourceMappingURL=helper.js.map