lvyjs 0.2.24 → 0.3.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/index.js +141 -49
- package/lib/assets/236e80b2c76c39f6fcf00d05ec8357c2.css +35 -0
- package/lib/assets/60a108ca45b93041a762af82a920c63c.css +14 -0
- package/lib/assets/dcb865bb1e44e5f95ecec3cb7290cfb7.css +30 -0
- package/lib/assets/ff44ec490241107927aa7b6853fdb1fb.css +55 -0
- package/lib/content.js +2 -2
- package/lib/main.js +24 -4
- package/lib/postcss.js +9 -9
- package/lib/readConfig.d.ts +2 -0
- package/lib/readConfig.js +69 -0
- package/lib/start.js +1 -56
- package/package.json +7 -3
- package/lib/config.d.ts +0 -12
- package/lib/index.d.ts +0 -3
- package/lib/rullup/index.d.ts +0 -17
- package/lib/store.d.ts +0 -92
- package/lib/typing.d.ts +0 -6
package/bin/index.js
CHANGED
|
@@ -3,61 +3,147 @@
|
|
|
3
3
|
import { fork } from 'child_process'
|
|
4
4
|
import { join, dirname, relative } from 'path'
|
|
5
5
|
import { fileURLToPath } from 'node:url'
|
|
6
|
-
import { createRequire } from 'node:module'
|
|
7
6
|
const args = [...process.argv.slice(2)]
|
|
8
7
|
const currentFilePath = fileURLToPath(import.meta.url)
|
|
9
8
|
const currentDirPath = dirname(currentFilePath)
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
...process.execArgv,
|
|
24
|
-
'--require',
|
|
25
|
-
require.resolve('tsx/preflight'),
|
|
26
|
-
'--import',
|
|
27
|
-
require.resolve('tsx')
|
|
28
|
-
],
|
|
29
|
-
env: Object.assign({}, process.env, {
|
|
30
|
-
PKG_DIR: pkgFilr
|
|
31
|
-
}),
|
|
32
|
-
shell: process.platform === 'win32'
|
|
33
|
-
})
|
|
34
|
-
if (msg.error) {
|
|
35
|
-
console.error(msg.error)
|
|
36
|
-
process.exit()
|
|
9
|
+
const indexJavaScriptDir = join(currentDirPath, '../lib/index.js')
|
|
10
|
+
const readConfigJavaScriptDir = relative(
|
|
11
|
+
process.cwd(),
|
|
12
|
+
join(currentDirPath, '../lib/readConfig.js')
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
const mode = args[0]
|
|
16
|
+
|
|
17
|
+
const dev = () => {
|
|
18
|
+
const indexFileDir = args[0]
|
|
19
|
+
if (!indexFileDir) {
|
|
20
|
+
console.error('[lvyjs] 请指定入口文件')
|
|
21
|
+
process.exit(1)
|
|
37
22
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
23
|
+
|
|
24
|
+
let devProcess = null
|
|
25
|
+
let pendingRestart = false // 标记是否有重启 pending
|
|
26
|
+
|
|
27
|
+
// 启动开发进程
|
|
28
|
+
const startDevProcess = data => {
|
|
29
|
+
// 如果正在等待重启,先不启动
|
|
30
|
+
if (pendingRestart) return
|
|
31
|
+
const envConfig = data?.env || {}
|
|
32
|
+
// 前面1个被占用,剩余参数
|
|
33
|
+
const restArgs = args.slice(1)
|
|
34
|
+
devProcess = fork(indexFileDir, restArgs, {
|
|
35
|
+
stdio: 'inherit',
|
|
36
|
+
execArgv: [
|
|
37
|
+
...process.execArgv,
|
|
38
|
+
'--require',
|
|
39
|
+
'tsx/preflight',
|
|
40
|
+
'--import',
|
|
41
|
+
'tsx',
|
|
42
|
+
'--import',
|
|
43
|
+
'lvyjs/register'
|
|
44
|
+
],
|
|
45
|
+
env: {
|
|
46
|
+
...process.env,
|
|
47
|
+
...envConfig,
|
|
48
|
+
__LVYJS_REGISTER_CONFIG: JSON.stringify(data) // 传递配置给子进程
|
|
49
|
+
},
|
|
50
|
+
shell: process.platform === 'win32'
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
// 监听错误
|
|
54
|
+
devProcess.on('error', err => {
|
|
55
|
+
console.error('[lvyjs] 开发进程错误:', err)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
// 进程退出时清空引用
|
|
59
|
+
devProcess.on('exit', (code, signal) => {
|
|
60
|
+
console.info(`[lvyjs] 开发进程退出 (${code || signal})`)
|
|
61
|
+
devProcess = null
|
|
62
|
+
|
|
63
|
+
// 如果是异常退出,可以尝试重启
|
|
64
|
+
if (code !== 0 && !pendingRestart) {
|
|
65
|
+
console.info('[lvyjs] 开发进程异常退出,等待配置重新加载...')
|
|
66
|
+
}
|
|
67
|
+
})
|
|
45
68
|
}
|
|
46
|
-
|
|
69
|
+
|
|
70
|
+
// 优雅重启开发进程
|
|
71
|
+
const restartDevProcess = newConfig => {
|
|
72
|
+
if (!devProcess) {
|
|
73
|
+
// 没有运行中的进程,直接启动
|
|
74
|
+
startDevProcess(newConfig)
|
|
75
|
+
return
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
pendingRestart = true
|
|
79
|
+
console.info('[lvyjs] 配置已更新,正在重启开发进程...')
|
|
80
|
+
|
|
81
|
+
// 监听退出事件,确保旧进程完全结束后再启动新进程
|
|
82
|
+
devProcess.once('exit', () => {
|
|
83
|
+
pendingRestart = false
|
|
84
|
+
startDevProcess(newConfig)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
// 发送终止信号
|
|
88
|
+
devProcess.kill('SIGTERM')
|
|
89
|
+
|
|
90
|
+
// 超时保护:如果 5 秒后还没退出,强制杀掉
|
|
91
|
+
setTimeout(() => {
|
|
92
|
+
if (devProcess && !devProcess.killed) {
|
|
93
|
+
console.info('[lvyjs] 开发进程无响应,强制终止')
|
|
94
|
+
devProcess.kill('SIGKILL')
|
|
95
|
+
}
|
|
96
|
+
}, 5000)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// 启动配置进程
|
|
100
|
+
const readConfigFork = fork(readConfigJavaScriptDir, [], {
|
|
101
|
+
// stdio: 'inherit',
|
|
102
|
+
execArgv: [...process.execArgv, '--require', 'tsx/preflight', '--import', 'tsx'],
|
|
103
|
+
env: Object.assign({}, process.env, {}),
|
|
104
|
+
shell: process.platform === 'win32'
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
readConfigFork.on('message', msg => {
|
|
108
|
+
if (msg.error) {
|
|
109
|
+
console.error('[lvyjs] 配置进程错误:', msg.error)
|
|
110
|
+
process.exit(1)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (msg.type === 'configReady') {
|
|
114
|
+
restartDevProcess(msg.payload.data)
|
|
115
|
+
}
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
readConfigFork.on('error', error => {
|
|
119
|
+
console.error('[lvyjs] 读取配置文件时发生错误:', error)
|
|
120
|
+
process.exit(1)
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
// 配置进程意外退出
|
|
124
|
+
readConfigFork.on('exit', code => {
|
|
125
|
+
if (code !== 0) {
|
|
126
|
+
console.error(`[lvyjs] 配置进程意外退出 (${code})`)
|
|
127
|
+
process.exit(1)
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
// 处理主进程退出
|
|
132
|
+
process.on('SIGINT', () => {
|
|
133
|
+
console.log('\n[lvyjs] 正在退出...')
|
|
134
|
+
if (devProcess) devProcess.kill()
|
|
135
|
+
if (readConfigFork) readConfigFork.kill()
|
|
136
|
+
process.exit(0)
|
|
137
|
+
})
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const build = () => {
|
|
141
|
+
// 剩余参数
|
|
142
|
+
const restArgs = args.slice(1)
|
|
143
|
+
const msg = fork(indexJavaScriptDir, ['--lvy-build', ...restArgs], {
|
|
47
144
|
stdio: 'inherit',
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
...process.execArgv,
|
|
51
|
-
'--require',
|
|
52
|
-
require.resolve('tsx/preflight'),
|
|
53
|
-
'--import',
|
|
54
|
-
require.resolve('tsx'),
|
|
55
|
-
'--import',
|
|
56
|
-
loaderFile
|
|
57
|
-
],
|
|
58
|
-
env: Object.assign({}, process.env, {
|
|
59
|
-
PKG_DIR: pkgFilr
|
|
60
|
-
}),
|
|
145
|
+
execArgv: [...process.execArgv, '--require', 'tsx/preflight', '--import', 'tsx'],
|
|
146
|
+
env: Object.assign({}, process.env, {}),
|
|
61
147
|
shell: process.platform === 'win32'
|
|
62
148
|
})
|
|
63
149
|
if (msg.error) {
|
|
@@ -65,3 +151,9 @@ if (args.includes('build')) {
|
|
|
65
151
|
process.exit()
|
|
66
152
|
}
|
|
67
153
|
}
|
|
154
|
+
|
|
155
|
+
if (mode === 'build') {
|
|
156
|
+
build()
|
|
157
|
+
} else {
|
|
158
|
+
dev()
|
|
159
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
.warning, .error, .success, .message {
|
|
2
|
+
border: 1px solid #ccc;
|
|
3
|
+
padding: 10px;
|
|
4
|
+
color: #333;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.success {
|
|
8
|
+
border-color: green;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.error {
|
|
12
|
+
border-color: red;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.warning {
|
|
16
|
+
border-color: yellow;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.info {
|
|
20
|
+
background: #A9A9A9;
|
|
21
|
+
box-shadow: 0 0 1px rgba(169, 169, 169, 0.25);
|
|
22
|
+
color: #fff;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.alert {
|
|
26
|
+
background: #8B0000;
|
|
27
|
+
box-shadow: 0 0 1px rgba(139, 0, 0, 0.25);
|
|
28
|
+
color: #fff;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.success {
|
|
32
|
+
background: #006400;
|
|
33
|
+
box-shadow: 0 0 1px rgba(0, 100, 0, 0.25);
|
|
34
|
+
color: #fff;
|
|
35
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
.button {
|
|
2
|
+
padding: 10px;
|
|
3
|
+
border-radius: 5px;
|
|
4
|
+
color: white;
|
|
5
|
+
background-color: #3498db;
|
|
6
|
+
}
|
|
7
|
+
.button:hover {
|
|
8
|
+
background-color: #217dbb;
|
|
9
|
+
}
|
|
10
|
+
.nav ul {
|
|
11
|
+
margin: 0;
|
|
12
|
+
padding: 0;
|
|
13
|
+
list-style: none;
|
|
14
|
+
}
|
|
15
|
+
.nav ul li {
|
|
16
|
+
display: inline-block;
|
|
17
|
+
}
|
|
18
|
+
.nav ul li a {
|
|
19
|
+
text-decoration: none;
|
|
20
|
+
color: #3498db;
|
|
21
|
+
}
|
|
22
|
+
.item-3 {
|
|
23
|
+
width: 300px;
|
|
24
|
+
}
|
|
25
|
+
.item-2 {
|
|
26
|
+
width: 200px;
|
|
27
|
+
}
|
|
28
|
+
.item-1 {
|
|
29
|
+
width: 100px;
|
|
30
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
div {
|
|
2
|
+
display: block;
|
|
3
|
+
background: url('/Users/lemonade/Desktop/lvyjs/src/assets/test.jpeg');
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
p {
|
|
7
|
+
padding: 0;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
body {
|
|
11
|
+
margin: 0;
|
|
12
|
+
padding: 0;
|
|
13
|
+
position: absolute;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
%message-shared {
|
|
17
|
+
border: 1px solid #ccc;
|
|
18
|
+
padding: 10px;
|
|
19
|
+
color: #333;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.warning2 {
|
|
23
|
+
@extend %message-shared;
|
|
24
|
+
border-color: yellow;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.warning, .error, .success, .message {
|
|
28
|
+
border: 1px solid #ccc;
|
|
29
|
+
padding: 10px;
|
|
30
|
+
color: #333;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.success {
|
|
34
|
+
border-color: green;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.error {
|
|
38
|
+
border-color: red;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.warning {
|
|
42
|
+
border-color: yellow;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.info {
|
|
46
|
+
background: #a9a9a9;
|
|
47
|
+
box-shadow: 0 0 1px rgba(169, 169, 169, 0.25);
|
|
48
|
+
color: #fff;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.alert {
|
|
52
|
+
background: #8b0000;
|
|
53
|
+
box-shadow: 0 0 1px rgba(139, 0, 0, 0.25);
|
|
54
|
+
color: #fff;
|
|
55
|
+
}
|
package/lib/content.js
CHANGED
|
@@ -3,7 +3,7 @@ import { convertPath } from './config.js';
|
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
4
|
import { dirname, join } from 'path';
|
|
5
5
|
|
|
6
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
const __dirname$1 = dirname(fileURLToPath(import.meta.url));
|
|
7
7
|
/**
|
|
8
8
|
* 生成模块内容
|
|
9
9
|
* @param {string} relativePath 相对路径
|
|
@@ -33,7 +33,7 @@ const chache = {};
|
|
|
33
33
|
const generateCSSModuleContent = (relativePath) => {
|
|
34
34
|
const inputURL = decodeURIComponent(relativePath);
|
|
35
35
|
const fileName = getRandomName(inputURL);
|
|
36
|
-
const outputURL = convertPath(join(__dirname, 'assets', `${fileName}.css`));
|
|
36
|
+
const outputURL = convertPath(join(__dirname$1, 'assets', `${fileName}.css`));
|
|
37
37
|
if (!chache[inputURL]) {
|
|
38
38
|
global.lvyWorkerProt.postMessage({
|
|
39
39
|
type: 'CSS_MODULE_GENERATED',
|
package/lib/main.js
CHANGED
|
@@ -1,13 +1,33 @@
|
|
|
1
|
-
import module from 'node:module';
|
|
1
|
+
import module$1 from 'node:module';
|
|
2
2
|
import { MessageChannel } from 'node:worker_threads';
|
|
3
3
|
import { initConfig } from './store.js';
|
|
4
4
|
import { postCSS } from './postcss.js';
|
|
5
5
|
import { stylesRegExp, assetsRegExp } from './config.js';
|
|
6
6
|
|
|
7
|
-
if (!module.register) {
|
|
7
|
+
if (!module$1.register) {
|
|
8
8
|
throw new Error(`This version of Node.js (${process.version}) does not support module.register(). Please upgrade to Node v18.19 or v20.6 and above.`);
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
if (process.env?.__LVYJS_REGISTER_CONFIG) {
|
|
11
|
+
const configValues = JSON.parse(process.env.__LVYJS_REGISTER_CONFIG);
|
|
12
|
+
// 进行深度转换,将带有 __regexp 标记的对象转换为 RegExp 实例
|
|
13
|
+
const convertConfig = (obj) => {
|
|
14
|
+
if (obj && typeof obj === 'object') {
|
|
15
|
+
if (obj.__regexp) {
|
|
16
|
+
return new RegExp(obj.source, obj.flags);
|
|
17
|
+
}
|
|
18
|
+
const newObj = Array.isArray(obj) ? [] : {};
|
|
19
|
+
for (const key in obj) {
|
|
20
|
+
newObj[key] = convertConfig(obj[key]);
|
|
21
|
+
}
|
|
22
|
+
return newObj;
|
|
23
|
+
}
|
|
24
|
+
return obj;
|
|
25
|
+
};
|
|
26
|
+
global.lvyConfig = convertConfig(configValues);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
await initConfig();
|
|
30
|
+
}
|
|
11
31
|
const { port1, port2 } = new MessageChannel();
|
|
12
32
|
const cache = {};
|
|
13
33
|
port1.on('message', msg => {
|
|
@@ -22,7 +42,7 @@ port1.on('message', msg => {
|
|
|
22
42
|
}
|
|
23
43
|
});
|
|
24
44
|
// port1.unref()
|
|
25
|
-
module.register('./loader.js', {
|
|
45
|
+
module$1.register('./loader.js', {
|
|
26
46
|
parentURL: import.meta.url,
|
|
27
47
|
data: {
|
|
28
48
|
port: port2,
|
package/lib/postcss.js
CHANGED
|
@@ -4,7 +4,7 @@ import { createRequire } from 'module';
|
|
|
4
4
|
import { join, resolve, dirname, isAbsolute } from 'path';
|
|
5
5
|
import { convertPath, createAlias } from './config.js';
|
|
6
6
|
|
|
7
|
-
const require = createRequire(import.meta.url);
|
|
7
|
+
const require$1 = createRequire(import.meta.url);
|
|
8
8
|
const config = {
|
|
9
9
|
css: null,
|
|
10
10
|
sass: null,
|
|
@@ -54,7 +54,7 @@ const loadPostcssConfig = (configPath, typing) => {
|
|
|
54
54
|
if (aliasEntries.length > 0) {
|
|
55
55
|
// 创建 postcss-import 插件并配置别名解析
|
|
56
56
|
try {
|
|
57
|
-
plugins.push(require('postcss-import')({
|
|
57
|
+
plugins.push(require$1('postcss-import')({
|
|
58
58
|
resolve: (id, basedir) => {
|
|
59
59
|
// 检查别名
|
|
60
60
|
for (const entry of aliasEntries) {
|
|
@@ -71,7 +71,7 @@ const loadPostcssConfig = (configPath, typing) => {
|
|
|
71
71
|
console.error(err);
|
|
72
72
|
}
|
|
73
73
|
try {
|
|
74
|
-
plugins.push(require('postcss-url')({
|
|
74
|
+
plugins.push(require$1('postcss-url')({
|
|
75
75
|
url: asset => {
|
|
76
76
|
// 使用 resolve 逻辑处理 URL
|
|
77
77
|
for (const entry of aliasEntries) {
|
|
@@ -89,11 +89,11 @@ const loadPostcssConfig = (configPath, typing) => {
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
for (let i = 2; i < includeKeys.length; i++) {
|
|
92
|
-
plugins.push(require(includeKeys[i])({}));
|
|
92
|
+
plugins.push(require$1(includeKeys[i])({}));
|
|
93
93
|
}
|
|
94
94
|
try {
|
|
95
95
|
if (fs.existsSync(configPath)) {
|
|
96
|
-
const cfg = require(configPath);
|
|
96
|
+
const cfg = require$1(configPath);
|
|
97
97
|
// 添加其他插件
|
|
98
98
|
if (!Array.isArray(cfg.plugins)) {
|
|
99
99
|
const keys = Object.keys(cfg.plugins);
|
|
@@ -102,7 +102,7 @@ const loadPostcssConfig = (configPath, typing) => {
|
|
|
102
102
|
if (includeKeys.includes(key))
|
|
103
103
|
continue;
|
|
104
104
|
const pluginConfig = cfg.plugins[key];
|
|
105
|
-
const plugin = require(key);
|
|
105
|
+
const plugin = require$1(key);
|
|
106
106
|
if (typeof plugin === 'function') {
|
|
107
107
|
plugins.push(plugin(pluginConfig));
|
|
108
108
|
}
|
|
@@ -153,7 +153,7 @@ const postCSS = (inputPath, outputPath) => {
|
|
|
153
153
|
const readAndProcessCSS = async () => {
|
|
154
154
|
let css = '';
|
|
155
155
|
if (typing === 'less') {
|
|
156
|
-
const less = require('less');
|
|
156
|
+
const less = require$1('less');
|
|
157
157
|
const lessResult = await less.render(fs.readFileSync(inputPath, 'utf-8'), {
|
|
158
158
|
filename: inputPath,
|
|
159
159
|
plugins: [LessAliasPlugin(createAlias(global.lvyConfig?.alias))] // 使用插件
|
|
@@ -161,7 +161,7 @@ const postCSS = (inputPath, outputPath) => {
|
|
|
161
161
|
css = lessResult.css;
|
|
162
162
|
}
|
|
163
163
|
else if (typing === 'sass' || typing === 'scss') {
|
|
164
|
-
const sass = require('sass');
|
|
164
|
+
const sass = require$1('sass');
|
|
165
165
|
const sassResult = sass.renderSync({ file: inputPath });
|
|
166
166
|
css = sassResult.css.toString();
|
|
167
167
|
}
|
|
@@ -199,4 +199,4 @@ const postCSS = (inputPath, outputPath) => {
|
|
|
199
199
|
});
|
|
200
200
|
};
|
|
201
201
|
|
|
202
|
-
export {
|
|
202
|
+
export { postCSS };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { existsSync, watch } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import process from 'process';
|
|
4
|
+
|
|
5
|
+
const main = async () => {
|
|
6
|
+
const files = [
|
|
7
|
+
'lvy.config.ts',
|
|
8
|
+
'lvy.config.js',
|
|
9
|
+
'lvy.config.mjs',
|
|
10
|
+
'lvy.config.cjs',
|
|
11
|
+
'lvy.config.tsx'
|
|
12
|
+
];
|
|
13
|
+
let configDir = '';
|
|
14
|
+
for (const file of files) {
|
|
15
|
+
if (existsSync(file)) {
|
|
16
|
+
configDir = file;
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (!configDir) {
|
|
21
|
+
console.warn('[lvyjs] 未找到 lvy.config 文件,使用默认配置');
|
|
22
|
+
// 发送空配置,让主进程用默认值
|
|
23
|
+
process.send?.({
|
|
24
|
+
type: 'configReady',
|
|
25
|
+
payload: { data: {} }
|
|
26
|
+
});
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
// 通知主进程配置已就绪
|
|
30
|
+
const sendConfig = async () => {
|
|
31
|
+
try {
|
|
32
|
+
// 清除缓存
|
|
33
|
+
const configPath = join(process.cwd(), configDir);
|
|
34
|
+
// 动态导入配置
|
|
35
|
+
const v = await import(`file://${configPath}?t=${Date.now()}`);
|
|
36
|
+
const lvyConfig = v.default || v;
|
|
37
|
+
// 序列化配置(处理正则等特殊类型)
|
|
38
|
+
const serializedConfig = JSON.parse(JSON.stringify(lvyConfig, (key, value) => {
|
|
39
|
+
if (value instanceof RegExp) {
|
|
40
|
+
return { __regexp: true, source: value.source, flags: value.flags };
|
|
41
|
+
}
|
|
42
|
+
return value;
|
|
43
|
+
}));
|
|
44
|
+
// 发送给主进程
|
|
45
|
+
process.send?.({
|
|
46
|
+
type: 'configReady',
|
|
47
|
+
payload: { data: serializedConfig }
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
console.error('[lvyjs] 加载配置失败:', err);
|
|
52
|
+
process.send?.({
|
|
53
|
+
type: 'error'
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
// 首次发送
|
|
58
|
+
await sendConfig();
|
|
59
|
+
// 监听文件变化
|
|
60
|
+
watch(process.cwd(), (_event, filename) => {
|
|
61
|
+
if (files.includes(filename)) {
|
|
62
|
+
console.info(`[lvyjs] 配置文件 ${filename} 已变化,重新加载...`);
|
|
63
|
+
sendConfig();
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
// 保持进程运行
|
|
67
|
+
process.on('SIGINT', () => process.exit(0));
|
|
68
|
+
};
|
|
69
|
+
main();
|
package/lib/start.js
CHANGED
|
@@ -1,64 +1,9 @@
|
|
|
1
1
|
import { buildAndRun } from './rullup/index.js';
|
|
2
2
|
import { initConfig } from './store.js';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* @param input
|
|
6
|
-
*/
|
|
7
|
-
const onDev = async () => {
|
|
8
|
-
const apps = [];
|
|
9
|
-
if (Array.isArray(global.lvyConfig?.plugins)) {
|
|
10
|
-
// 修改config
|
|
11
|
-
for (const plugin of global.lvyConfig.plugins) {
|
|
12
|
-
if (!plugin) {
|
|
13
|
-
continue;
|
|
14
|
-
}
|
|
15
|
-
await apps.push(plugin(global.lvyConfig));
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
for (const app of apps) {
|
|
19
|
-
if (!app) {
|
|
20
|
-
continue;
|
|
21
|
-
}
|
|
22
|
-
if (typeof app == 'function') {
|
|
23
|
-
await app(global.lvyConfig);
|
|
24
|
-
}
|
|
25
|
-
else if (typeof app.load == 'function') {
|
|
26
|
-
app.load(global.lvyConfig);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* @param input
|
|
32
|
-
*/
|
|
33
|
-
const onBuild = async () => {
|
|
34
|
-
const apps = [];
|
|
35
|
-
if (Array.isArray(global.lvyConfig?.plugins)) {
|
|
36
|
-
// 修改config
|
|
37
|
-
for (const plugin of global.lvyConfig.plugins) {
|
|
38
|
-
if (!plugin) {
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
await apps.push(plugin(global.lvyConfig));
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
//
|
|
45
|
-
for (const app of apps) {
|
|
46
|
-
if (!app) {
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
if (typeof app != 'function' && typeof app.build == 'function') {
|
|
50
|
-
await app.build(global.lvyConfig);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
4
|
const main = async () => {
|
|
55
|
-
if (process.argv.includes('--lvy-
|
|
56
|
-
await initConfig();
|
|
57
|
-
await onDev();
|
|
58
|
-
}
|
|
59
|
-
else if (process.argv.includes('--lvy-build')) {
|
|
5
|
+
if (process.argv.includes('--lvy-build')) {
|
|
60
6
|
await initConfig();
|
|
61
|
-
await onBuild();
|
|
62
7
|
buildAndRun();
|
|
63
8
|
}
|
|
64
9
|
};
|
package/package.json
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lvyjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0-alpha.0",
|
|
4
4
|
"description": "tsx compile script",
|
|
5
5
|
"author": "lemonade",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"scripts": {
|
|
10
|
-
"build": "node bundle.js"
|
|
10
|
+
"build": "node bundle.js",
|
|
11
|
+
"start": "node lib/index.js",
|
|
12
|
+
"dev": "tsx src/index.ts",
|
|
13
|
+
"dev:watch": "tsx watch src/index.ts"
|
|
11
14
|
},
|
|
12
15
|
"dependencies": {
|
|
13
16
|
"@rollup/plugin-alias": "^5.1.0",
|
|
@@ -16,6 +19,7 @@
|
|
|
16
19
|
"@rollup/plugin-typescript": "^11.1.6",
|
|
17
20
|
"@rollup/pluginutils": "^5.1.3",
|
|
18
21
|
"autoprefixer": "^10.4.20",
|
|
22
|
+
"chokidar": "^3.6.0",
|
|
19
23
|
"postcss": "^8.4.47",
|
|
20
24
|
"postcss-import": "^16.1.0",
|
|
21
25
|
"postcss-url": "^10.1.3",
|
|
@@ -75,4 +79,4 @@
|
|
|
75
79
|
"type": "git",
|
|
76
80
|
"url": "https://github.com/lemonade-lab/lvyjs.git"
|
|
77
81
|
}
|
|
78
|
-
}
|
|
82
|
+
}
|
package/lib/config.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
declare const assetsRegExp: RegExp;
|
|
2
|
-
declare const stylesRegExp: RegExp;
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* @param val
|
|
6
|
-
* @returns
|
|
7
|
-
*/
|
|
8
|
-
declare const createAlias: (val: any) => {};
|
|
9
|
-
declare const isWin32: () => boolean;
|
|
10
|
-
declare const convertPath: (inputPath: string) => string;
|
|
11
|
-
|
|
12
|
-
export { assetsRegExp, convertPath, createAlias, isWin32, stylesRegExp };
|
package/lib/index.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export { Options, PluginsCallBack, PluginsOptions, PluginsValue, defineConfig, getOptions, initConfig } from './store.js';
|
|
2
|
-
export { buildAndRun, buildJS } from './rullup/index.js';
|
|
3
|
-
export { assetsRegExp, convertPath, createAlias, isWin32, stylesRegExp } from './config.js';
|
package/lib/rullup/index.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 打包 JS
|
|
3
|
-
* *** 注意 **
|
|
4
|
-
* 和initConfig配合使用
|
|
5
|
-
* **
|
|
6
|
-
* 确保已经初始化了配置
|
|
7
|
-
* @param inputs
|
|
8
|
-
* @param output
|
|
9
|
-
*/
|
|
10
|
-
declare const buildJS: (inputs: string[]) => Promise<void>;
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
* @param script
|
|
14
|
-
*/
|
|
15
|
-
declare function buildAndRun(): Promise<void>;
|
|
16
|
-
|
|
17
|
-
export { buildAndRun, buildJS };
|
package/lib/store.d.ts
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { RollupCommonJSOptions } from '@rollup/plugin-commonjs';
|
|
2
|
-
import { RollupTypescriptOptions } from '@rollup/plugin-typescript';
|
|
3
|
-
import { RollupOptions, OutputOptions } from 'rollup';
|
|
4
|
-
import { Alias } from './typing.js';
|
|
5
|
-
|
|
6
|
-
type PluginsValue = (options: Options) => void;
|
|
7
|
-
type PluginsCallBack = PluginsValue | {
|
|
8
|
-
load?: PluginsValue;
|
|
9
|
-
build?: PluginsValue;
|
|
10
|
-
};
|
|
11
|
-
type PluginsOptions = (options: Options) => PluginsCallBack | void;
|
|
12
|
-
type Options = {
|
|
13
|
-
env?: {
|
|
14
|
-
[key: string]: string;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* 配置调整机及其回调插件
|
|
18
|
-
*/
|
|
19
|
-
plugins?: PluginsOptions[];
|
|
20
|
-
/**
|
|
21
|
-
* 别名
|
|
22
|
-
*/
|
|
23
|
-
alias?: {
|
|
24
|
-
/**
|
|
25
|
-
* 别名规则
|
|
26
|
-
*/
|
|
27
|
-
entries?: Alias[];
|
|
28
|
-
} | false;
|
|
29
|
-
/**
|
|
30
|
-
* 静态资源识别
|
|
31
|
-
*/
|
|
32
|
-
assets?: {
|
|
33
|
-
/**
|
|
34
|
-
* 过滤得到指定格式的文件识别之为静态资源
|
|
35
|
-
*/
|
|
36
|
-
filter?: RegExp;
|
|
37
|
-
} | false;
|
|
38
|
-
styles?: {
|
|
39
|
-
/**
|
|
40
|
-
* 过滤得到指定格式的文件识别之为静态资源
|
|
41
|
-
*/
|
|
42
|
-
filter?: RegExp;
|
|
43
|
-
} | false;
|
|
44
|
-
/**
|
|
45
|
-
* 打包时配置
|
|
46
|
-
*/
|
|
47
|
-
build?: {
|
|
48
|
-
/**
|
|
49
|
-
* cjs文件处理
|
|
50
|
-
*/
|
|
51
|
-
commonjs?: RollupCommonJSOptions | false;
|
|
52
|
-
/**
|
|
53
|
-
* ts配置
|
|
54
|
-
*/
|
|
55
|
-
typescript?: RollupTypescriptOptions | false;
|
|
56
|
-
/**
|
|
57
|
-
*
|
|
58
|
-
*/
|
|
59
|
-
RollupOptions?: RollupOptions;
|
|
60
|
-
/**
|
|
61
|
-
*
|
|
62
|
-
*/
|
|
63
|
-
OutputOptions?: OutputOptions & {
|
|
64
|
-
/**
|
|
65
|
-
* 默认 src
|
|
66
|
-
*/
|
|
67
|
-
input?: string;
|
|
68
|
-
};
|
|
69
|
-
} | false;
|
|
70
|
-
};
|
|
71
|
-
/**
|
|
72
|
-
*
|
|
73
|
-
*/
|
|
74
|
-
declare global {
|
|
75
|
-
var lvyConfig: Options;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
*
|
|
79
|
-
*/
|
|
80
|
-
declare const initConfig: () => Promise<void>;
|
|
81
|
-
/**
|
|
82
|
-
* @returns
|
|
83
|
-
*/
|
|
84
|
-
declare const getOptions: () => Options;
|
|
85
|
-
/**
|
|
86
|
-
* @param param0
|
|
87
|
-
* @returns
|
|
88
|
-
*/
|
|
89
|
-
declare const defineConfig: (optoins?: Options) => Options | undefined;
|
|
90
|
-
|
|
91
|
-
export { defineConfig, getOptions, initConfig };
|
|
92
|
-
export type { Options, PluginsCallBack, PluginsOptions, PluginsValue };
|