@ray-js/builder-component 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/build.d.ts +1 -0
- package/lib/build.js +32 -17
- package/lib/transform/babelTransform.js +0 -2
- package/lib/transform/index.js +2 -1
- package/lib/transform/type.d.ts +1 -3
- package/lib/transform/type.js +19 -30
- package/package.json +6 -6
package/lib/build.d.ts
CHANGED
@@ -2,6 +2,7 @@ import { CliOptions } from '@ray-js/types';
|
|
2
2
|
declare type Options = Pick<CliOptions, 'source' | 'output' | 'watch'> & {
|
3
3
|
cwd: string;
|
4
4
|
transformMode: 'pure' | 'auto';
|
5
|
+
emitDeclarationDev: boolean;
|
5
6
|
};
|
6
7
|
export default function build(options: Options): Promise<void>;
|
7
8
|
export {};
|
package/lib/build.js
CHANGED
@@ -22,14 +22,32 @@ colors_1.default.enable();
|
|
22
22
|
const LOG_PREFIX = 'builder-component';
|
23
23
|
function build(options) {
|
24
24
|
return __awaiter(this, void 0, void 0, function* () {
|
25
|
-
const { cwd = process.cwd(), source = 'src', output = 'lib', watch = false, transformMode = 'auto', } = options;
|
25
|
+
const { cwd = process.cwd(), source = 'src', output = 'lib', watch = false, transformMode = 'auto', emitDeclarationDev = false, } = options;
|
26
26
|
const sourceDir = path_1.default.join(cwd, source);
|
27
27
|
const outputDir = path_1.default.join(cwd, output);
|
28
|
+
const emitDTS = (0, transform_1.generateDTS)((file, content) => {
|
29
|
+
const fileBase = path_1.default.relative(sourceDir, file);
|
30
|
+
const dtsFilePath = path_1.default.join(outputDir, fileBase);
|
31
|
+
(0, shared_1.writeFileSync)(dtsFilePath, content);
|
32
|
+
shared_1.log.verbose(LOG_PREFIX, fileBase.gray);
|
33
|
+
});
|
34
|
+
function genDTS(files) {
|
35
|
+
const dtsStartTime = Date.now();
|
36
|
+
shared_1.log.info(LOG_PREFIX, 'd.ts generating...'.yellow);
|
37
|
+
emitDTS(files);
|
38
|
+
shared_1.log.info(LOG_PREFIX, 'd.ts done.'.green, Date.now() - dtsStartTime, 'ms');
|
39
|
+
}
|
40
|
+
const files = globby_1.default.sync(['**/*.*', '!**/demos/**/*.*', '!**/__tests__/**/*.*'], {
|
41
|
+
dot: false,
|
42
|
+
cwd: sourceDir,
|
43
|
+
absolute: true,
|
44
|
+
});
|
28
45
|
if (watch) {
|
29
46
|
shared_1.log.info(LOG_PREFIX, 'watching...');
|
30
47
|
const watcher = chokidar_1.default.watch(['**/*.*', '!**/demos/**/*.*', '!**/__tests__/**/*.*', '!**/*.md'], {
|
31
48
|
cwd: sourceDir,
|
32
49
|
});
|
50
|
+
const filesWaitForGenDTS = [...files];
|
33
51
|
watcher.on('all', (event, filePath, _) => __awaiter(this, void 0, void 0, function* () {
|
34
52
|
const file = path_1.default.join(sourceDir, filePath);
|
35
53
|
if (event === 'change' || event === 'add') {
|
@@ -42,6 +60,15 @@ function build(options) {
|
|
42
60
|
}).catch((error) => {
|
43
61
|
console.error(error);
|
44
62
|
});
|
63
|
+
if (emitDeclarationDev) {
|
64
|
+
const index = filesWaitForGenDTS.indexOf(file);
|
65
|
+
if (index === -1) {
|
66
|
+
genDTS([file]);
|
67
|
+
}
|
68
|
+
else {
|
69
|
+
filesWaitForGenDTS.splice(index, 1);
|
70
|
+
}
|
71
|
+
}
|
45
72
|
}
|
46
73
|
else {
|
47
74
|
shared_1.log.warn(`[${event}]`, filePath);
|
@@ -54,13 +81,11 @@ function build(options) {
|
|
54
81
|
}
|
55
82
|
}
|
56
83
|
}));
|
84
|
+
if (emitDeclarationDev) {
|
85
|
+
genDTS(files);
|
86
|
+
}
|
57
87
|
}
|
58
88
|
else {
|
59
|
-
const files = globby_1.default.sync(['**/*.*', '!**/demos/**/*.*', '!**/__tests__/**/*.*'], {
|
60
|
-
dot: false,
|
61
|
-
cwd: sourceDir,
|
62
|
-
absolute: true,
|
63
|
-
});
|
64
89
|
if (!files || files.length === 0) {
|
65
90
|
shared_1.log.error(LOG_PREFIX, 'Not exist any files'.red, cwd);
|
66
91
|
process.exit(0);
|
@@ -76,17 +101,7 @@ function build(options) {
|
|
76
101
|
console.error(error);
|
77
102
|
});
|
78
103
|
}
|
79
|
-
|
80
|
-
shared_1.log.info(LOG_PREFIX, 'd.ts generating...'.yellow);
|
81
|
-
const typeFiles = yield (0, transform_1.generateDTS)(files.filter((file) => /\.tsx?$/.test(file)));
|
82
|
-
for (let index = 0; index < Object.entries(typeFiles).length; index++) {
|
83
|
-
const [dtsFile, content] = Object.entries(typeFiles)[index];
|
84
|
-
const fileBase = path_1.default.relative(sourceDir, dtsFile);
|
85
|
-
const dtsFilePath = path_1.default.join(outputDir, fileBase);
|
86
|
-
(0, shared_1.writeFileSync)(dtsFilePath, content);
|
87
|
-
shared_1.log.verbose(LOG_PREFIX, fileBase.gray);
|
88
|
-
}
|
89
|
-
shared_1.log.info(LOG_PREFIX, 'd.ts done.'.green, Date.now() - dtsStartTime, 'ms');
|
104
|
+
genDTS(files);
|
90
105
|
}
|
91
106
|
});
|
92
107
|
}
|
@@ -25,8 +25,6 @@ function babelTransform(file, options) {
|
|
25
25
|
let code = source;
|
26
26
|
if (options.target) {
|
27
27
|
const { target } = options;
|
28
|
-
process.env.PLATFORM = target;
|
29
|
-
process.env.REMAX_PLATFORM = target;
|
30
28
|
babelPlugin = [
|
31
29
|
[
|
32
30
|
require.resolve('../babel/import-replacement'),
|
package/lib/transform/index.js
CHANGED
@@ -59,6 +59,7 @@ function unlinkPlatformFiles(options) {
|
|
59
59
|
const libFile = path_1.default.join(outputDir, fileBase);
|
60
60
|
if (['.ts', '.tsx', '.js', '.jsx'].includes(fileExt) && fileExt !== '.d.ts') {
|
61
61
|
likePaths.push(replaceExt(libFile, '.js'));
|
62
|
+
likePaths.push(replaceExt(libFile, '.d.ts'));
|
62
63
|
transformTarget.forEach((target) => {
|
63
64
|
likePaths.push(replaceExt(libFile, `.${target}.js`));
|
64
65
|
});
|
@@ -69,7 +70,7 @@ function unlinkPlatformFiles(options) {
|
|
69
70
|
likePaths.filter(fs_extra_1.default.existsSync).map(fs_extra_1.default.unlinkSync);
|
70
71
|
}
|
71
72
|
exports.unlinkPlatformFiles = unlinkPlatformFiles;
|
72
|
-
const PLATFORM_EXTENSION = [...Object.keys(types_1.PlatformTarget), 'mini'
|
73
|
+
const PLATFORM_EXTENSION = [...Object.keys(types_1.PlatformTarget), 'mini'];
|
73
74
|
// 平台文件后缀
|
74
75
|
// .mini.js 是 ray 定义的小程序文件后缀
|
75
76
|
const REGEXP_PLATFORM_EXTENSION = new RegExp(`\\.(?<target>(${PLATFORM_EXTENSION.join('|')}))\\.(ts|js)x?$`);
|
package/lib/transform/type.d.ts
CHANGED
package/lib/transform/type.js
CHANGED
@@ -22,40 +22,29 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
22
|
__setModuleDefault(result, mod);
|
23
23
|
return result;
|
24
24
|
};
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
32
|
-
});
|
33
|
-
};
|
34
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
35
26
|
exports.generateDTS = void 0;
|
36
27
|
const ts = __importStar(require("typescript"));
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
};
|
28
|
+
const options = {
|
29
|
+
allowJs: false,
|
30
|
+
declaration: true,
|
31
|
+
emitDeclarationOnly: true,
|
32
|
+
esModuleInterop: true,
|
33
|
+
target: ts.ScriptTarget.ES5,
|
34
|
+
noUnusedParameters: true,
|
35
|
+
noUnusedLocals: true,
|
36
|
+
strictNullChecks: true,
|
37
|
+
jsx: ts.JsxEmit.Preserve,
|
38
|
+
allowSyntheticDefaultImports: true,
|
39
|
+
};
|
40
|
+
function generateDTS(cb) {
|
41
|
+
const host = ts.createCompilerHost(options);
|
42
|
+
host.writeFile = (fileName, contents) => {
|
43
|
+
cb(fileName, contents);
|
44
|
+
};
|
45
|
+
return (files) => {
|
56
46
|
const program = ts.createProgram(files, options, host);
|
57
47
|
program.emit();
|
58
|
-
|
59
|
-
});
|
48
|
+
};
|
60
49
|
}
|
61
50
|
exports.generateDTS = generateDTS;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@ray-js/builder-component",
|
3
|
-
"version": "0.5.
|
3
|
+
"version": "0.5.5",
|
4
4
|
"description": "Ray builder for component",
|
5
5
|
"keywords": [
|
6
6
|
"ray"
|
@@ -24,10 +24,10 @@
|
|
24
24
|
"@babel/helper-plugin-utils": "^7.14.5",
|
25
25
|
"@babel/traverse": "^7.16.3",
|
26
26
|
"@babel/types": "^7.16.0",
|
27
|
-
"@ray-js/babel-preset-standard": "^0.5.
|
28
|
-
"@ray-js/env-loader": "^0.5.
|
29
|
-
"@ray-js/shared": "^0.5.
|
30
|
-
"@ray-js/types": "^0.5.
|
27
|
+
"@ray-js/babel-preset-standard": "^0.5.5",
|
28
|
+
"@ray-js/env-loader": "^0.5.5",
|
29
|
+
"@ray-js/shared": "^0.5.5",
|
30
|
+
"@ray-js/types": "^0.5.5",
|
31
31
|
"babel-plugin-import": "^1.13.3",
|
32
32
|
"chokidar": "^3.5.2",
|
33
33
|
"colors": "1.4.0",
|
@@ -44,6 +44,6 @@
|
|
44
44
|
"email": "tuyafe@tuya.com"
|
45
45
|
}
|
46
46
|
],
|
47
|
-
"gitHead": "
|
47
|
+
"gitHead": "a8ddeab1f4782e6b3772dc2deeae3e3e3af0de00",
|
48
48
|
"repository": {}
|
49
49
|
}
|