@ray-js/cli 1.6.25 → 1.6.26
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 +7 -7
- package/bin/ray-build.js +20 -19
- package/bin/ray-start.js +23 -23
- package/bin/register-env.js +3 -3
- package/lib/index.d.ts +37 -1
- package/lib/index.js +1 -8
- package/package.json +17 -13
- package/lib/API.d.ts +0 -30
- package/lib/API.js +0 -96
- package/lib/build.d.ts +0 -2
- package/lib/build.js +0 -51
- package/lib/run-builder.d.ts +0 -2
- package/lib/run-builder.js +0 -87
- package/lib/start.d.ts +0 -2
- package/lib/start.js +0 -50
package/bin/ray
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const { log } = require('@ray-js/shared');
|
|
2
|
+
const { log, i18n } = require('@ray-js/shared');
|
|
3
3
|
const colors = require('colors');
|
|
4
4
|
|
|
5
5
|
colors.enable();
|
|
@@ -12,7 +12,7 @@ if (process.argv.includes('--verbose') || 'VERBOSE' in process.env) {
|
|
|
12
12
|
if (parseInt(process.versions.node.split('.')[0]) < 16) {
|
|
13
13
|
log.error('env', 'node version:', process.versions.node);
|
|
14
14
|
log.error('error', 'node version must be >= 16.0.0');
|
|
15
|
-
log.error('error',
|
|
15
|
+
log.error('error', i18n.__('upgradeNodeVersion'), 'https://nodejs.org/en'.underline.blue);
|
|
16
16
|
process.exit(1);
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -21,13 +21,13 @@ const pkg = require('../package.json');
|
|
|
21
21
|
|
|
22
22
|
program
|
|
23
23
|
.version(pkg.version)
|
|
24
|
-
.description('
|
|
25
|
-
.command('start [cwd] [options]', '
|
|
24
|
+
.description(i18n.__('rayCliTool'))
|
|
25
|
+
.command('start [cwd] [options]', i18n.__('devMode'))
|
|
26
26
|
.alias('d')
|
|
27
|
-
.command('build [cwd] [options]', '
|
|
27
|
+
.command('build [cwd] [options]', i18n.__('buildDesc'))
|
|
28
28
|
.alias('b')
|
|
29
|
-
.option('--verbose', '
|
|
29
|
+
.option('--verbose', i18n.__('showDetailedLogs'))
|
|
30
30
|
.parse(process.argv);
|
|
31
31
|
|
|
32
32
|
log.info('env', 'node', process.version.yellow);
|
|
33
|
-
log.info('cli', pkg.name, pkg.version.yellow);
|
|
33
|
+
log.info('cli', pkg.name, pkg.version.yellow);
|
package/bin/ray-build.js
CHANGED
|
@@ -1,32 +1,33 @@
|
|
|
1
1
|
const program = require('commander')
|
|
2
|
-
const path = require('path')
|
|
3
|
-
const { log } = require('@ray-js/shared')
|
|
2
|
+
const path = require('node:path')
|
|
3
|
+
const { log,i18n } = require('@ray-js/shared');
|
|
4
4
|
const registerEnv = require('./register-env')
|
|
5
5
|
|
|
6
6
|
program
|
|
7
7
|
.arguments('[cwd]')
|
|
8
|
-
.description('
|
|
9
|
-
.option('--source <folder>', '
|
|
10
|
-
.option('--output <folder>', '
|
|
11
|
-
.option('--mini', '
|
|
12
|
-
.option('--blended', '
|
|
13
|
-
.option('--no-mini', '
|
|
14
|
-
.option('--sourcemap', '
|
|
15
|
-
.option('--no-sourcemap', '
|
|
16
|
-
.option('-t --target <target>', '
|
|
17
|
-
.option('-a --analyze', '
|
|
18
|
-
.option('--drop', '
|
|
19
|
-
.option('--type <type>', '
|
|
20
|
-
.option('--transform-mode <mode>', '
|
|
8
|
+
.description(i18n.__('buildDesc'))
|
|
9
|
+
.option('--source <folder>', i18n.__('sourceFolder'))
|
|
10
|
+
.option('--output <folder>', i18n.__('outputFolder'))
|
|
11
|
+
.option('--mini', i18n.__('enableMini'), true)
|
|
12
|
+
.option('--blended', i18n.__('blended'))
|
|
13
|
+
.option('--no-mini', i18n.__('disableMini'))
|
|
14
|
+
.option('--sourcemap', i18n.__('enableSourcemap'), true)
|
|
15
|
+
.option('--no-sourcemap', i18n.__('disableSourcemap'))
|
|
16
|
+
.option('-t --target <target>', i18n.__('targetPlatform'))
|
|
17
|
+
.option('-a --analyze', i18n.__('enableAnalyze'))
|
|
18
|
+
.option('--drop', i18n.__('removeLogs'), false)
|
|
19
|
+
.option('--type <type>', i18n.__('buildType'), 'app')
|
|
20
|
+
.option('--transform-mode <mode>', i18n.__('transformMode'), 'pure')
|
|
21
21
|
.option(
|
|
22
22
|
'--bundler <type>',
|
|
23
|
-
'
|
|
23
|
+
i18n.__('bundlerDesc'),
|
|
24
24
|
'esbuild'
|
|
25
25
|
)
|
|
26
|
-
.option('--debug [debug]', '
|
|
26
|
+
.option('--debug [debug]', i18n.__('enableDebug'), (v) => {
|
|
27
27
|
return JSON.parse(v === '1' || v === 'true')
|
|
28
28
|
})
|
|
29
29
|
.action((cwd = '', options) => {
|
|
30
|
+
// Rest of the function unchanged
|
|
30
31
|
log.verbose('cli', options)
|
|
31
32
|
if (options.target === 'tuya') {
|
|
32
33
|
log.verbose('cli', 'change target tuya -> thing')
|
|
@@ -53,6 +54,6 @@ program
|
|
|
53
54
|
const analyze = !!process.env.CI_BUILD_ANALYZE || options.analyze
|
|
54
55
|
const mode = process.env.NODE_ENV
|
|
55
56
|
process.chdir(cwd)
|
|
56
|
-
require('../lib
|
|
57
|
+
require('../lib').build({ ...options, cwd, mode, devtools, analyze })
|
|
57
58
|
})
|
|
58
|
-
.parse(process.argv)
|
|
59
|
+
.parse(process.argv)
|
package/bin/ray-start.js
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
const program = require('commander')
|
|
2
|
-
const path = require('path')
|
|
3
|
-
const { log } = require('@ray-js/shared')
|
|
2
|
+
const path = require('node:path')
|
|
3
|
+
const { log, i18n } = require('@ray-js/shared');
|
|
4
4
|
const registerEnv = require('./register-env')
|
|
5
5
|
|
|
6
6
|
program
|
|
7
7
|
.arguments('[cwd]')
|
|
8
|
-
.description('
|
|
9
|
-
.option('--source <folder>', '
|
|
10
|
-
.option('--output <folder>', '
|
|
11
|
-
.option('--mini', '
|
|
12
|
-
.option('--blended', '
|
|
13
|
-
.option('--no-mini', '
|
|
14
|
-
.option('--sourcemap', '
|
|
15
|
-
.option('--no-sourcemap', '
|
|
16
|
-
.option('-t --target <target>', '
|
|
17
|
-
.option('-a --analyze', '
|
|
18
|
-
.option('--drop', '
|
|
19
|
-
.option('--type <type>', '
|
|
20
|
-
.option('--transform-mode <mode>', '
|
|
8
|
+
.description(i18n.__('startDesc'))
|
|
9
|
+
.option('--source <folder>', i18n.__('sourceFolder'))
|
|
10
|
+
.option('--output <folder>', i18n.__('outputFolder'))
|
|
11
|
+
.option('--mini', i18n.__('enableMini'), false)
|
|
12
|
+
.option('--blended', i18n.__('blended'))
|
|
13
|
+
.option('--no-mini', i18n.__('disableMini'))
|
|
14
|
+
.option('--sourcemap', i18n.__('enableSourcemap'), true)
|
|
15
|
+
.option('--no-sourcemap', i18n.__('disableSourcemap'))
|
|
16
|
+
.option('-t --target <target>', i18n.__('targetPlatform'))
|
|
17
|
+
.option('-a --analyze', i18n.__('enableAnalyze'))
|
|
18
|
+
.option('--drop', i18n.__('removeLogs'), false)
|
|
19
|
+
.option('--type <type>', i18n.__('buildType'), 'app')
|
|
20
|
+
.option('--transform-mode <mode>', i18n.__('transformMode'), 'pure')
|
|
21
21
|
.option(
|
|
22
22
|
'--bundler <type>',
|
|
23
|
-
'
|
|
23
|
+
i18n.__('bundlerDesc'),
|
|
24
24
|
'esbuild'
|
|
25
25
|
)
|
|
26
|
-
.option('--debug [debug]', '
|
|
26
|
+
.option('--debug [debug]', i18n.__('enableDebug'), (v) => {
|
|
27
27
|
return JSON.parse(v === '1' || v === 'true')
|
|
28
28
|
})
|
|
29
|
-
.option('--emit-declaration-dev', '
|
|
30
|
-
.action(
|
|
29
|
+
.option('--emit-declaration-dev', i18n.__('emitDeclarationDev'), false)
|
|
30
|
+
.action((cwd = '', options) => {
|
|
31
31
|
log.verbose('cli', options)
|
|
32
32
|
if (options.target === 'tuya') {
|
|
33
33
|
log.verbose('cli', 'change target tuya -> thing')
|
|
34
34
|
options.target = 'thing'
|
|
35
35
|
}
|
|
36
36
|
if (typeof options.debug === 'boolean') {
|
|
37
|
-
process.env.RAY_DEBUG = JSON.stringify(options.debug) //
|
|
38
|
-
process.env.REMAX_DEBUG = process.env.RAY_DEBUG //
|
|
37
|
+
process.env.RAY_DEBUG = JSON.stringify(options.debug) // i18n.__('rayRuntimeLog')
|
|
38
|
+
process.env.REMAX_DEBUG = process.env.RAY_DEBUG // i18n.__('rayCoreRuntimeLog')
|
|
39
39
|
} else {
|
|
40
40
|
const rayDebug = process.env.RAY_DEBUG
|
|
41
41
|
if (rayDebug === 'true' || rayDebug === 'false') {
|
|
@@ -53,6 +53,6 @@ program
|
|
|
53
53
|
const devtools = process.env.TUYA_DEVTOOLS !== undefined
|
|
54
54
|
const mode = process.env.NODE_ENV
|
|
55
55
|
process.chdir(cwd)
|
|
56
|
-
require('../lib
|
|
56
|
+
require('../lib').start({ ...options, cwd, mode, devtools })
|
|
57
57
|
})
|
|
58
|
-
.parse(process.argv)
|
|
58
|
+
.parse(process.argv)
|
package/bin/register-env.js
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -1 +1,37 @@
|
|
|
1
|
-
|
|
1
|
+
import { API as API$1, CliOptions, RayConfig, Plugin, PluginMethods } from '@ray-js/types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 命令行运行容器上下文
|
|
5
|
+
* 集成插件流程
|
|
6
|
+
*/
|
|
7
|
+
declare class API implements API$1 {
|
|
8
|
+
private plugins;
|
|
9
|
+
options: CliOptions;
|
|
10
|
+
config: RayConfig;
|
|
11
|
+
constructor(options: CliOptions);
|
|
12
|
+
/**
|
|
13
|
+
* 在当前 cwd 路径下搜索 js ts 文件
|
|
14
|
+
* @param fileName - 文件名不包含后缀
|
|
15
|
+
*/
|
|
16
|
+
searchJSFile(fileName: string): string;
|
|
17
|
+
requireJSFile(file: string, specifier: string): any;
|
|
18
|
+
/**
|
|
19
|
+
* 在当前 cwd 路径下写入文件
|
|
20
|
+
* @param fileBase - 文件地址
|
|
21
|
+
* @param context - 文件内容
|
|
22
|
+
*/
|
|
23
|
+
writeFile(fileBase: string, context: string): void;
|
|
24
|
+
/**
|
|
25
|
+
* 加载 ray.config.js 文件
|
|
26
|
+
*/
|
|
27
|
+
loadConfig(): void;
|
|
28
|
+
loadPlugin(): void;
|
|
29
|
+
addPlugin(plugin: Plugin): void;
|
|
30
|
+
callPluginMethod(method: PluginMethods, ...args: any[]): void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
declare function build(options: CliOptions): void;
|
|
34
|
+
|
|
35
|
+
declare function start(options: CliOptions): void;
|
|
36
|
+
|
|
37
|
+
export { API, build, start };
|
package/lib/index.js
CHANGED
|
@@ -1,8 +1 @@
|
|
|
1
|
-
"
|
|
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; } });
|
|
1
|
+
var q=Object.create;var d=Object.defineProperty,B=Object.defineProperties,D=Object.getOwnPropertyDescriptor,F=Object.getOwnPropertyDescriptors,S=Object.getOwnPropertyNames,y=Object.getOwnPropertySymbols,J=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable;var O=(o,i,t)=>i in o?d(o,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[i]=t,p=(o,i)=>{for(var t in i||(i={}))w.call(i,t)&&O(o,t,i[t]);if(y)for(var t of y(i))j.call(i,t)&&O(o,t,i[t]);return o},f=(o,i)=>B(o,F(i));var m=(o,i)=>{var t={};for(var s in o)w.call(o,s)&&i.indexOf(s)<0&&(t[s]=o[s]);if(o!=null&&y)for(var s of y(o))i.indexOf(s)<0&&j.call(o,s)&&(t[s]=o[s]);return t};var U=(o,i)=>{for(var t in i)d(o,t,{get:i[t],enumerable:!0})},v=(o,i,t,s)=>{if(i&&typeof i=="object"||typeof i=="function")for(let e of S(i))!w.call(o,e)&&e!==t&&d(o,e,{get:()=>i[e],enumerable:!(s=D(i,e))||s.enumerable});return o};var A=(o,i,t)=>(t=o!=null?q(J(o)):{},v(i||!o||!o.__esModule?d(t,"default",{value:o,enumerable:!0}):t,o)),_=o=>v(d({},"__esModule",{value:!0}),o);var M=(o,i,t)=>new Promise((s,e)=>{var r=a=>{try{u(t.next(a))}catch(g){e(g)}},c=a=>{try{u(t.throw(a))}catch(g){e(g)}},u=a=>a.done?s(a.value):Promise.resolve(a.value).then(r,c);u((t=t.apply(o,i)).next())});var Y={};U(Y,{API:()=>l,build:()=>P,start:()=>C});module.exports=_(Y);var I=A(require("path")),n=require("@ray-js/shared");function z(o){let i=require.resolve(o);return(0,n.requireJSFile)(i)}var l=class{constructor(i){this.options=i,this.plugins=[],this.config={}}searchJSFile(i){return(0,n.searchJSFile)(i,{cwd:this.options.cwd,extensions:[".tsx",".ts",".jsx",".js"]})}requireJSFile(i,t){return(0,n.requireJSFile)(i,t)}writeFile(i,t){let s=I.default.join(this.options.cwd,i);(0,n.writeFileSync)(s,t)}loadConfig(){let i=this.searchJSFile("ray.config");if(!i)throw n.log.error("cli","Missing ray config file."),new Error("Must has ray config.");this.config=(0,n.requireJSFile)(i),(!this.config.plugins||!Array.isArray(this.config.plugins))&&(this.config.plugins=[]),n.log.verbose("cli:API","ray.config",this.config)}loadPlugin(){this.config.plugins.concat(["@ray-js/build-plugin-router","@ray-js/build-plugin-ray","@ray-js/ray/plugins/i18n-plugin"]).forEach(i=>{this.addPlugin(i)})}addPlugin(i){typeof i=="string"&&(i.startsWith("ray")&&(i=`@ray-js/${i}`),i=z(i));let t=typeof i=="function"?i(this):i;if(!t)return;this.plugins.some(e=>e.name&&t.name&&e.name===t.name)||this.plugins.push(t)}callPluginMethod(i,...t){n.log.verbose("cli:api","callPluginMethod:",i),this.plugins.forEach(s=>{typeof s[i]=="function"&&s[i].apply(s,t)})}};var R=require("@ray-js/builder-mp"),E=require("@ray-js/builder-web"),h=require("@ray-js/shared"),k=A(require("colors"));k.default.enable();var G={cwd:process.cwd(),source:"src",mode:"development",watch:!1,target:"thing",mini:!1,analyze:!1,devtools:!1,debug:!1,output:"dist"};function b(o){return M(this,null,function*(){let i=new l(o);i.loadConfig();let t=Object.assign({},G,i.config,o),s=process.env.RAY_DEBUG===void 0;o.debug===void 0&&(s?typeof i.config.debug=="boolean"&&(process.env.RAY_DEBUG=JSON.stringify(i.config.debug),process.env.REMAX_DEBUG=process.env.RAY_DEBUG):t.debug=process.env.RAY_DEBUG==="true");let{cwd:e,target:r,output:c,onTargetDir:u}=t,a=r==="thing"?"tuya":r,g=(0,h.resolvePath)(typeof u=="function"?[u(c,a)]:[c,a],{cwd:e});t.output=g,i.options=t,h.log.verbose("ray-builder","final options:",t),i.loadPlugin(),i.callPluginMethod("setup");let x={api:i};switch(t.target){case"tuya":case"wechat":case"thing":yield(0,R.build)(t,x);break;case"web":yield(0,E.build)(t,x);break;default:throw new Error(`Target '${t.target}' is not supported.'`)}})}function P(o){let s=o,{type:i="app"}=s,t=m(s,["type"]);if(t.target==="thing"&&t.bundler==="esbuild"){process.chdir(t.cwd);let{build:e}=require("@ray-js/raypack"),r={cwd:t.cwd,watch:!1,sourceDir:t.source||"src",output:t.output||"dist/tuya",minify:t.mini,autoCssModules:!1,sourcemap:t.sourcemap,drop:t.drop,analyze:t.analyze};e(r).catch(c=>{console.log(c),process.exit(101)})}else if(i==="component"){let{build:e}=require("@ray-js/builder-component");e(f(p({},t),{watch:!1})).catch(r=>{console.log(r),process.exit(1)})}else b(f(p({},o),{watch:!1})).catch(e=>{console.log(e),process.exit(1)})}function C(o){let s=o,{type:i="app"}=s,t=m(s,["type"]);if(t.target==="thing"&&t.bundler==="esbuild"){let{build:e}=require("@ray-js/raypack"),r={cwd:t.cwd,watch:!0,sourceDir:t.source||"src",output:t.output||"dist/tuya",minify:t.mini,autoCssModules:!1,sourcemap:t.sourcemap,drop:t.drop,analyze:t.analyze};e(r).catch(c=>{console.log(c),process.exit(101)})}else if(i==="component"){let{build:e}=require("@ray-js/builder-component");e(f(p({},t),{watch:!0})).catch(r=>{console.log(r),process.exit(1)})}else b(f(p({},o),{watch:!0})).catch(e=>{console.log(e),process.exit(1)})}0&&(module.exports={API,build,start});
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-js/cli",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.26",
|
|
4
4
|
"description": "Ray cli",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ray"
|
|
7
7
|
],
|
|
8
8
|
"repository": {},
|
|
9
9
|
"license": "MIT",
|
|
10
|
+
"type": "commonjs",
|
|
10
11
|
"maintainers": [
|
|
11
12
|
{
|
|
12
13
|
"name": "tuyafe",
|
|
@@ -22,19 +23,19 @@
|
|
|
22
23
|
"bin"
|
|
23
24
|
],
|
|
24
25
|
"scripts": {
|
|
25
|
-
"build": "
|
|
26
|
+
"build": "tsup src/index.ts --minify --dts --format cjs --out-dir lib --tsconfig tsconfig.build.json",
|
|
26
27
|
"clean": "rm -rf lib",
|
|
27
|
-
"watch": "
|
|
28
|
+
"watch": "npm run build -- --watch"
|
|
28
29
|
},
|
|
29
30
|
"dependencies": {
|
|
30
|
-
"@ray-js/build-plugin-ray": "1.6.
|
|
31
|
-
"@ray-js/build-plugin-router": "1.6.
|
|
32
|
-
"@ray-js/builder-component": "1.6.
|
|
33
|
-
"@ray-js/builder-mp": "1.6.
|
|
34
|
-
"@ray-js/builder-web": "1.6.
|
|
35
|
-
"@ray-js/raypack": "1.6.
|
|
36
|
-
"@ray-js/shared": "1.6.
|
|
37
|
-
"@ray-js/types": "1.6.
|
|
31
|
+
"@ray-js/build-plugin-ray": "1.6.26",
|
|
32
|
+
"@ray-js/build-plugin-router": "1.6.26",
|
|
33
|
+
"@ray-js/builder-component": "1.6.26",
|
|
34
|
+
"@ray-js/builder-mp": "1.6.26",
|
|
35
|
+
"@ray-js/builder-web": "1.6.26",
|
|
36
|
+
"@ray-js/raypack": "1.6.26",
|
|
37
|
+
"@ray-js/shared": "1.6.26",
|
|
38
|
+
"@ray-js/types": "1.6.26",
|
|
38
39
|
"colors": "1.4.0",
|
|
39
40
|
"commander": "^8.3.0",
|
|
40
41
|
"webpack-chain": "^6.5.1"
|
|
@@ -43,8 +44,11 @@
|
|
|
43
44
|
"access": "public",
|
|
44
45
|
"registry": "https://registry.npmjs.com"
|
|
45
46
|
},
|
|
46
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "d842231dd15303495069483a809a71dbc640ebaf",
|
|
47
48
|
"devDependencies": {
|
|
48
|
-
"
|
|
49
|
+
"@swc/cli": "^0.6.0",
|
|
50
|
+
"@swc/core": "^1.11.11",
|
|
51
|
+
"tsup": "^8.4.0",
|
|
52
|
+
"typescript": "^5.8.2"
|
|
49
53
|
}
|
|
50
54
|
}
|
package/lib/API.d.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { API as IAPI, CliOptions, Plugin, PluginMethods, RayConfig } from '@ray-js/types';
|
|
2
|
-
/**
|
|
3
|
-
* 命令行运行容器上下文
|
|
4
|
-
* 集成插件流程
|
|
5
|
-
*/
|
|
6
|
-
export default class API implements IAPI {
|
|
7
|
-
private plugins;
|
|
8
|
-
options: CliOptions;
|
|
9
|
-
config: RayConfig;
|
|
10
|
-
constructor(options: CliOptions);
|
|
11
|
-
/**
|
|
12
|
-
* 在当前 cwd 路径下搜索 js ts 文件
|
|
13
|
-
* @param fileName - 文件名不包含后缀
|
|
14
|
-
*/
|
|
15
|
-
searchJSFile(fileName: string): string;
|
|
16
|
-
requireJSFile(file: string, specifier: string): any;
|
|
17
|
-
/**
|
|
18
|
-
* 在当前 cwd 路径下写入文件
|
|
19
|
-
* @param fileBase - 文件地址
|
|
20
|
-
* @param context - 文件内容
|
|
21
|
-
*/
|
|
22
|
-
writeFile(fileBase: string, context: string): void;
|
|
23
|
-
/**
|
|
24
|
-
* 加载 ray.config.js 文件
|
|
25
|
-
*/
|
|
26
|
-
loadConfig(): void;
|
|
27
|
-
loadPlugin(): void;
|
|
28
|
-
addPlugin(plugin: Plugin): void;
|
|
29
|
-
callPluginMethod(method: PluginMethods, ...args: any[]): void;
|
|
30
|
-
}
|
package/lib/API.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
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
|
-
function requirePlugin(pkg) {
|
|
9
|
-
const pluginMain = require.resolve(pkg);
|
|
10
|
-
const plugin = (0, shared_1.requireJSFile)(pluginMain);
|
|
11
|
-
return plugin;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* 命令行运行容器上下文
|
|
15
|
-
* 集成插件流程
|
|
16
|
-
*/
|
|
17
|
-
class API {
|
|
18
|
-
constructor(options) {
|
|
19
|
-
this.options = options;
|
|
20
|
-
this.plugins = [];
|
|
21
|
-
this.config = {};
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* 在当前 cwd 路径下搜索 js ts 文件
|
|
25
|
-
* @param fileName - 文件名不包含后缀
|
|
26
|
-
*/
|
|
27
|
-
searchJSFile(fileName) {
|
|
28
|
-
return (0, shared_1.searchJSFile)(fileName, {
|
|
29
|
-
cwd: this.options.cwd,
|
|
30
|
-
extensions: ['.tsx', '.ts', '.jsx', '.js'],
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
requireJSFile(file, specifier) {
|
|
34
|
-
return (0, shared_1.requireJSFile)(file, specifier);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* 在当前 cwd 路径下写入文件
|
|
38
|
-
* @param fileBase - 文件地址
|
|
39
|
-
* @param context - 文件内容
|
|
40
|
-
*/
|
|
41
|
-
writeFile(fileBase, context) {
|
|
42
|
-
const file = path_1.default.join(this.options.cwd, fileBase);
|
|
43
|
-
(0, shared_1.writeFileSync)(file, context);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* 加载 ray.config.js 文件
|
|
47
|
-
*/
|
|
48
|
-
loadConfig() {
|
|
49
|
-
const rayConfigFile = this.searchJSFile(`ray.config`);
|
|
50
|
-
if (!rayConfigFile) {
|
|
51
|
-
shared_1.log.error('cli', 'Missing ray config file.');
|
|
52
|
-
throw new Error('Must has ray config.');
|
|
53
|
-
}
|
|
54
|
-
this.config = (0, shared_1.requireJSFile)(rayConfigFile);
|
|
55
|
-
if (!this.config.plugins || !Array.isArray(this.config.plugins)) {
|
|
56
|
-
this.config.plugins = [];
|
|
57
|
-
}
|
|
58
|
-
shared_1.log.verbose('cli:API', 'ray.config', this.config);
|
|
59
|
-
}
|
|
60
|
-
loadPlugin() {
|
|
61
|
-
this.config.plugins
|
|
62
|
-
.concat([
|
|
63
|
-
'@ray-js/build-plugin-router',
|
|
64
|
-
'@ray-js/build-plugin-ray',
|
|
65
|
-
'@ray-js/ray/plugins/i18n-plugin',
|
|
66
|
-
])
|
|
67
|
-
.forEach((p) => {
|
|
68
|
-
this.addPlugin(p);
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
addPlugin(plugin) {
|
|
72
|
-
if (typeof plugin === 'string') {
|
|
73
|
-
if (plugin.startsWith('ray')) {
|
|
74
|
-
plugin = `@ray-js/${plugin}`;
|
|
75
|
-
}
|
|
76
|
-
plugin = requirePlugin(plugin);
|
|
77
|
-
}
|
|
78
|
-
const _p = typeof plugin === 'function' ? plugin(this) : plugin;
|
|
79
|
-
if (!_p) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
const exist = this.plugins.some((p) => p.name && _p.name && p.name === _p.name);
|
|
83
|
-
if (!exist) {
|
|
84
|
-
this.plugins.push(_p);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
callPluginMethod(method, ...args) {
|
|
88
|
-
shared_1.log.verbose('cli:api', 'callPluginMethod:', method);
|
|
89
|
-
this.plugins.forEach((plugin) => {
|
|
90
|
-
if (typeof plugin[method] === 'function') {
|
|
91
|
-
plugin[method].apply(plugin, args);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
exports.default = API;
|
package/lib/build.d.ts
DELETED
package/lib/build.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.default = build;
|
|
15
|
-
const run_builder_1 = require("./run-builder");
|
|
16
|
-
function build(options) {
|
|
17
|
-
const { type = 'app' } = options, restOptions = __rest(options, ["type"]);
|
|
18
|
-
if (restOptions.target === 'thing' && restOptions.bundler === 'esbuild') {
|
|
19
|
-
process.chdir(restOptions.cwd);
|
|
20
|
-
// 使用 raypack 进行构建
|
|
21
|
-
const { build } = require('@ray-js/raypack');
|
|
22
|
-
const opts = {
|
|
23
|
-
cwd: restOptions.cwd,
|
|
24
|
-
watch: false,
|
|
25
|
-
sourceDir: restOptions.source || 'src',
|
|
26
|
-
output: restOptions.output || 'dist/tuya',
|
|
27
|
-
minify: restOptions.mini,
|
|
28
|
-
autoCssModules: false,
|
|
29
|
-
sourcemap: restOptions.sourcemap,
|
|
30
|
-
drop: restOptions.drop,
|
|
31
|
-
analyze: restOptions.analyze,
|
|
32
|
-
};
|
|
33
|
-
build(opts).catch((error) => {
|
|
34
|
-
console.log(error);
|
|
35
|
-
process.exit(101);
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
else if (type === 'component') {
|
|
39
|
-
const { build: buildComponent } = require('@ray-js/builder-component');
|
|
40
|
-
buildComponent(Object.assign(Object.assign({}, restOptions), { watch: false })).catch((error) => {
|
|
41
|
-
console.log(error);
|
|
42
|
-
process.exit(1);
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
(0, run_builder_1.runBuilder)(Object.assign(Object.assign({}, options), { watch: false })).catch((error) => {
|
|
47
|
-
console.log(error);
|
|
48
|
-
process.exit(1);
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
}
|
package/lib/run-builder.d.ts
DELETED
package/lib/run-builder.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.runBuilder = runBuilder;
|
|
16
|
-
const builder_mp_1 = require("@ray-js/builder-mp");
|
|
17
|
-
const builder_web_1 = require("@ray-js/builder-web");
|
|
18
|
-
const shared_1 = require("@ray-js/shared");
|
|
19
|
-
const colors_1 = __importDefault(require("colors"));
|
|
20
|
-
const API_1 = __importDefault(require("./API"));
|
|
21
|
-
colors_1.default.enable();
|
|
22
|
-
const defaultCompileOptions = {
|
|
23
|
-
cwd: process.cwd(),
|
|
24
|
-
source: 'src',
|
|
25
|
-
mode: 'development',
|
|
26
|
-
watch: false,
|
|
27
|
-
target: 'thing',
|
|
28
|
-
mini: false,
|
|
29
|
-
analyze: false,
|
|
30
|
-
devtools: false,
|
|
31
|
-
debug: false,
|
|
32
|
-
output: 'dist',
|
|
33
|
-
};
|
|
34
|
-
function runBuilder(options) {
|
|
35
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
36
|
-
const api = new API_1.default(options);
|
|
37
|
-
// 加载ray.config.ts 或 ray.config.js
|
|
38
|
-
api.loadConfig();
|
|
39
|
-
// 选项优先级:defaultCompileOptions < 配置文件 < 命令行环境变量 < 命令行参数
|
|
40
|
-
const finalOpts = Object.assign({}, defaultCompileOptions, api.config, options);
|
|
41
|
-
const isUndefined = process.env.RAY_DEBUG === undefined;
|
|
42
|
-
// 根据输入配置中注入运行时环境变量
|
|
43
|
-
if (options.debug === undefined) {
|
|
44
|
-
if (isUndefined) {
|
|
45
|
-
if (typeof api.config.debug === 'boolean') {
|
|
46
|
-
process.env.RAY_DEBUG = JSON.stringify(api.config.debug);
|
|
47
|
-
process.env.REMAX_DEBUG = process.env.RAY_DEBUG; // ray-js 依赖 ray-core,因此需根据 ray-js 来设置 ray-core 的 debug 环境变量
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
finalOpts.debug = process.env.RAY_DEBUG === 'true';
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
const { cwd, target, output, onTargetDir } = finalOpts;
|
|
55
|
-
/**
|
|
56
|
-
* 又是历史原因
|
|
57
|
-
* 因老项目生成的产物目录是tuya,所以就干脆是tuya,不然会出现既 tuya 又 thing 的目录
|
|
58
|
-
* 将开发整懵逼
|
|
59
|
-
*/
|
|
60
|
-
const dist = target === 'thing' ? 'tuya' : target;
|
|
61
|
-
// 默认产物会编译到目录${output}/${target}下
|
|
62
|
-
// 某些情况下需要直接编译到 ${output}/下
|
|
63
|
-
// onTargetDir 提供一个修改 output 的方法
|
|
64
|
-
const outputPath = (0, shared_1.resolvePath)(typeof onTargetDir === 'function' ? [onTargetDir(output, dist)] : [output, dist], { cwd });
|
|
65
|
-
finalOpts.output = outputPath;
|
|
66
|
-
api.options = finalOpts;
|
|
67
|
-
shared_1.log.verbose('ray-builder', `final options:`, finalOpts);
|
|
68
|
-
// 加载插件,插件可以是插件的模块路径
|
|
69
|
-
api.loadPlugin();
|
|
70
|
-
// 初始化插件,即执行插件plugin.setup()方法
|
|
71
|
-
api.callPluginMethod('setup');
|
|
72
|
-
const ctx = { api };
|
|
73
|
-
switch (finalOpts.target) {
|
|
74
|
-
// @ts-ignore
|
|
75
|
-
case 'tuya':
|
|
76
|
-
case 'wechat':
|
|
77
|
-
case 'thing':
|
|
78
|
-
yield (0, builder_mp_1.build)(finalOpts, ctx);
|
|
79
|
-
break;
|
|
80
|
-
case 'web':
|
|
81
|
-
yield (0, builder_web_1.build)(finalOpts, ctx);
|
|
82
|
-
break;
|
|
83
|
-
default:
|
|
84
|
-
throw new Error(`Target '${finalOpts.target}' is not supported.'`);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
}
|
package/lib/start.d.ts
DELETED
package/lib/start.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.default = start;
|
|
15
|
-
const run_builder_1 = require("./run-builder");
|
|
16
|
-
function start(options) {
|
|
17
|
-
const { type = 'app' } = options, restOptions = __rest(options, ["type"]);
|
|
18
|
-
if (restOptions.target === 'thing' && restOptions.bundler === 'esbuild') {
|
|
19
|
-
// 使用 raypack 进行构建
|
|
20
|
-
const { build } = require('@ray-js/raypack');
|
|
21
|
-
const opts = {
|
|
22
|
-
cwd: restOptions.cwd,
|
|
23
|
-
watch: true,
|
|
24
|
-
sourceDir: restOptions.source || 'src',
|
|
25
|
-
output: restOptions.output || 'dist/tuya',
|
|
26
|
-
minify: restOptions.mini,
|
|
27
|
-
autoCssModules: false,
|
|
28
|
-
sourcemap: restOptions.sourcemap,
|
|
29
|
-
drop: restOptions.drop,
|
|
30
|
-
analyze: restOptions.analyze,
|
|
31
|
-
};
|
|
32
|
-
build(opts).catch((error) => {
|
|
33
|
-
console.log(error);
|
|
34
|
-
process.exit(101);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
else if (type === 'component') {
|
|
38
|
-
const { build: buildComponent } = require('@ray-js/builder-component');
|
|
39
|
-
buildComponent(Object.assign(Object.assign({}, restOptions), { watch: true })).catch((error) => {
|
|
40
|
-
console.log(error);
|
|
41
|
-
process.exit(1);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
else {
|
|
45
|
-
(0, run_builder_1.runBuilder)(Object.assign(Object.assign({}, options), { watch: true })).catch((error) => {
|
|
46
|
-
console.log(error);
|
|
47
|
-
process.exit(1);
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
}
|