lvyjs 0.2.8 → 0.2.10

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/lib/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { Options, defineConfig, getOptions, initConfig, usePlugin } from './store.js';
1
+ export { Options, PluginsCallBack, PluginsOptions, PluginsValue, defineConfig, getOptions, initConfig } from './store.js';
2
2
  export { buildAndRun, buildJS } from './rullup/index.js';
3
3
  export { assetsRegExp, convertPath, createAlias, isWin32, stylesRegExp } from './config.js';
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { buildAndRun } from './rullup/index.js';
2
2
  export { buildJS } from './rullup/index.js';
3
3
  import { initConfig } from './store.js';
4
- export { defineConfig, getOptions, usePlugin } from './store.js';
4
+ export { defineConfig, getOptions } from './store.js';
5
5
  export { assetsRegExp, convertPath, createAlias, isWin32, stylesRegExp } from './config.js';
6
6
 
7
7
  /**
@@ -15,7 +15,7 @@ const onDev = async () => {
15
15
  if (!plugin) {
16
16
  continue;
17
17
  }
18
- apps.push(plugin(global.lvyConfig));
18
+ await apps.push(plugin(global.lvyConfig));
19
19
  }
20
20
  }
21
21
  // 执行loader
@@ -25,17 +25,46 @@ const onDev = async () => {
25
25
  if (!app) {
26
26
  continue;
27
27
  }
28
- if (typeof app == 'function')
29
- app(global.lvyConfig);
28
+ if (typeof app == 'function') {
29
+ await app(global.lvyConfig);
30
+ }
31
+ else if (typeof app.load == 'function') {
32
+ app.load(global.lvyConfig);
33
+ }
34
+ }
35
+ };
36
+ /**
37
+ * @param input
38
+ */
39
+ const onBuild = async () => {
40
+ const apps = [];
41
+ if (Array.isArray(global.lvyConfig?.plugins)) {
42
+ // 修改config
43
+ for (const plugin of global.lvyConfig.plugins) {
44
+ if (!plugin) {
45
+ continue;
46
+ }
47
+ await apps.push(plugin(global.lvyConfig));
48
+ }
49
+ }
50
+ //
51
+ for (const app of apps) {
52
+ if (!app) {
53
+ continue;
54
+ }
55
+ if (typeof app != 'function' && typeof app.build == 'function') {
56
+ await app.build(global.lvyConfig);
57
+ }
30
58
  }
31
59
  };
32
60
  const main = async () => {
33
61
  if (process.argv.includes('--lvy-dev')) {
34
62
  await initConfig();
35
- onDev();
63
+ await onDev();
36
64
  }
37
65
  else if (process.argv.includes('--lvy-build')) {
38
66
  await initConfig();
67
+ await onBuild();
39
68
  buildAndRun();
40
69
  }
41
70
  };
package/lib/store.d.ts CHANGED
@@ -3,11 +3,17 @@ import { RollupTypescriptOptions } from '@rollup/plugin-typescript';
3
3
  import { RollupOptions, OutputOptions } from 'rollup';
4
4
  import { Alias } from './typing.js';
5
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);
6
12
  type Options = {
7
13
  /**
8
14
  * 配置调整机及其回调插件
9
15
  */
10
- plugins?: ((options: Options) => ((options: Options) => void) | void | undefined | null)[];
16
+ plugins?: PluginsOptions[];
11
17
  /**
12
18
  * 别名
13
19
  */
@@ -59,12 +65,6 @@ type Options = {
59
65
  };
60
66
  } | false;
61
67
  };
62
- /**
63
- *
64
- * @param options
65
- * @returns
66
- */
67
- declare const usePlugin: (load: (options: Options) => ((options: Options) => void) | void | undefined | null) => (options: Options) => ((options: Options) => void) | void | undefined | null;
68
68
  /**
69
69
  *
70
70
  */
@@ -85,4 +85,4 @@ declare const getOptions: () => Options;
85
85
  */
86
86
  declare const defineConfig: (optoins?: Options) => Options | undefined;
87
87
 
88
- export { type Options, defineConfig, getOptions, initConfig, usePlugin };
88
+ export { type Options, type PluginsCallBack, type PluginsOptions, type PluginsValue, defineConfig, getOptions, initConfig };
package/lib/store.js CHANGED
@@ -1,12 +1,6 @@
1
1
  import { existsSync } from 'fs';
2
2
  import { join } from 'path';
3
3
 
4
- /**
5
- *
6
- * @param options
7
- * @returns
8
- */
9
- const usePlugin = (load) => load;
10
4
  /**
11
5
  *
12
6
  */
@@ -44,4 +38,4 @@ const getOptions = () => global.lvyConfig;
44
38
  */
45
39
  const defineConfig = (optoins) => optoins;
46
40
 
47
- export { defineConfig, getOptions, initConfig, usePlugin };
41
+ export { defineConfig, getOptions, initConfig };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lvyjs",
3
- "version": "0.2.8",
3
+ "version": "0.2.10",
4
4
  "description": "tsx compile script",
5
5
  "author": "lemonade",
6
6
  "license": "MIT",
@@ -1,54 +0,0 @@
1
- import { join } from 'path'
2
- import crypto from 'node:crypto'
3
-
4
- /**
5
- * @param inputPath
6
- * @returns
7
- */
8
- const convertPath = inputPath => {
9
- return ['win32'].includes(process.platform) ? inputPath : inputPath.replace(/\\/g, '/')
10
- }
11
- /**
12
- * 生成模块内容
13
- * @param {string} relativePath 相对路径
14
- */
15
- const generateModuleContent = relativePath => {
16
- const contents = [
17
- `const reg = ['win32'].includes(process.platform) ? /^file:\\/\\/\\// : /^file:\\/\\// ;`,
18
- `const fileUrl = import.meta.resolve('${convertPath(relativePath)}').replace(reg, '');`,
19
- 'export default fileUrl;'
20
- ].join('\n')
21
- return contents
22
- }
23
- const getRandomName = str => {
24
- // 使用 MD5 算法创建哈希对象
25
- const hash = crypto.createHash('md5')
26
- // 更新哈希对象内容
27
- hash.update(str)
28
- return hash.digest('hex')
29
- }
30
- const chache = {}
31
- /**
32
- *
33
- * @param fileUrl
34
- * @returns
35
- */
36
- const generateCSSModuleContent = pathURL => {
37
- const fileName = getRandomName(pathURL)
38
- const outputFileURL = convertPath(
39
- join(process.cwd(), 'node_modules', 'lvyjs', 'assets', `${fileName}.css`)
40
- )
41
- if (!chache[pathURL]) {
42
- global.lvyWorkerProt.postMessage({
43
- type: 'CSS_MODULE_GENERATED',
44
- payload: {
45
- from: pathURL,
46
- to: outputFileURL
47
- }
48
- })
49
- chache[pathURL] = true
50
- }
51
- return `export default "${outputFileURL}";`
52
- }
53
-
54
- export { generateCSSModuleContent, generateModuleContent }
package/lib/server.js DELETED
@@ -1,11 +0,0 @@
1
- import Koa from 'koa'
2
- import KoaStatic from 'koa-static'
3
-
4
- const app = new Koa()
5
- // 使用 koa-static 中间件来提供静态文件
6
- app.use(KoaStatic(process.cwd()))
7
- // 设定端口并启动服务器
8
- const PORT = 8989
9
- app.listen(8989, () => {
10
- console.log(`Server running at http://localhost:${PORT}`)
11
- })