@ray-js/cli 0.7.1-beta-1 → 0.7.3-beta-1

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/ray-build.js CHANGED
@@ -15,7 +15,6 @@ program
15
15
  .option('--type <type>', '构建类型 eg: app | component', 'app')
16
16
  .option('--transform-mode <mode>', '组件转换类型 eg: auto | pure', 'pure')
17
17
  .option('--debug', '开启运行时日志', false)
18
- .option('--max-workers <workers>', 'RN打包的max-workers')
19
18
  .action(function (cwd = '', options) {
20
19
  log.verbose('cli', options)
21
20
  if (options.target === 'tuya') {
@@ -26,10 +25,11 @@ program
26
25
  NODE_ENV: 'production',
27
26
  PLATFORM: options.target,
28
27
  REMAX_PLATFORM: options.target,
29
- REMAX_DEBUG: JSON.stringify(options.debug),
30
- TUYA_DEVTOOLS: JSON.stringify('false'),
28
+ REMAX_DEBUG: options.debug,
31
29
  })
32
- const finalCwd = path.join(process.cwd(), cwd)
33
- require('../lib/build').default({ cwd: finalCwd, ...options, mode: process.env.NODE_ENV })
30
+ cwd = path.join(process.cwd(), cwd)
31
+ const devtools = process.env.TUYA_DEVTOOLS !== undefined
32
+ const mode = process.env.NODE_ENV
33
+ require('../lib/build').default({ ...options, cwd, mode, devtools })
34
34
  })
35
35
  .parse(process.argv)
package/bin/ray-start.js CHANGED
@@ -26,10 +26,11 @@ program
26
26
  NODE_ENV: 'development',
27
27
  PLATFORM: options.target,
28
28
  REMAX_PLATFORM: options.target, // @ray-core/ray/one 依赖此环境变量
29
- REMAX_DEBUG: JSON.stringify(options.debug), // ray 运行时日志
30
- TUYA_DEVTOOLS: JSON.stringify('false'),
29
+ REMAX_DEBUG: options.debug, // ray 运行时日志
31
30
  })
32
- const finalCwd = path.join(process.cwd(), cwd)
33
- require('../lib/start').default({ cwd: finalCwd, ...options, mode: process.env.NODE_ENV })
31
+ cwd = path.join(process.cwd(), cwd)
32
+ const devtools = process.env.TUYA_DEVTOOLS !== undefined
33
+ const mode = process.env.NODE_ENV
34
+ require('../lib/start').default({ ...options, cwd, mode, devtools })
34
35
  })
35
36
  .parse(process.argv)
@@ -1,5 +1,7 @@
1
1
  module.exports = function (opts = {}) {
2
2
  Object.keys(opts).forEach((key) => {
3
- process.env[key] = process.env[key] || opts[key]
3
+ if (opts[key] !== false) {
4
+ process.env[key] = process.env[key] || opts[key]
5
+ }
4
6
  })
5
7
  }
package/lib/API.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import WebpackChain from 'webpack-chain';
2
1
  import { API as IAPI, CliOptions, Plugin, PluginMethods, RayConfig } from '@ray-js/types';
3
2
  /**
4
3
  * 命令行运行容器上下文
@@ -9,11 +8,6 @@ export default class API implements IAPI {
9
8
  options: CliOptions;
10
9
  config: RayConfig;
11
10
  constructor(options: CliOptions);
12
- /**
13
- * 将 ray.config 作用于 webpack config
14
- * @param config - webpack config
15
- */
16
- configIntoWebpackConfig(config: WebpackChain): void;
17
11
  /**
18
12
  * 在当前 cwd 路径下搜索 js ts 文件
19
13
  * @param fileName - 文件名不包含后缀
@@ -30,8 +24,7 @@ export default class API implements IAPI {
30
24
  * 加载 ray.config.js 文件
31
25
  */
32
26
  loadConfig(): void;
33
- loadBuiltinPlugins(): void;
34
- loadPlugin(pkg: string): Plugin;
27
+ loadPlugin(): void;
35
28
  addPlugin(plugin: Plugin): void;
36
29
  callPluginMethod(method: PluginMethods, ...args: any[]): void;
37
30
  }
package/lib/API.js CHANGED
@@ -5,6 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const path_1 = __importDefault(require("path"));
7
7
  const shared_1 = require("@ray-js/shared");
