lvyjs 0.0.1 → 0.0.2
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/README.md +41 -1
- package/bin/index.js +1 -16
- package/lib/index.js +33 -44
- package/lib/store.d.ts +27 -27
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,3 +1,43 @@
|
|
|
1
1
|
# LVY
|
|
2
2
|
|
|
3
|
-
一款为 node 构建的开发工具
|
|
3
|
+
长春藤。 一款为 node 构建的开发工具
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install lvyjs -D
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
// lvy.config.ts
|
|
11
|
+
import { defineConfig } from 'lvyjs'
|
|
12
|
+
import { alias, files } from 'lvyjs/plugins'
|
|
13
|
+
import { fileURLToPath } from 'url'
|
|
14
|
+
import { dirname, join } from 'path'
|
|
15
|
+
const __filename = fileURLToPath(import.meta.url)
|
|
16
|
+
const __dirname = dirname(__filename)
|
|
17
|
+
export default defineConfig({
|
|
18
|
+
plugins: [
|
|
19
|
+
{
|
|
20
|
+
name: 'my-app',
|
|
21
|
+
callback: () => {
|
|
22
|
+
// 要执行的会调函数
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
],
|
|
26
|
+
build: {
|
|
27
|
+
plugins: [
|
|
28
|
+
alias({
|
|
29
|
+
entries: [{ find: '@src', replacement: join(__dirname, 'src') }]
|
|
30
|
+
}),
|
|
31
|
+
files({ filter: /\.(png|jpg)$/ })
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
npx lvy dev
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
npx lvy build
|
|
43
|
+
```
|
package/bin/index.js
CHANGED
|
@@ -7,22 +7,7 @@ const currentFilePath = fileURLToPath(import.meta.url)
|
|
|
7
7
|
const currentDirPath = dirname(currentFilePath)
|
|
8
8
|
const pkgFilr = join(currentDirPath, '../package.json')
|
|
9
9
|
// 启动模式
|
|
10
|
-
if (args.includes('
|
|
11
|
-
const jsFile = join(currentDirPath, '../lib/index.js')
|
|
12
|
-
const jsdir = relative(process.cwd(), jsFile)
|
|
13
|
-
const argsx = args.filter(arg => arg !== 'start')
|
|
14
|
-
const msg = spawn('node', [jsdir, '--lvy-start', ...argsx], {
|
|
15
|
-
stdio: 'inherit',
|
|
16
|
-
env: Object.assign({}, process.env, {
|
|
17
|
-
PKG_DIR: pkgFilr
|
|
18
|
-
}),
|
|
19
|
-
shell: process.platform === 'win32'
|
|
20
|
-
})
|
|
21
|
-
if (msg.error) {
|
|
22
|
-
console.error(msg.error)
|
|
23
|
-
process.exit()
|
|
24
|
-
}
|
|
25
|
-
} else if (args.includes('build')) {
|
|
10
|
+
if (args.includes('build')) {
|
|
26
11
|
const jsFile = join(currentDirPath, '../lib/index.js')
|
|
27
12
|
const jsdir = relative(process.cwd(), jsFile)
|
|
28
13
|
const argsx = args.filter(arg => arg !== 'build')
|
package/lib/index.js
CHANGED
|
@@ -1,57 +1,46 @@
|
|
|
1
|
-
import { buildAndRun } from './build/rullup.js'
|
|
2
|
-
import { initConfig } from './store.js'
|
|
3
|
-
export { defineConfig } from './store.js'
|
|
1
|
+
import { buildAndRun } from './build/rullup.js'
|
|
2
|
+
import { initConfig } from './store.js'
|
|
3
|
+
export { defineConfig } from './store.js'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @param input
|
|
7
7
|
*/
|
|
8
8
|
const onDev = async () => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
apps.push(plugin);
|
|
9
|
+
const apps = []
|
|
10
|
+
// 修改config
|
|
11
|
+
for (const plugin of global.lvyConfig.plugins) {
|
|
12
|
+
if (plugin?.config) {
|
|
13
|
+
const cfg = await plugin.config(global.lvyConfig)
|
|
14
|
+
global.lvyConfig = {
|
|
15
|
+
...global.lvyConfig,
|
|
16
|
+
...cfg
|
|
17
|
+
}
|
|
20
18
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
19
|
+
apps.push(plugin)
|
|
20
|
+
}
|
|
21
|
+
// 执行loader
|
|
22
|
+
await import('./loader/main.js')
|
|
23
|
+
// 执行callback
|
|
24
|
+
for (const app of apps) {
|
|
25
|
+
if (app?.callback) await app.callback()
|
|
26
|
+
}
|
|
27
|
+
}
|
|
29
28
|
/**
|
|
30
29
|
*
|
|
31
30
|
* @param input
|
|
32
31
|
* @param ouput
|
|
33
32
|
*/
|
|
34
33
|
const onBuild = () => {
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
*
|
|
39
|
-
*/
|
|
40
|
-
const onStart = async () => {
|
|
41
|
-
// 运行模式
|
|
42
|
-
console.log('暂不支持');
|
|
43
|
-
};
|
|
34
|
+
buildAndRun('src', 'lib')
|
|
35
|
+
}
|
|
36
|
+
|
|
44
37
|
const main = async () => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
onStart();
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
main();
|
|
38
|
+
if (process.argv.includes('--lvy-dev')) {
|
|
39
|
+
await initConfig()
|
|
40
|
+
onDev()
|
|
41
|
+
} else if (process.argv.includes('--lvy-build')) {
|
|
42
|
+
await initConfig()
|
|
43
|
+
onBuild()
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
main()
|
package/lib/store.d.ts
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
import { RollupOptions } from 'rollup'
|
|
1
|
+
import { RollupOptions } from 'rollup'
|
|
2
2
|
|
|
3
3
|
type Options = {
|
|
4
|
+
plugins?: {
|
|
5
|
+
name: string
|
|
6
|
+
/**
|
|
7
|
+
* ⚠️直接optoins进行调整
|
|
8
|
+
* @param options
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
config?: (options: Options) => Options
|
|
12
|
+
/**
|
|
13
|
+
* 执行
|
|
14
|
+
*/
|
|
15
|
+
callback?: () => void
|
|
16
|
+
}[]
|
|
17
|
+
build?: {
|
|
4
18
|
plugins?: {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
*/
|
|
15
|
-
callback?: () => void;
|
|
16
|
-
}[];
|
|
17
|
-
build?: {
|
|
18
|
-
plugins?: {
|
|
19
|
-
belong: 'rollup' | 'esbuild' | 'other';
|
|
20
|
-
name: string;
|
|
21
|
-
load: any;
|
|
22
|
-
}[];
|
|
23
|
-
rollupOptions?: {
|
|
24
|
-
input?: string | string[];
|
|
25
|
-
} & RollupOptions;
|
|
26
|
-
};
|
|
27
|
-
};
|
|
19
|
+
belong: 'rollup' | 'esbuild' | 'other'
|
|
20
|
+
name: string
|
|
21
|
+
load: any
|
|
22
|
+
}[]
|
|
23
|
+
rollupOptions?: {
|
|
24
|
+
input?: string | string[]
|
|
25
|
+
} & RollupOptions
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
28
|
/**
|
|
29
29
|
*
|
|
30
30
|
*/
|
|
31
31
|
declare global {
|
|
32
|
-
|
|
32
|
+
var lvyConfig: Options
|
|
33
33
|
}
|
|
34
34
|
/**
|
|
35
35
|
* @param param0
|
|
36
36
|
* @returns
|
|
37
37
|
*/
|
|
38
|
-
declare const defineConfig: (optoins?: Options) => Options
|
|
38
|
+
declare const defineConfig: (optoins?: Options) => Options
|
|
39
39
|
|
|
40
|
-
export { type Options, defineConfig }
|
|
40
|
+
export { type Options, defineConfig }
|