Skip to content

Commit 0708dfb

Browse files
committed
fix(tiny-vue): 内部和开源代码同步,减少维护成本 [WI2023]
Match-id-ff29bb87fa078919ec7b37b0b2d1556776776d01
1 parent 87e8f49 commit 0708dfb

File tree

80 files changed

+8541
-231
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+8541
-231
lines changed

.cid/tiny-vue-renderless.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
version: 0.1.0
2+
name: tiny-vue-renderless
3+
language: nodejs
4+
5+
6+
# 构建工具
7+
dependencies:
8+
base:
9+
nodejs: best
10+
11+
# 构建机器
12+
machine:
13+
standard:
14+
euler:
15+
- default
16+
17+
# 构建脚本
18+
scripts:
19+
- sh build.sh
20+
21+
# 构建产物
22+
artifacts:
23+
npm_deploy:
24+
- config_path: ./package.json
25+
publish_path: ./dist/

.eslintrc

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"comma-dangle": ["off", "always-multiline"],
5555
"semi-style": ["warn", "last"],
5656
"max-lines": ["error", 2000],
57-
"max-lines-per-function": ["error", 200],
57+
"max-lines-per-function": ["warn", 50],
5858
"complexity": ["error", 20],
5959
"max-depth": ["warn", 4],
6060
"max-nested-callbacks": ["error", 4],
@@ -75,8 +75,8 @@
7575
"accessor-pairs": "error",
7676
"no-prototype-builtins": "error",
7777
"guard-for-in": "error",
78-
"eqeqeq": "warn",
79-
"no-negated-condition": "warn",
78+
"eqeqeq": "off",
79+
"no-negated-condition": "off",
8080
"default-case": "off",
8181
"no-fallthrough": "error",
8282
"no-case-declarations": "error",

.husky/_/husky.sh

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env sh
2+
if [ -z "$husky_skip_init" ]; then
3+
debug () {
4+
if [ "$HUSKY_DEBUG" = "1" ]; then
5+
echo "husky (debug) - $1"
6+
fi
7+
}
8+
9+
readonly hook_name="$(basename -- "$0")"
10+
debug "starting $hook_name..."
11+
12+
if [ "$HUSKY" = "0" ]; then
13+
debug "HUSKY env variable is set to 0, skipping hook"
14+
exit 0
15+
fi
16+
17+
if [ -f ~/.huskyrc ]; then
18+
debug "sourcing ~/.huskyrc"
19+
. ~/.huskyrc
20+
fi
21+
22+
readonly husky_skip_init=1
23+
export husky_skip_init
24+
sh -e "$0" "$@"
25+
exitCode="$?"
26+
27+
if [ $exitCode != 0 ]; then
28+
echo "husky - $hook_name hook exited with code $exitCode (error)"
29+
fi
30+
31+
if [ $exitCode = 127 ]; then
32+
echo "husky - command not found in PATH=$PATH"
33+
fi
34+
35+
exit $exitCode
36+
fi

.husky/commit-msg

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4-
yarn commitlint --edit $1
4+
npx --no-install commitlint --edit

build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
if [ ! $version ];
33
then npm version 0.1.0-`date "+%Y%m%d%H%M%S"`;
4-
else npm version ${version};
4+
else npm version $version;
55
fi
66

77
npm install

build/build-version.js

+3-9
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,14 @@ const utils = require('./utils')
88

