refactor: rename plugin name (#771)

规范插件包名称
工具栏generate-vue插件改名为 generate-code(不限定生成vue代码,传入不同的出码服务可以生成不同技术栈代码)
状态管理插件plugin-data改名为plugin-state,更符合语义
工具栏锁定插件toolbar-checkinout改名为 toolbar-lock,更易理解(当前图标早已切换为lock,而不是之前的checkin和checkout)
This commit is contained in:
Hexqi 2024-09-03 14:11:05 +08:00 committed by GitHub
parent 3eb2ecd039
commit 591ff8e171
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
38 changed files with 69 additions and 456 deletions

View File

@ -21,11 +21,11 @@ import {
Save,
Clean,
Preview,
GenerateVue,
GenerateCode,
Refresh,
Collaboration,
Materials,
Data,
State,
Script,
Tree,
Help,
@ -72,12 +72,12 @@ export default {
Clean,
Preview,
Refresh,
GenerateVue,
GenerateCode,
Save,
Fullscreen,
Lang
],
plugins: [Materials, Tree, Page, Block, Datasource, Bridge, I18n, Script, Data, Schema, Help, Robot],
plugins: [Materials, Tree, Page, Block, Datasource, Bridge, I18n, Script, State, Schema, Help, Robot],
dsls: [{ id: 'engine.dsls.dslvue' }],
settings: [Props, Styles, Events],
canvas: Canvas

View File

@ -8,7 +8,7 @@
"@opentiny/tiny-engine-meta-register": ["packages/register/src/index.js"],
"@opentiny/tiny-engine-canvas": ["packages/canvas/src/index.js"],
"@opentiny/tiny-engine-plugin-materials": ["packages/plugins/materials/index"],
"@opentiny/tiny-engine-plugin-data": ["packages/plugins/data/index"],
"@opentiny/tiny-engine-plugin-state": ["packages/plugins/state/index"],
"@opentiny/tiny-engine-plugin-script": ["packages/plugins/script/index"],
"@opentiny/tiny-engine-plugin-tree": ["packages/plugins/tree/index"],
"@opentiny/tiny-engine-plugin-help": ["packages/plugins/help/index"],
@ -24,11 +24,11 @@
"@opentiny/tiny-engine-toolbar-fullscreen": ["packages/toolbars/fullscreen/index"],
"@opentiny/tiny-engine-toolbar-lang": ["packages/toolbars/lang/index"],
"@opentiny/tiny-engine-toolbar-layout": ["packages/toolbars/layout/index"],
"@opentiny/tiny-engine-toolbar-checkinout": ["packages/toolbars/lock/index"],
"@opentiny/tiny-engine-toolbar-lock": ["packages/toolbars/lock/index"],
"@opentiny/tiny-engine-toolbar-logo": ["packages/toolbars/logo/index"],
"@opentiny/tiny-engine-toolbar-media": ["packages/toolbars/media/index"],
"@opentiny/tiny-engine-toolbar-preview": ["packages/toolbars/preview/index"],
"@opentiny/tiny-engine-toolbar-generate-vue": ["packages/toolbars/generate-vue/index"],
"@opentiny/tiny-engine-toolbar-generate-code": ["packages/toolbars/generate-code/index"],
"@opentiny/tiny-engine-toolbar-clean": ["packages/toolbars/clean/index"],
"@opentiny/tiny-engine-toolbar-save": ["packages/toolbars/save/index"],
"tiny-engine-canvas": ["packages/canvas/index"],
@ -37,7 +37,7 @@
"@opentiny/tiny-engine-svgs": ["packages/svgs/index"],
"@opentiny/tiny-engine-http": ["packages/http/index"],
"@opentiny/tiny-engine-plugin-materials/*": ["packages/plugins/materials/*"],
"@opentiny/tiny-engine-plugin-data/*": ["packages/plugins/data/*"],
"@opentiny/tiny-engine-plugin-state/*": ["packages/plugins/state/*"],
"@opentiny/tiny-engine-plugin-script/*": ["packages/plugins/script/*"],
"@opentiny/tiny-engine-plugin-tree/*": ["packages/plugins/tree/*"],
"@opentiny/tiny-engine-plugin-help/*": ["packages/plugins/help/*"],
@ -53,7 +53,7 @@
"@opentiny/tiny-engine-toolbar-fullscreen/*": ["packages/toolbars/fullscreen/*"],
"@opentiny/tiny-engine-toolbar-lang/*": ["packages/toolbars/lang/*"],
"@opentiny/tiny-engine-toolbar-layout/*": ["packages/toolbars/layout/*"],
"@opentiny/tiny-engine-toolbar-checkinout/*": ["packages/toolbars/lock/*"],
"@opentiny/tiny-engine-toolbar-lock/*": ["packages/toolbars/lock/*"],
"@opentiny/tiny-engine-toolbar-logo/*": ["packages/toolbars/logo/*"],
"@opentiny/tiny-engine-toolbar-media/*": ["packages/toolbars/media/*"],
"@opentiny/tiny-engine-toolbar-preview/*": ["packages/toolbars/preview/*"],

View File

@ -18,7 +18,7 @@ const getDevAlias = (useSourceAlias) => {
'@opentiny/tiny-engine-common': path.resolve(basePath, 'packages/common/index.js'),
'@opentiny/tiny-engine-plugin-materials': path.resolve(basePath, 'packages/plugins/materials/index.js'),
'@opentiny/tiny-engine-plugin-block': path.resolve(basePath, 'packages/plugins/block/index.js'),
'@opentiny/tiny-engine-plugin-data': path.resolve(basePath, 'packages/plugins/data/index.js'),
'@opentiny/tiny-engine-plugin-state': path.resolve(basePath, 'packages/plugins/state/index.js'),
'@opentiny/tiny-engine-plugin-datasource': path.resolve(basePath, 'packages/plugins/datasource/index.js'),
'@opentiny/tiny-engine-plugin-script': path.resolve(basePath, 'packages/plugins/script/index.js'),
'@opentiny/tiny-engine-plugin-tree': path.resolve(basePath, 'packages/plugins/tree/index.js'),
@ -37,12 +37,12 @@ const getDevAlias = (useSourceAlias) => {
'@opentiny/tiny-engine-toolbar-fullscreen': path.resolve(basePath, 'packages/toolbars/fullscreen/index.js'),
'@opentiny/tiny-engine-toolbar-lang': path.resolve(basePath, 'packages/toolbars/lang/index.js'),
'@opentiny/tiny-engine-toolbar-layout': path.resolve(basePath, 'packages/toolbars/layout/index.js'),
'@opentiny/tiny-engine-toolbar-checkinout': path.resolve(basePath, 'packages/toolbars/lock/index.js'),
'@opentiny/tiny-engine-toolbar-lock': path.resolve(basePath, 'packages/toolbars/lock/index.js'),
'@opentiny/tiny-engine-toolbar-logo': path.resolve(basePath, 'packages/toolbars/logo/index.js'),
'@opentiny/tiny-engine-toolbar-logout': path.resolve(basePath, 'packages/toolbars/logout/index.js'),
'@opentiny/tiny-engine-toolbar-media': path.resolve(basePath, 'packages/toolbars/media/index.js'),
'@opentiny/tiny-engine-toolbar-preview': path.resolve(basePath, 'packages/toolbars/preview/index.js'),
'@opentiny/tiny-engine-toolbar-generate-vue': path.resolve(basePath, 'packages/toolbars/generate-vue/index.js'),
'@opentiny/tiny-engine-toolbar-generate-code': path.resolve(basePath, 'packages/toolbars/generate-code/index.js'),
'@opentiny/tiny-engine-toolbar-refresh': path.resolve(basePath, 'packages/toolbars/refresh/index.js'),
'@opentiny/tiny-engine-toolbar-redoundo': path.resolve(basePath, 'packages/toolbars/redoundo/index.js'),
'@opentiny/tiny-engine-toolbar-clean': path.resolve(basePath, 'packages/toolbars/clean/index.js'),

View File

@ -4,20 +4,19 @@ export { init } from './src/init'
export { default as Breadcrumb, BreadcrumbService } from '@opentiny/tiny-engine-toolbar-breadcrumb'
export { default as Fullscreen } from '@opentiny/tiny-engine-toolbar-fullscreen'
export { default as Lang } from '@opentiny/tiny-engine-toolbar-lang'
export { default as Checkinout } from '@opentiny/tiny-engine-toolbar-checkinout'
export { default as Logo } from '@opentiny/tiny-engine-toolbar-logo'
export { default as Lock } from '@opentiny/tiny-engine-toolbar-checkinout'
export { default as Lock } from '@opentiny/tiny-engine-toolbar-lock'
export { default as Media } from '@opentiny/tiny-engine-toolbar-media'
export { default as Redoundo, HistoryService } from '@opentiny/tiny-engine-toolbar-redoundo'
export { default as Save } from '@opentiny/tiny-engine-toolbar-save'
export { default as Clean } from '@opentiny/tiny-engine-toolbar-clean'
export { default as Preview } from '@opentiny/tiny-engine-toolbar-preview'
export { default as GenerateVue, SaveLocalService } from '@opentiny/tiny-engine-toolbar-generate-vue'
export { default as GenerateCode, SaveLocalService } from '@opentiny/tiny-engine-toolbar-generate-code'
export { default as Refresh } from '@opentiny/tiny-engine-toolbar-refresh'
export { default as Collaboration } from '@opentiny/tiny-engine-toolbar-collaboration'
export { default as Setting } from '@opentiny/tiny-engine-toolbar-setting'
export { default as Materials, ResourceService, MaterialService } from '@opentiny/tiny-engine-plugin-materials'
export { default as Data } from '@opentiny/tiny-engine-plugin-data'
export { default as State } from '@opentiny/tiny-engine-plugin-state'
export { default as Script } from '@opentiny/tiny-engine-plugin-script'
export { default as Tree } from '@opentiny/tiny-engine-plugin-tree'
export { default as Help, HelpService } from '@opentiny/tiny-engine-plugin-help'

View File

@ -52,7 +52,7 @@
"@opentiny/tiny-engine-i18n-host": "workspace:*",
"@opentiny/tiny-engine-plugin-block": "workspace:*",
"@opentiny/tiny-engine-plugin-bridge": "workspace:*",
"@opentiny/tiny-engine-plugin-data": "workspace:*",
"@opentiny/tiny-engine-plugin-state": "workspace:*",
"@opentiny/tiny-engine-plugin-datasource": "workspace:*",
"@opentiny/tiny-engine-plugin-help": "workspace:*",
"@opentiny/tiny-engine-plugin-i18n": "workspace:*",
@ -73,11 +73,11 @@
"@opentiny/tiny-engine-theme-light": "workspace:*",
"@opentiny/tiny-engine-theme-base": "workspace:*",
"@opentiny/tiny-engine-toolbar-breadcrumb": "workspace:*",
"@opentiny/tiny-engine-toolbar-checkinout": "workspace:*",
"@opentiny/tiny-engine-toolbar-lock": "workspace:*",
"@opentiny/tiny-engine-toolbar-clean": "workspace:*",
"@opentiny/tiny-engine-toolbar-collaboration": "workspace:*",
"@opentiny/tiny-engine-toolbar-fullscreen": "workspace:*",
"@opentiny/tiny-engine-toolbar-generate-vue": "workspace:*",
"@opentiny/tiny-engine-toolbar-generate-code": "workspace:*",
"@opentiny/tiny-engine-toolbar-lang": "workspace:*",
"@opentiny/tiny-engine-toolbar-layout": "workspace:*",
"@opentiny/tiny-engine-toolbar-logo": "workspace:*",

View File

@ -14,19 +14,19 @@ import {
Breadcrumb,
Fullscreen,
Lang,
Checkinout,
Lock,
Logo,
Media,
Redoundo,
Save,
Clean,
Preview,
GenerateVue,
GenerateCode,
Refresh,
Collaboration,
Setting,
Materials,
Data,
State,
Script,
Tree,
Help,
@ -71,15 +71,15 @@ export default {
Clean,
Refresh,
Save,
GenerateVue,
GenerateCode,
Preview,
Redoundo,
Fullscreen,
Checkinout,
Lock,
Setting,
Lang
],
plugins: [Materials, Tree, Page, Block, Datasource, Bridge, I18n, Script, Data, Schema, Help, Robot],
plugins: [Materials, Tree, Page, Block, Datasource, Bridge, I18n, Script, State, Schema, Help, Robot],
dsls: [{ id: 'engine.dsls.dslvue' }],
settings: [Props, Styles, Events],
canvas: Canvas

View File

@ -1,22 +0,0 @@
/**
* Copyright (c) 2023 - present TinyEngine Authors.
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
*
* Use of this source code is governed by an MIT-style license.
*
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
*
*/
export const STATE = {
CURRENT_STATE: 'current',
GLOBAL_STATE: 'global'
}
export const OPTION_TYPE = {
ADD: 'add',
UPDATE: 'update',
COPY: 'copy'
}

View File

@ -1,5 +1,5 @@
{
"name": "@opentiny/tiny-engine-plugin-data",
"name": "@opentiny/tiny-engine-plugin-state",
"version": "1.0.3",
"publishConfig": {
"access": "public"
@ -15,7 +15,7 @@
"repository": {
"type": "git",
"url": "https://github.com/opentiny/tiny-engine",
"directory": "packages/plugins/data"
"directory": "packages/plugins/state"
},
"bugs": {
"url": "https://github.com/opentiny/tiny-engine/issues"

View File

@ -1,14 +1,14 @@
/**
* Copyright (c) 2023 - present TinyEngine Authors.
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
*
* Use of this source code is governed by an MIT-style license.
*
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
*
*/
* Copyright (c) 2023 - present TinyEngine Authors.
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
*
* Use of this source code is governed by an MIT-style license.
*
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
*
*/
/**
* 校验monaco编辑器必填与是否有语法错误

View File

@ -0,0 +1,22 @@
/**
* Copyright (c) 2023 - present TinyEngine Authors.
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
*
* Use of this source code is governed by an MIT-style license.
*
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
*
*/
export const STATE = {
CURRENT_STATE: 'current',
GLOBAL_STATE: 'global'
}
export const OPTION_TYPE = {
ADD: 'add',
UPDATE: 'update',
COPY: 'copy'
}

View File

@ -24,7 +24,7 @@ export default defineConfig({
build: {
lib: {
entry: path.resolve(__dirname, './index.js'),
name: 'plugin-data',
name: 'plugin-state',
fileName: () => 'index.js',
formats: ['es']
},

View File

@ -26,7 +26,7 @@ export const META_APP = {
Clean: 'engine.toolbars.clean',
Refresh: 'engine.toolbars.refresh',
Save: 'engine.toolbars.save',
GenerateVue: 'engine.toolbars.generate-vue',
GenerateCode: 'engine.toolbars.generate-code',
Preview: 'engine.toolbars.preview',
RedoUndo: 'engine.toolbars.redoundo',
Fullscreen: 'engine.toolbars.fullscreen',

View File

@ -1,7 +1,7 @@
export default {
id: 'engine.toolbars.generate-vue',
id: 'engine.toolbars.generate-code',
type: 'toolbars',
title: 'generate-vue',
title: 'generate-code',
icon: '',
align: 'right'
}

View File

@ -1,5 +1,5 @@
{
"name": "@opentiny/tiny-engine-toolbar-generate-vue",
"name": "@opentiny/tiny-engine-toolbar-generate-code",
"version": "1.0.3",
"publishConfig": {
"access": "public"
@ -15,7 +15,7 @@
"repository": {
"type": "git",
"url": "https://github.com/opentiny/tiny-engine",
"directory": "packages/toolbars/generate-vue"
"directory": "packages/toolbars/generate-code"
},
"bugs": {
"url": "https://github.com/opentiny/tiny-engine/issues"
@ -27,8 +27,7 @@
"@opentiny/tiny-engine-common": "workspace:*",
"@opentiny/tiny-engine-http": "workspace:*",
"@opentiny/tiny-engine-utils": "workspace:*",
"@opentiny/tiny-engine-meta-register": "workspace:*",
"prettier": "2.7.1"
"@opentiny/tiny-engine-meta-register": "workspace:*"
},
"devDependencies": {
"@vitejs/plugin-vue": "^4.2.3",

View File

@ -24,12 +24,12 @@ export default defineConfig({
build: {
lib: {
entry: path.resolve(__dirname, './index.js'),
name: 'toolbar-generate-vue',
name: 'toolbar-generate-code',
fileName: () => 'index.js',
formats: ['es']
},
rollupOptions: {
external: ['vue', /@opentiny\/tiny-engine.*/, /@opentiny\/vue.*/, /^prettier.*/]
external: ['vue', /@opentiny\/tiny-engine.*/, /@opentiny\/vue.*/]
}
}
})

View File

@ -1,385 +0,0 @@
/**
* Copyright (c) 2023 - present TinyEngine Authors.
* Copyright (c) 2023 - present Huawei Cloud Computing Technologies Co., Ltd.
*
* Use of this source code is governed by an MIT-style license.
*
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
*
*/
import prettier from 'prettier'
import parserHtml from 'prettier/parser-html'
import parseCss from 'prettier/parser-postcss'
import parserBabel from 'prettier/parser-babel'
import prettierCommon from '@opentiny/tiny-engine-common/js/config-files/prettierrc'
// LOWCODE_TODO: 从本地配置文件获取
const basePaths = {
i18n: 'src/i18n/',
pages: 'src/views/',
blocks: 'src/components/',
utils: 'src/lowcode/utils.js',
dataSource: 'src/lowcode/dataSource.json',
router: 'src/router/index.js',
store: 'src/stores/'
}
const FILE_TYPES = {
Page: 'Page',
Block: 'Block',
I18n: 'I18n',
Utils: 'Utils',
DataSource: 'DataSource',
Router: 'Router',
Store: 'Store'
}
function formatScript(string) {
return prettier.format(string, {
...prettierCommon,
parser: 'babel',
plugins: [parserBabel]
})
}
function getPaths(page, pagesMap) {
if (!page) return ''
const parentArr = []
let cur = page
let parentId = `${cur.parentId}`
while (parentId && pagesMap[parentId]) {
parentArr.unshift(pagesMap[parentId].route)
cur = pagesMap[parentId]
parentId = `${cur.parentId}`
}
return parentArr.length ? parentArr.join('/') + '/' : ''
}
function getCurrentPagePath(params, pages = []) {
if (!pages.length) {
return ''
}
const pagesMap = pages.reduce((acc, cur) => ({ ...acc, [`${cur.id}`]: cur }), {})
const curPage = pages.find((page) => page.id === params.id)
return getPaths(curPage, pagesMap)
}
function generateStores({ globalState }) {
if (!Array.isArray(globalState)) {
return []
}
const filePath = basePaths.store
const result = "import { defineStore } from 'pinia'\n\n"
const res = []
const storeIds = []
const getStoreFnStrs = (getters = {}) =>
Object.values(getters)
.map(({ value }) => value?.replace(/function /, ''))
.join(',\n')
globalState.forEach(({ id, state, getters, actions }) => {
storeIds.push(id)
const storeCode = `export const ${id} = defineStore({
id: '${id}',
state: () => (${JSON.stringify(state)}),
getters: {
${getStoreFnStrs(getters)}
},
actions: {
${getStoreFnStrs(actions)}
}
})\n`
res.push({
filePath: `${filePath}${id}.js`,
fileType: FILE_TYPES.Store,
fileContent: formatScript(`${result}\n${storeCode}`)
})
})
res.push({
filePath: `${filePath}index.js`,
fileType: FILE_TYPES.Store,
fileContent: formatScript(storeIds.map((id) => `export { ${id} } from './${id}'`).join('\n'))
})
return res
}
function generatePageFiles(codeList, pagePath = '') {
const pageFiles = []
const formatTypePluginMap = {
babel: [parserBabel],
vue: [parserHtml, parserBabel, parseCss],
javascript: [parserBabel],
css: [parseCss],
less: [parseCss],
sass: [parseCss],
json: [parserBabel]
}
const blockList = codeList.filter((item) => item.type === 'Block').map((item) => item.panelName)
codeList.forEach(({ panelName, panelValue, prettierOpts, type }) => {
if (panelName && panelValue) {
if (prettierOpts?.parser && formatTypePluginMap[prettierOpts.parser]) {
panelValue = prettier.format(panelValue, {
...prettierOpts,
plugins: formatTypePluginMap[prettierOpts.parser]
})
}
if (type === 'Page' && blockList.length) {
blockList.forEach((blockName) => {
panelValue = panelValue.replace(`./${blockName}`, `${basePaths.blocks.replace('src/', '@/')}${blockName}`)
})
}
pageFiles.push({
fileType: type,
filePath: (type === 'Block' ? basePaths.blocks : basePaths.pages + pagePath) + panelName,
fileContent: panelValue
})
}
})
return pageFiles
}
function generateI18n({ i18n }) {
if (!i18n) {
return []
}
const langMap = {
en_US: 'en.json',
zh_CN: 'zh.json'
}
const result = []
Object.keys(i18n).forEach((key) => {
const fileName = langMap[key]
if (!fileName) {
const supportedLocales = Object.keys(this.langMap)
const message = `failed to generate i18n: invalid locale: ${key}. Only support ${supportedLocales.join('/')}`
this.logger.error(message)
throw new Error(message)
}
const filePath = basePaths.i18n + fileName
result.push({
fileType: FILE_TYPES.I18n,
filePath,
fileContent: JSON.stringify(i18n[key], null, 2)
})
})
return result
}
function generateDataSource({ dataSource }) {
const { dataHandler, list: originList } = dataSource || {}
if (!originList?.length) {
return []
}
const filePath = basePaths.dataSource
const list = originList.map(({ id, name, data }) => ({ id, name, ...data }))
const code = { dataHandler, list }
return [
{
filePath,
fileType: FILE_TYPES.DataSource,
fileContent: JSON.stringify(code, null, 2)
}
]
}
function getImportStrsFromImports(imports) {
const result = []
Object.entries(imports).forEach(([key, value]) => {
const list = []
if (value.exportName) {
list.push(value.exportName)
}
if (Array.isArray(value.destructurings) && value.destructurings.length) {
const destructuringsWithAliases = value.destructurings.map((destructuring, index) => {
const alias = value.aliases[index]
if (destructuring === alias) {
return destructuring
}
return `${destructuring} as ${alias}`
})
list.push(`{ ${destructuringsWithAliases.join(', ')} }`)
}
result.push(`import ${list.join(', ')} from '${key}'`)
})
return result
}
function parseExportInfo(utilItem, imports, exportNames, functionStrs) {
if (utilItem.type === 'npm') {
const importFrom = `${utilItem.content.package || ''}${utilItem.content.main || ''}`
if (importFrom) {
imports[importFrom] = imports[importFrom] || {}
const importItem = imports[importFrom]
if (utilItem.content.destructuring) {
importItem.destructurings = importItem.destructurings || []
importItem.destructurings.push(utilItem.content.exportName)
importItem.aliases = importItem.aliases || []
importItem.aliases.push(utilItem.name)
} else {
importItem.exportName = utilItem.name
}
exportNames.push(utilItem.name)
}
} else if (utilItem.type === 'function') {
functionStrs.push(`const ${utilItem.name} = ${utilItem.content.value}`)
exportNames.push(utilItem.name)
}
}
function generateExport(list) {
const strs = []
if (Array.isArray(list)) {
const exportNames = []
const functionStrs = []
const imports = {}
list.forEach((item) => {
parseExportInfo(item, imports, exportNames, functionStrs)
})
const importStrs = getImportStrsFromImports(imports)
strs.push(...importStrs, ...functionStrs)
if (exportNames.length) {
strs.push(`export { ${exportNames.join(', ')} }`)
}
}
return strs.join('\n')
}
function generateUtils({ utils }) {
const result = []
if (utils?.length) {
const utilStr = generateExport(utils)
const content = formatScript(utilStr)
result.push({
fileType: FILE_TYPES.Utils,
filePath: basePaths.utils,
fileContent: formatScript(content)
})
}
return result
}
function generateRoutes(pages) {
const pagesMap = pages.reduce((acc, cur) => ({ ...acc, [`${cur.id}`]: cur }), {})
const routes = pages
.filter((page) => page.isPage)
.map((page) => {
const paths = getPaths(page, pagesMap)
const fileName = `${page.name}.vue`
return {
fileName,
filePath: `${paths}${fileName}`,
isHome: page.isHome,
path: `/${paths}${page.route.trim()}`,
id: page.id,
name: page.name,
parentId: page.parentId
}
})
const hasRoot = routes.some(({ path }) => path === '/')
if (!hasRoot && routes.length) {
const { path: homePath } = routes.find(({ isHome }) => isHome) || {}
if (homePath) {
routes.unshift({ path: '/', redirect: homePath })
} else {
routes.unshift({ path: '/', redirect: routes[0].path })
}
}
return routes
}
export function generateRouter(pages) {
if (!pages?.length) {
return []
}
const routes = generateRoutes(pages)
const importRoutes = "import { createRouter, createWebHashHistory } from 'vue-router'\n"
const content = `
${importRoutes}
const routes = [
${routes
.map(
({ fileName, path, redirect, filePath }) => `{
path: '${path}',${redirect ? `redirect: '${redirect}',` : ''}
${fileName ? `component: () => import('${basePaths.pages.replace('src/', '@/')}${filePath}'),` : ''}
}`
)
.join(',')}
]
export default createRouter({
history: createWebHashHistory(),
routes
})
`
const codeStr = formatScript(content)
return [
{
fileType: FILE_TYPES.Router,
filePath: basePaths.router,
fileContent: codeStr
}
]
}
export function generateVuePage({ params, codeList, metaData, pageList }) {
const pageFiles = generatePageFiles(codeList, getCurrentPagePath(params, pageList))
const i18nFiles = generateI18n(metaData)
const utilsFiles = generateUtils(metaData)
const dataSourceFiles = generateDataSource(metaData)
const storeFiles = generateStores(metaData)
const routeFiles = generateRouter(pageList)
return [...pageFiles, ...i18nFiles, ...utilsFiles, ...dataSourceFiles, ...storeFiles, ...routeFiles]
}
export function generateVueBlock({ params, codeList, metaData }) {
return generateVuePage({ params, codeList, metaData })
}

View File

@ -1,5 +1,5 @@
{
"name": "@opentiny/tiny-engine-toolbar-checkinout",
"name": "@opentiny/tiny-engine-toolbar-lock",
"version": "1.0.3",
"publishConfig": {
"access": "public"

View File

@ -24,7 +24,7 @@ export default defineConfig({
build: {
lib: {
entry: path.resolve(__dirname, './index.js'),
name: 'toolbar-checkinout',
name: 'toolbar-lock',
fileName: () => 'index.js',
formats: ['es']
},