8
+ function requirePlugin(pkg) {
9
+ const pluginMain = require.resolve(pkg);
10
+ const plugin = (0, shared_1.requireJSFile)(pluginMain);
11
+ return plugin;
12
+ }
8
13
  /**
9
14
  * 命令行运行容器上下文
10
15
  * 集成插件流程
@@ -15,17 +20,6 @@ class API {
15
20
  this.plugins = [];
16
21
  this.config = {};
17
22
  }
18
- /**
19
- * 将 ray.config 作用于 webpack config
20
- * @param config - webpack config
21
- */
22
- configIntoWebpackConfig(config) {
23
- if (this.config.resolveAlias) {
24
- Object.entries(this.config.resolveAlias).forEach(([key, value]) => {
25
- config.resolve.alias.set(key, value);
26
- });
27
- }
28
- }
29
23
  /**
30
24
  * 在当前 cwd 路径下搜索 js ts 文件
31
25
  * @param fileName - 文件名不包含后缀
@@ -60,23 +54,24 @@ class API {
60
54
  this.config = (0, shared_1.requireJSFile)(rayConfigFile);
61
55
  shared_1.log.verbose('cli:API', 'ray.config', this.config);
62
56
  }
63
- loadBuiltinPlugins() {
64
- ;
65
- ['@ray-js/build-plugin-router', '@ray-js/build-plugin-ray'].forEach((pluginName) => {
66
- const p = this.loadPlugin(pluginName);
57
+ loadPlugin() {
58
+ this.config.plugins
59
+ .concat(['@ray-js/build-plugin-router', '@ray-js/build-plugin-ray'])
60
+ .forEach((p) => {
67
61
  this.addPlugin(p);
68
62
  });
69
63
  }
70
- loadPlugin(pkg) {
71
- const pluginMain = require.resolve(pkg);
72
- const plugin = (0, shared_1.requireJSFile)(pluginMain);
73
- return plugin;
74
- }
75
64
  addPlugin(plugin) {
76
- const pluginIns = plugin(this);
77
- const exist = this.plugins.some((p) => p.name === pluginIns.name);
65
+ if (typeof plugin === 'string') {
66
+ plugin = requirePlugin(plugin);
67
+ }
68
+ const _plugin = typeof plugin === 'function' ? plugin(this) : plugin;
69
+ if (!_plugin) {
70
+ return;
71
+ }
72
+ const exist = this.plugins.some((p) => p.name === _plugin.name);
78
73
  if (!exist) {
79
- this.plugins.push(pluginIns);
74
+ this.plugins.push(_plugin);
80
75
  }
81
76
  }
82
77
  callPluginMethod(method, ...args) {
@@ -30,10 +30,14 @@ const API_1 = __importDefault(require("./API"));
30
30
  function runBuilder(options) {
31
31
  return __awaiter(this, void 0, void 0, function* () {
32
32
  const api = new API_1.default(options);
33
- const { type = 'app' } = options, opts = __rest(options, ["type"]);
33
+ const { type = 'app' } = options, opts = __rest(options
34
+ // 加载ray.config.ts 或 ray.config.js
35
+ , ["type"]);
36
+ // 加载ray.config.ts 或 ray.config.js
34
37
  api.loadConfig();
35
- // 加载内置插件
36
- api.loadBuiltinPlugins();
38
+ // 加载插件,插件可以是插件的模块路径
39
+ api.loadPlugin();
40
+ // 初始化插件,即执行插件plugin.setup()方法
37
41
  api.callPluginMethod('setup');
38
42
  const ctx = { api };
39
43
  switch (opts.target) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/cli",
3
- "version": "0.7.1-beta-1",
3
+ "version": "0.7.3-beta-1",
4
4
  "description": "Ray cli",
5
5
  "bin": {
6
6
  "ray": "./bin/ray"
@@ -24,13 +24,13 @@
24
24
  "watch": "tsc -p ./tsconfig.build.json --watch"
25
25
  },
26
26
  "dependencies": {
27
- "@ray-js/build-plugin-ray": "^0.7.1-beta-1",
28
- "@ray-js/build-plugin-router": "^0.7.1-beta-1",
29
- "@ray-js/builder-component": "^0.7.1-beta-1",
30
- "@ray-js/builder-mp": "^0.7.1-beta-1",
31
- "@ray-js/builder-web": "^0.7.1-beta-1",
32
- "@ray-js/shared": "^0.7.1-beta-1",
33
- "@ray-js/types": "^0.7.1-beta-1",
27
+ "@ray-js/build-plugin-ray": "^0.7.3-beta-1",
28
+ "@ray-js/build-plugin-router": "^0.7.3-beta-1",
29
+ "@ray-js/builder-component": "^0.7.3-beta-1",
30
+ "@ray-js/builder-mp": "^0.7.3-beta-1",
31
+ "@ray-js/builder-web": "^0.7.3-beta-1",
32
+ "@ray-js/shared": "^0.7.3-beta-1",
33
+ "@ray-js/types": "^0.7.3-beta-1",
34
34
  "colors": "1.4.0",
35
35
  "commander": "^8.2.0",
36
36
  "webpack-chain": "^6.5.1"
@@ -41,6 +41,6 @@
41
41
  "email": "tuyafe@tuya.com"
42
42
  }
43
43
  ],
44
- "gitHead": "2640de2036353f044299b13254feab39544e6336",
44
+ "gitHead": "7bf0a660651d23a0a5580e2d18f956689c30db0c",
45
45
  "repository": {}
46
46
  }