@ray-js/cli 0.3.0-beta.1c347991

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 ADDED
@@ -0,0 +1 @@
1
+ # @ray-js/cli
package/bin/ray ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env node
2
+ const { log } = require('@ray-js/shared');
3
+ const colors = require('colors');
4
+
5
+ colors.enable();
6
+
7
+ if (process.argv.includes('--verbose') || 'VERBOSE' in process.env) {
8
+ process.env.LOG_LEVEL = 'verbose';
9
+ }
10
+
11
+ const program = require('commander');
12
+ const pkg = require('../package.json');
13
+
14
+ program
15
+ .version(pkg.version)
16
+ .description('Ray 命令行工具')
17
+ .command('start [cwd] [options]', '开发调试')
18
+ .alias('d')
19
+ .command('build [cwd] [options]', '构建应用/组件')
20
+ .alias('b')
21
+ .option('--verbose', '显示详细运行日志')
22
+ .parse(process.argv);
23
+
24
+ log.info('env', 'node', process.version.yellow);
25
+ log.info('cli', pkg.name, pkg.version.yellow);
@@ -0,0 +1,23 @@
1
+ const program = require('commander');
2
+ const path = require('path');
3
+ const { log } = require('@ray-js/shared');
4
+ program
5
+ .arguments('[cwd]')
6
+ .description('执行构建应用/组件')
7
+ .option('--source <folder>', '源码目录', 'src')
8
+ .option('--output <folder>', '产物目录')
9
+ .option('--mini', '启用压缩构建产物', true)
10
+ .option('--no-mini', '禁用压缩构建产物')
11
+ .option('-t --target <target>', '目标平台')
12
+ .option('-a --analyze', '开启 analyze 分析', false)
13
+ .option('--type <type>', '构建类型 eg: app | component', 'app')
14
+ .option('--transform-mode <mode>', '组件转换类型 eg: auto | pure', 'auto')
15
+ .option('--debug', '开启运行时日志', false)
16
+ .option('--max-workers <workers>', 'RN打包的max-workers')
17
+ .action(function (cwd = '', options) {
18
+ log.verbose('cli', options);
19
+ const finalCwd = path.join(process.cwd(), cwd);
20
+
21
+ require('../lib/build').default({ cwd: finalCwd, ...options });
22
+ })
23
+ .parse(process.argv);
@@ -0,0 +1,21 @@
1
+ const program = require('commander');
2
+ const path = require('path');
3
+ const { log } = require('@ray-js/shared');
4
+ program
5
+ .arguments('[cwd]')
6
+ .description('启动实时编译/预览')
7
+ .option('--source <folder>', '源码目录', 'src')
8
+ .option('--output <folder>', '产物目录')
9
+ .option('--mini', '启用压缩构建产物', true)
10
+ .option('--no-mini', '禁用压缩构建产物')
11
+ .option('-t --target <target>', '目标平台')
12
+ .option('-a --analyze', '开启 analyze 分析', false)
13
+ .option('--type <type>', '构建类型 eg: app | component', 'app')
14
+ .option('--transform-mode <mode>', '组件转换类型 eg: auto | pure', 'auto')
15
+ .option('--debug', '开启运行时日志', false)
16
+ .action(function (cwd = '', options) {
17
+ log.verbose('cli', options);
18
+ const finalCwd = path.join(process.cwd(), cwd);
19
+ require('../lib/start').default({ cwd: finalCwd, ...options });
20
+ })
21
+ .parse(process.argv);
package/lib/API.d.ts ADDED
@@ -0,0 +1,37 @@
1
+ import WebpackChain from 'webpack-chain';
2
+ import { API as IAPI, CliOptions, Plugin, PluginMethods, RayConfig } from '@ray-js/types';
3
+ /**
4
+ * 命令行运行容器上下文
5
+ * 集成插件流程
6
+ */
7
+ export default class API implements IAPI {
8
+ private plugins;
9
+ options: CliOptions;
10
+ config: RayConfig;
11
+ constructor(options: CliOptions);
12
+ /**
13
+ * 将 ray.config 作用于 webpack config
14
+ * @param config - webpack config
15
+ */
16
+ configIntoWebpackConfig(config: WebpackChain): void;
17
+ /**
18
+ * 在当前 cwd 路径下搜索 js ts 文件
19
+ * @param fileName - 文件名不包含后缀
20
+ */
21
+ searchJSFile(fileName: string): string;
22
+ requireJSFile(file: string, specifier: string): any;
23
+ /**
24
+ * 在当前 cwd 路径下写入文件
25
+ * @param fileBase - 文件地址
26
+ * @param context - 文件内容
27
+ */
28
+ writeFile(fileBase: string, context: string): void;
29
+ /**
30
+ * 加载 ray.config.js 文件
31
+ */
32
+ loadConfig(): void;
33
+ loadBuiltinPlugins(): void;
34
+ loadPlugin(pkg: string): Plugin;
35
+ addPlugin(plugin: Plugin): void;
36
+ callPluginMethod(method: PluginMethods, ...args: any[]): void;
37
+ }
package/lib/API.js ADDED
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const path_1 = __importDefault(require("path"));
7
+ const shared_1 = require("@ray-js/shared");
8
+ /**
9
+ * 命令行运行容器上下文
10
+ * 集成插件流程
11
+ */
12
+ class API {
13
+ constructor(options) {
14
+ this.options = options;
15
+ this.plugins = [];
16
+ this.config = {};
17
+ }
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
+ /**
30
+ * 在当前 cwd 路径下搜索 js ts 文件
31
+ * @param fileName - 文件名不包含后缀
32
+ */
33
+ searchJSFile(fileName) {
34
+ return (0, shared_1.searchJSFile)(fileName, {
35
+ cwd: this.options.cwd,
36
+ extensions: ['.tsx', '.ts', '.jsx', '.js'],
37
+ });
38
+ }
39
+ requireJSFile(file, specifier) {
40
+ return (0, shared_1.requireJSFile)(file, specifier);
41
+ }
42
+ /**
43
+ * 在当前 cwd 路径下写入文件
44
+ * @param fileBase - 文件地址
45
+ * @param context - 文件内容
46
+ */
47
+ writeFile(fileBase, context) {
48
+ const file = path_1.default.join(this.options.cwd, fileBase);
49
+ (0, shared_1.writeFileSync)(file, context);
50
+ }
51
+ /**
52
+ * 加载 ray.config.js 文件
53
+ */
54
+ loadConfig() {
55
+ const rayConfigFile = this.searchJSFile(`ray.config`);
56
+ if (!rayConfigFile) {
57
+ shared_1.log.error('cli', 'Missing ray config file.');
58
+ throw new Error('Must has ray config.');
59
+ }
60
+ this.config = (0, shared_1.requireJSFile)(rayConfigFile);
61
+ shared_1.log.verbose('cli:API', 'ray.config', this.config);
62
+ }
63
+ loadBuiltinPlugins() {
64
+ ['@ray-js/build-plugin-router', '@ray-js/build-plugin-ray'].forEach((pluginName) => {
65
+ const p = this.loadPlugin(pluginName);
66
+ this.addPlugin(p);
67
+ });
68
+ }
69
+ loadPlugin(pkg) {
70
+ const pluginMain = require.resolve(pkg);
71
+ const plugin = (0, shared_1.requireJSFile)(pluginMain);
72
+ return plugin;
73
+ }
74
+ addPlugin(plugin) {
75
+ const pluginIns = plugin(this);
76
+ const exist = this.plugins.some((p) => p.name === pluginIns.name);
77
+ if (!exist) {
78
+ this.plugins.push(pluginIns);
79
+ }
80
+ }
81
+ callPluginMethod(method, ...args) {
82
+ shared_1.log.verbose('cli:api', 'callPluginMethod:', method);
83
+ this.plugins.forEach((plugin) => {
84
+ if (typeof plugin[method] === 'function') {
85
+ plugin[method].apply(plugin, args);
86
+ }
87
+ });
88
+ }
89
+ }
90
+ exports.default = API;
package/lib/build.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { CliOptions } from '@ray-js/types';
2
+ export default function build(options: CliOptions): Promise<void>;
package/lib/build.js ADDED
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ const run_builder_1 = require("./run-builder");
24
+ function build(options) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const { type = 'app' } = options, restOptions = __rest(options, ["type"]);
27
+ if (type === 'component') {
28
+ const { build: buildComponent } = require('@ray-js/builder-component');
29
+ yield buildComponent(Object.assign(Object.assign({}, restOptions), { mode: 'production', watch: false })).catch((error) => {
30
+ console.log(error);
31
+ process.exit(1);
32
+ });
33
+ }
34
+ else {
35
+ yield (0, run_builder_1.runBuilder)(Object.assign(Object.assign({}, options), { mode: 'production', watch: false })).catch((error) => {
36
+ console.log(error);
37
+ process.exit(1);
38
+ });
39
+ }
40
+ });
41
+ }
42
+ exports.default = build;
package/lib/index.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { default as API } from './API';
package/lib/index.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.API = void 0;
7
+ var API_1 = require("./API");
8
+ Object.defineProperty(exports, "API", { enumerable: true, get: function () { return __importDefault(API_1).default; } });
@@ -0,0 +1,2 @@
1
+ import { CliOptions } from '@ray-js/types';
2
+ export declare function runBuilder(options: CliOptions): Promise<void>;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.runBuilder = void 0;
27
+ const API_1 = __importDefault(require("./API"));
28
+ function runBuilder(options) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ const api = new API_1.default(options);
31
+ const { type = 'app' } = options, restOptions = __rest(options, ["type"]);
32
+ api.loadConfig();
33
+ // 加载内置插件
34
+ api.loadBuiltinPlugins();
35
+ api.callPluginMethod('setup');
36
+ if (['wechat', 'tuya'].includes(restOptions.target)) {
37
+ const { build: buildMiniProgram } = require('@ray-js/builder-mp');
38
+ yield buildMiniProgram(Object.assign({}, restOptions), { api });
39
+ }
40
+ else if (restOptions.target === 'web') {
41
+ const { build: buildWeb } = require('@ray-js/builder-web');
42
+ yield buildWeb(Object.assign({}, restOptions), { api });
43
+ }
44
+ else if (restOptions.target === 'native') {
45
+ const { build: buildRN } = require('@ray-js/builder-native');
46
+ yield buildRN(Object.assign({}, restOptions), { api });
47
+ }
48
+ else {
49
+ throw new Error(`Target '${restOptions.target}' is not supported.'`);
50
+ }
51
+ });
52
+ }
53
+ exports.runBuilder = runBuilder;
package/lib/start.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { CliOptions } from '@ray-js/types';
2
+ export default function start(options: CliOptions): Promise<void>;
package/lib/start.js ADDED
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ const run_builder_1 = require("./run-builder");
24
+ function start(options) {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const { type = 'app' } = options, restOptions = __rest(options, ["type"]);
27
+ if (type === 'component') {
28
+ const { build: buildComponent } = require('@ray-js/builder-component');
29
+ yield buildComponent(Object.assign(Object.assign({}, restOptions), { watch: true })).catch((error) => {
30
+ console.log(error);
31
+ process.exit(1);
32
+ });
33
+ }
34
+ else {
35
+ yield (0, run_builder_1.runBuilder)(Object.assign(Object.assign({}, options), { mode: 'development', watch: true })).catch((error) => {
36
+ console.log(error);
37
+ process.exit(1);
38
+ });
39
+ }
40
+ });
41
+ }
42
+ exports.default = start;
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@ray-js/cli",
3
+ "version": "0.3.0-beta.1c347991",
4
+ "description": "Ray cli",
5
+ "bin": {
6
+ "ray": "./bin/ray"
7
+ },
8
+ "keywords": [
9
+ "ray"
10
+ ],
11
+ "author": "子长 <zichang.nong@tuya.com>",
12
+ "license": "MIT",
13
+ "main": "lib/index.js",
14
+ "files": [
15
+ "lib",
16
+ "bin"
17
+ ],
18
+ "publishConfig": {
19
+ "access": "public",
20
+ "registry": "https://registry.npmjs.org"
21
+ },
22
+ "scripts": {
23
+ "clean": "rm -rf lib",
24
+ "build": "tsc -p ./tsconfig.build.json",
25
+ "watch": "tsc -p ./tsconfig.build.json --watch"
26
+ },
27
+ "dependencies": {
28
+ "@ray-js/build-plugin-ray": "^0.3.0-beta.1c347991",
29
+ "@ray-js/build-plugin-router": "^0.3.0-beta.1c347991",
30
+ "@ray-js/builder-component": "^0.3.0-beta.1c347991",
31
+ "@ray-js/builder-mp": "^0.3.0-beta.1c347991",
32
+ "@ray-js/builder-native": "^0.3.0-beta.1c347991",
33
+ "@ray-js/builder-web": "^0.3.0-beta.1c347991",
34
+ "@ray-js/shared": "^0.3.0-beta.1c347991",
35
+ "@ray-js/types": "^0.3.0-beta.1c347991",
36
+ "colors": "1.4.0",
37
+ "commander": "^8.2.0"
38
+ },
39
+ "devDependencies": {
40
+ "webpack-chain": "^6.5.1"
41
+ },
42
+ "maintainers": [
43
+ {
44
+ "name": "tuyafe",
45
+ "email": "tuyafe@tuya.com"
46
+ }
47
+ ],
48
+ "gitHead": "e0bd013022ddda63380d3c9e20fd8cadb46cd61f",
49
+ "repository": {}
50
+ }