99
const RUNTIME_VERSION = 'process.env.RUNTIME_VERSION'
1010
const BASE_RUNTIME_PATH = path.join(__dirname, '..', 'dist', 'common')
11-
const RENDERLESS_VERSION = fs.readJsonSync(
12-
path.join(__dirname, '../package.json')
13-
).version
14-
15-
;['index.js', 'runtime.js'].forEach((fileName) => {
11+
const RENDERLESS_VERSION = fs.readJsonSync(path.join(__dirname, '../package.json')).version;
12+
['index.js', 'runtime.js'].forEach((fileName) => {
1613
const fullPath = path.join(BASE_RUNTIME_PATH, fileName)
1714

1815
if (fs.existsSync(fullPath)) {
1916
let scriptContent = fs.readFileSync(fullPath).toString('UTF-8')
2017

21-
scriptContent = scriptContent.replace(
22-
RUNTIME_VERSION,
23-
`'${RENDERLESS_VERSION}'`
24-
)
18+
scriptContent = scriptContent.replace(RUNTIME_VERSION, `'${RENDERLESS_VERSION}'`)
2519

2620
fs.writeFileSync(fullPath, scriptContent)
2721
}

build/create-ui.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ const createRenderLessIndex = ({ libName }) => {
1717
`
1818
const output = utils.prettierFormat({ str: template })
1919

20-
writeFileSync(
21-
utils.mkdirByPathSync(utils.pathJoin('..', 'src', libName, 'index.js')),
22-
output
23-
)
20+
writeFileSync(utils.mkdirByPathSync(utils.pathJoin('..', 'src', libName, 'index.js')), output)
2421
}
2522

2623
/**
@@ -62,10 +59,7 @@ const createRenderLessValue = ({ libName }) => {
6259
options: { printWidth: 1000 }
6360
})
6461

65-
writeFileSync(
66-
utils.mkdirByPathSync(utils.pathJoin('..', 'src', libName, 'vue.js')),
67-
output
68-
)
62+
writeFileSync(utils.mkdirByPathSync(utils.pathJoin('..', 'src', libName, 'vue.js')), output)
6963
}
7064

7165
if (args.length > 0) {

build/test-unit.js

+5-21
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
const { sep, join } = require('path')
22
const { existsSync, statSync } = require('fs-extra')
3-
const {
4-
getInputCmd,
5-
execCmd,
6-
kebabCase,
7-
logGreen,
8-
walkFileTree,
9-
logRed
10-
} = require('./utils')
3+
const { getInputCmd, execCmd, kebabCase, logGreen, walkFileTree, logRed } = require('./utils')
114

125
/**
136
* 快捷测试命令,支持单组件、多组件以都号分割、文件夹(非深度遍历)
@@ -49,21 +42,16 @@ for (let i = 0, len = uiNames.length; i < len; i++) {
4942
callback: (file, subPath) => {
5043
if (file.indexOf(specSuffixes) > -1) {
5144
const rootPart = sep + fileName + sep
52-
const newPathPart = subPath
53-
.substring(subPath.indexOf(rootPart) + rootPart.length - 1)
54-
.replace(sep, '/')
45+
const newPathPart = subPath.substring(subPath.indexOf(rootPart) + rootPart.length - 1).replace(sep, '/')
5546
const matchPath = testPath + newPathPart
5647

57-
!uiMatchs.includes(matchPath) &&
58-
uiMatchs.push(testPath + newPathPart)
48+
!uiMatchs.includes(matchPath) && uiMatchs.push(testPath + newPathPart)
5949
}
6050
}
6151
})
6252
} else {
6353
const matchPath = testPath + specSuffixes
64-
existsSync(testPathLink + specSuffixes) &&
65-
!uiMatchs.includes(matchPath) &&
66-
uiMatchs.push(testPath + specSuffixes)
54+
existsSync(testPathLink + specSuffixes) && !uiMatchs.includes(matchPath) && uiMatchs.push(testPath + specSuffixes)
6755
}
6856
} else {
6957
uiMatchs.length = 1
@@ -99,9 +87,5 @@ if (cmdStr) {
9987
e
10088
}
10189
} else {
102-
logRed(
103-
`Enter the file or folder : ${uiNames.join(
104-
','
105-
)} is not exist , please enter valid name.`
106-
)
90+
logRed(`Enter the file or folder : ${uiNames.join(',')} is not exist , please enter valid name.`)
10791
}

build/utils.js

+19-34
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,26 @@ const logger = () => {}
1010
* 根据运行上下文获取路径(运行时打包用)
1111
* @returns 文件绝对路径
1212
*/
13-
const resolveCwd = (...args) => {
14-
return path.join(process.cwd(), ...args)
15-
}
13+
const resolveCwd = (...args) => path.join(process.cwd(), ...args)
1614

1715
/**
1816
* 获取模板替换路径(动态)
1917
* @param {String} posixPath 路径
2018
* @returns 文件绝对路径
2119
*/
22-
const assetsPath = (posixPath) => {
23-
return path.posix.join('static', posixPath)
24-
}
20+
const assetsPath = (posixPath) => path.posix.join('static', posixPath)
2521

2622
/**
2723
* 根据运行上下文获取,当前运行组件的名称
2824
* @returns 当前运行组件目录名称
2925
*/
30-
const getComponentName = () => {
31-
return process.cwd().split(path.sep).pop()
32-
}
26+
const getComponentName = () => process.cwd().split(path.sep).pop()
3327

3428
/**
3529
* 获取当前上下文的路径
3630
* @returns 文件绝对路径
3731
*/
38-
const pathJoin = (...args) => {
39-
return path.join(__dirname, ...args)
40-
}
32+
const pathJoin = (...args) => path.join(__dirname, ...args)
4133

4234
/**
4335
* 获取用户输入命令参数
@@ -69,11 +61,7 @@ const execCmd = (cmdStr) => {
6961
* @param {String} str 字符串
7062
* @returns 字符串
7163
*/
72-
const capitalize = (str) => {
73-
return typeof str === 'string'
74-
? str.slice(0, 1).toUpperCase() + str.slice(1)
75-
: str
76-
}
64+
const capitalize = (str) => (typeof str === 'string' ? str.slice(0, 1).toUpperCase() + str.slice(1) : str)
7765

7866
/**
7967
* @description 将驼峰字符串转化为以指定字符分割的小写字符串
@@ -84,18 +72,20 @@ const capitalize = (str) => {
8472
* @param splitChar 分隔符
8573
*/
8674
const kebabCase = ({ str, splitChar = '-' }) => {
87-
if (!str || typeof str !== 'string') return str
75+
if (!str || typeof str !== 'string') {
76+
return str
77+
}
8878

8979
return str
9080
.split('')
9181
.map((char, index) => {
9282
const charCod = char.charCodeAt(0)
9383

94-
if (charCod < 65 || charCod > 122) return char
84+
if (charCod < 65 || charCod > 122) {
85+
return char
86+
}
9587

96-
return (charCod >= 65 && charCod) <= 90
97-
? (index !== 0 ? splitChar : '') + char.toLowerCase()
98-
: char
88+
return (charCod >= 65 && charCod) <= 90 ? (index !== 0 ? splitChar : '') + char.toLowerCase() : char
9989
})
10090
.join('')
10191
}
@@ -104,11 +94,7 @@ const kebabCase = ({ str, splitChar = '-' }) => {
10494
* 根据文件路径判断是否为文件,未创建的文件路径
10595
* @param {String} pathLink 文件路径
10696
*/
107-
const isVirtualFile = (pathLink) => {
108-
return ['.js', '.css', '.json', '.vue', '.log', '.md'].some(
109-
(item) => pathLink.lastIndexOf(item) > pathLink.length - 5
110-
)
111-
}
97+
const isVirtualFile = (pathLink) => ['.js', '.css', '.json', '.vue', '.log', '.md'].some((item) => pathLink.lastIndexOf(item) > pathLink.length - 5)
11298

11399
/**
114100
* 根据文件 url 创建对应的文件夹
@@ -154,11 +140,11 @@ const rmdirAll = (targetDir) => {
154140
* @param {Function} callback 遍历回调
155141
*/
156142
const walkFileTree = ({ dirPath, isDeep = false, callback }) => {
157-
if (!dirPath || typeof callback !== 'function') return
143+
if (!dirPath || typeof callback !== 'function') {
144+
return
145+
}
158146

159-
const dirs = fs.readdirSync(
160-
path.isAbsolute(dirPath) ? dirPath : path.join(__dirname, dirPath)
161-
)
147+
const dirs = fs.readdirSync(path.isAbsolute(dirPath) ? dirPath : path.join(__dirname, dirPath))
162148

163149
if (Array.isArray(dirs) && dirs.length > 0) {
164150
dirs.forEach((file) => {
@@ -214,8 +200,8 @@ const logRed = (str) => {
214200
* @param {String} str 格式字符
215201
* @param {Object} options 格式字符
216202
*/
217-
const prettierFormat = ({ str, options = {} }) => {
218-
return require('prettier').format(str, {
203+
const prettierFormat = ({ str, options = {} }) =>
204+
require('prettier').format(str, {
219205
printWidth: 100,
220206
jsxBracketSameLine: false,
221207
tabWidth: 2,
@@ -227,7 +213,6 @@ const prettierFormat = ({ str, options = {} }) => {
227213
parser: 'babel',
228214
...options
229215
})
230-
}
231216

232217
module.exports = {
233218
logRed,

0 commit comments

Comments
 (0)