fix(cli): template path resolve error after built (#279)

fix #267
This commit is contained in:
zuixinwang 2023-06-12 10:59:33 +08:00 committed by GitHub
parent ede750475e
commit 608aa043c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 42 additions and 13 deletions

View File

@ -1,6 +1,11 @@
import path from 'node:path'
import { removeSync } from 'fs-extra'
import { walkFileTree, pathJoin, logGreen, logRed } from '../shared/utils'
import {
walkFileTree,
logGreen,
logRed,
pathJoinFromCLI
} from '../shared/utils'
/**
* packages distruntimenode_modules
@ -22,7 +27,7 @@ const deleteDistFile = () => {
return flag
},
dirPath: pathJoin('..', 'packages'),
dirPath: pathJoinFromCLI('../../packages'),
callback() {
// empty
}

View File

@ -10,11 +10,12 @@ import fs from 'fs-extra'
import semver from 'semver'
import {
getInputCmd,
pathJoin,
walkFileTree,
capitalizeKebabCase,
logGreen,
logYellow
logYellow,
templatePath,
pathJoinFromCLI
} from '../../shared/utils'
import { createModuleMapping } from '../../shared/module-utils'
import handlebarsRender from '../build/handlebars.render'
@ -24,9 +25,9 @@ const args = getInputCmd()
if (args.length > 0) {
const commands: string[] = []
const components: string[] = []
const templateDir = pathJoin('../../public/template/component')
const componetDir = pathJoin('../../../../packages/vue/src')
const { version } = fs.readJSONSync(pathJoin('../../../../packages/vue/package.json'))
const templateDir = path.join(templatePath, './component')
const componetDir = pathJoinFromCLI('../../packages/vue/src')
const { version } = fs.readJSONSync(pathJoinFromCLI('../../packages/vue/package.json'))
args.forEach((item) => {
if (item.indexOf('-') === 0) {

View File

@ -13,16 +13,16 @@ import {
capitalizeKebabCase,
prettierFormat,
logGreen,
logRed
logRed,
templatePath
} from '../../shared/utils'
const svgRE = /\.svg$/
const svgDir = pathJoin('..', 'node_modules', '@opentiny', 'theme', 'svgs')
const iconDir = pathJoin('..', 'packages', 'icon')
const packageJson = 'package.json'
const templatePath = pathJoin('..', 'template')
// 检查是否按照依赖包
// 检查是否安装依赖包
if (!fs.existsSync(svgDir)) {
logYellow('The @opentiny/vue-theme is not exist , please npm install @opentiny/vue-theme.')
}

View File

@ -11,7 +11,7 @@ import {
capitalizeKebabCase,
kebabCase,
prettierFormat,
pathJoin
pathJoinFromCLI
} from './utils'
const require = createRequire(import.meta.url)
@ -434,7 +434,7 @@ const createModuleMapping = (componentName, isMobile = false) => {
const moduleJson = quickSort({ sortData: moduleMap, returnType: 'object' })
fs.writeJsonSync(
pathJoin('..', 'modules.json'),
pathJoinFromCLI('../../packages/modules.json'),
prettierFormat({
str: JSON.stringify(moduleJson),
options: {

View File

@ -482,6 +482,23 @@ const filesFragmentReplace = (folderPath, regExpStr: Array<string | RegExp> | st
}
}
/** 是否已打包 */
const isCLIProduction = process.env.TINY_TSUP_ENV === 'production'
/** 相对 `CLI` 工程目录解析路径 */
const pathJoinFromCLI = (...args: string[]) => {
const cliDir = path.resolve(dirname, '../../', isCLIProduction ? '../' : '')
return path.join(cliDir, ...args)
}
/** 相对 `CLI` 入口文件解析目录 */
const pathJoinFromCLIEntry = (...args: string[]) => {
return path.join(dirname, '../', ...args)
}
/** 模板所在路径 */
const templatePath = isCLIProduction ? pathJoinFromCLIEntry('./template') : pathJoinFromCLI('./public/template')
export {
assetsPath,
capitalize,
@ -517,4 +534,7 @@ export {
getBuildTag,
getVueVersion,
pathFromWorkspaceRoot,
pathJoinFromCLI,
pathJoinFromCLIEntry,
templatePath,
}

View File

@ -9,7 +9,10 @@ const shared: Options = {
target: 'node14',
platform: 'node',
dts: false,
publicDir: true
publicDir: true,
env: {
TINY_TSUP_ENV: 'production'
}
}
export default defineConfig([