@vyr/cli 0.0.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/default/index.js +74 -0
- package/.bin/index.js +17 -0
- package/.entry/app.js +78575 -0
- package/README.md +168 -0
- package/README.zh-CN.md +169 -0
- package/build/css/1060.a79f9d80.css +1 -0
- package/build/css/1111.7f5086f2.css +1 -0
- package/build/css/1124.b91daf98.css +1 -0
- package/build/css/1583.69c975fc.css +1 -0
- package/build/css/2505.39376622.css +1 -0
- package/build/css/4296.963f15af.css +1 -0
- package/build/css/530.e132216c.css +1 -0
- package/build/css/6357.7bd0168e.css +1 -0
- package/build/css/6827.7d5b54a4.css +1 -0
- package/build/css/6881.972ad8f8.css +1 -0
- package/build/css/8093.21e188eb.css +3 -0
- package/build/css/8743.b91daf98.css +1 -0
- package/build/css/9157.971090af.css +1 -0
- package/build/css/9339.e14b8c45.css +1 -0
- package/build/css/login.de13ff0c.css +1 -0
- package/build/css.worker.js +1 -0
- package/build/deps/locale.js +1 -0
- package/build/deps/socket.js +6 -0
- package/build/editor.worker.js +1 -0
- package/build/favicon.ico +0 -0
- package/build/fonts/codicon.5b7d6fac.ttf +0 -0
- package/build/fonts/iconfont.01dfbc15.ttf +0 -0
- package/build/fonts/iconfont.2e5056cd.woff +0 -0
- package/build/html.worker.js +1 -0
- package/build/index.html +1 -0
- package/build/js/1008.1212a92b.js +1 -0
- package/build/js/1018.094a4eaf.js +1 -0
- package/build/js/1048.959d2b15.js +1 -0
- package/build/js/1060.331f9a15.js +1 -0
- package/build/js/1111.8555bd5c.js +1 -0
- package/build/js/112.43f83ad0.js +1 -0
- package/build/js/1124.4cf01e6d.js +1 -0
- package/build/js/1176.03ce189a.js +1 -0
- package/build/js/1320.11b1f843.js +1 -0
- package/build/js/1346.07f056a0.js +1 -0
- package/build/js/1349.8c9198a0.js +1 -0
- package/build/js/1376.c78b811b.js +1 -0
- package/build/js/1384.330a9809.js +1 -0
- package/build/js/1402.4e06e186.js +1 -0
- package/build/js/150.0eb50ff3.js +1 -0
- package/build/js/1583.e8f36a93.js +1 -0
- package/build/js/1592.2007c851.js +1 -0
- package/build/js/1696.67999338.js +7 -0
- package/build/js/1704.a712bcfe.js +1 -0
- package/build/js/1877.41a30a46.js +1 -0
- package/build/js/1978.d78b7ff2.js +1 -0
- package/build/js/2024.61ad4ff8.js +1 -0
- package/build/js/2132.0f13c789.js +1 -0
- package/build/js/220.332f13be.js +1 -0
- package/build/js/2264.74826096.js +1 -0
- package/build/js/2320.01b45f7e.js +1 -0
- package/build/js/2328.91f4fab2.js +1 -0
- package/build/js/2424.1b901127.js +1 -0
- package/build/js/2472.fd550726.js +1 -0
- package/build/js/250.369da5c4.js +1 -0
- package/build/js/2505.b43421df.js +1 -0
- package/build/js/2521.64e8a1c3.js +1 -0
- package/build/js/2576.af7b57dd.js +1 -0
- package/build/js/2674.a0fefa3b.js +1 -0
- package/build/js/2808.2a6f1a99.js +1 -0
- package/build/js/2868.2c921d66.js +1 -0
- package/build/js/2958.148f2f28.js +1 -0
- package/build/js/3084.f01b8161.js +1 -0
- package/build/js/3124.865bbeea.js +1 -0
- package/build/js/3160.ad6a00b2.js +1 -0
- package/build/js/3328.0e752372.js +1 -0
- package/build/js/3416.59bed435.js +1 -0
- package/build/js/3454.fc17644a.js +1 -0
- package/build/js/3507.aafa886d.js +1 -0
- package/build/js/3785.151db669.js +1 -0
- package/build/js/3792.c95b5a4d.js +1 -0
- package/build/js/3944.0eafa506.js +1 -0
- package/build/js/4040.bd29cbd3.js +1 -0
- package/build/js/4124.1c353188.js +1 -0
- package/build/js/4171.ecaed70c.js +1 -0
- package/build/js/4196.1ecc5bb3.js +1 -0
- package/build/js/4230.d1f2577c.js +1 -0
- package/build/js/4263.870a448a.js +1 -0
- package/build/js/4288.cfaa98a7.js +1 -0
- package/build/js/4291.cea6a8d5.js +12 -0
- package/build/js/4296.634b3fe2.js +1 -0
- package/build/js/4416.8faeee6a.js +1 -0
- package/build/js/4490.afacfe53.js +1 -0
- package/build/js/4530.60b7c78d.js +1 -0
- package/build/js/4570.312d27c5.js +1 -0
- package/build/js/4582.a686fadd.js +1 -0
- package/build/js/4587.9701b203.js +1 -0
- package/build/js/4744.fb66347f.js +1 -0
- package/build/js/4764.df45c000.js +1 -0
- package/build/js/4786.89599e34.js +1 -0
- package/build/js/4816.cd55469f.js +1 -0
- package/build/js/4872.0bafb3d5.js +1 -0
- package/build/js/4900.cdee80ca.js +1 -0
- package/build/js/530.b4e0e136.js +1 -0
- package/build/js/5354.9e7d2a59.js +1 -0
- package/build/js/5388.ba7b29bd.js +1 -0
- package/build/js/5620.4ebcd1ef.js +1 -0
- package/build/js/5639.7661231d.js +1 -0
- package/build/js/5694.4e720480.js +1 -0
- package/build/js/5696.1ec004f6.js +5 -0
- package/build/js/5768.ff6d1da1.js +1 -0
- package/build/js/5788.fb009553.js +1 -0
- package/build/js/5804.a7530102.js +1 -0
- package/build/js/5888.e88a2170.js +1 -0
- package/build/js/5918.fd8226fe.js +1 -0
- package/build/js/6136.a7604e8a.js +1 -0
- package/build/js/6166.c3ca51e8.js +1 -0
- package/build/js/6234.8760a038.js +1 -0
- package/build/js/6248.d7c77c1a.js +1 -0
- package/build/js/6308.358e0a94.js +1 -0
- package/build/js/6315.81f5e202.js +7 -0
- package/build/js/6357.1354eb2c.js +1 -0
- package/build/js/6476.133083f0.js +1 -0
- package/build/js/6488.a1bb6380.js +1 -0
- package/build/js/6552.af7ecaa3.js +1 -0
- package/build/js/6600.66570635.js +1 -0
- package/build/js/6720.7e4d97d6.js +1 -0
- package/build/js/677.618fc137.js +1 -0
- package/build/js/6827.62f794a0.js +1 -0
- package/build/js/6881.e7455ee6.js +1 -0
- package/build/js/6937.53af487b.js +1 -0
- package/build/js/6968.07bbc3cd.js +1 -0
- package/build/js/7128.bddbefa5.js +1 -0
- package/build/js/7132.784f034a.js +1 -0
- package/build/js/7167.ba37f9e6.js +1 -0
- package/build/js/7195.7a9c1589.js +1 -0
- package/build/js/7227.9320ac5b.js +7 -0
- package/build/js/7380.378a750c.js +1 -0
- package/build/js/7390.cb73108e.js +6 -0
- package/build/js/7409.871dc004.js +7 -0
- package/build/js/7494.0fecaf55.js +1 -0
- package/build/js/7692.217959b6.js +1 -0
- package/build/js/7713.e38c75be.js +1 -0
- package/build/js/7769.15f4d355.js +1 -0
- package/build/js/7820.84cbe06d.js +1 -0
- package/build/js/7960.6e25b569.js +1 -0
- package/build/js/7980.816096c5.js +1 -0
- package/build/js/800.7696b6c7.js +1 -0
- package/build/js/8004.80b538a1.js +1 -0
- package/build/js/8030.70f27b26.js +1 -0
- package/build/js/8093.b4466960.js +3 -0
- package/build/js/8328.d2170039.js +1 -0
- package/build/js/8344.e4b1e024.js +1 -0
- package/build/js/8366.2854dcb7.js +1 -0
- package/build/js/8438.72c0fcbf.js +1 -0
- package/build/js/8550.69a717cc.js +1 -0
- package/build/js/8554.1dbe7424.js +1 -0
- package/build/js/8632.da334e90.js +1 -0
- package/build/js/8637.20577619.js +1 -0
- package/build/js/8657.d3a8799b.js +1 -0
- package/build/js/8743.2cffd0be.js +1 -0
- package/build/js/88.4db81116.js +1 -0
- package/build/js/8856.9f70af00.js +1 -0
- package/build/js/9020.b3a4d09b.js +1 -0
- package/build/js/9044.73639ece.js +1 -0
- package/build/js/9157.58a8fa2d.js +1 -0
- package/build/js/9256.85fca918.js +1 -0
- package/build/js/931.88800e05.js +1 -0
- package/build/js/9339.d75f7c2e.js +1 -0
- package/build/js/9384.adddd8c7.js +1 -0
- package/build/js/94.59ed492b.js +1 -0
- package/build/js/9620.e7e75a12.js +1 -0
- package/build/js/9751.8b76fab5.js +1 -0
- package/build/js/9842.d1ed9070.js +1 -0
- package/build/js/9947.e172d61d.js +1 -0
- package/build/js/chunk-vendors.fea3dfe0.js +24 -0
- package/build/js/index.b935de87.js +1 -0
- package/build/js/login.1488a09a.js +1 -0
- package/build/js/preview.6c550af7.js +1 -0
- package/build/json.worker.js +1 -0
- package/build/login.html +1 -0
- package/build/logo//344/270/273LOGO.png +0 -0
- package/build/logo//344/270/273/345/233/276/346/240/207.png +0 -0
- package/build/logo//344/270/273/346/226/271/345/275/242.png +0 -0
- package/build/logo//347/201/260/345/272/246LOGO.png +0 -0
- package/build/logo//351/200/217/346/230/216/345/233/276/346/240/207.png +0 -0
- package/build/logo//351/200/217/346/230/216/350/203/214/346/231/257LOGO.png +0 -0
- package/build/preview.html +1 -0
- package/build/ts.worker.js +6 -0
- package/pack/auto-provider-plugin/index.js +38 -0
- package/pack/auto-provider-plugin/loader.js +53 -0
- package/pack/auto-provider-plugin/package.json +8 -0
- package/pack/class-wrapper-plugin/index.js +42 -0
- package/pack/class-wrapper-plugin/loaders/descriptor.js +89 -0
- package/pack/class-wrapper-plugin/loaders/dynamic-interpreter.js +54 -0
- package/pack/class-wrapper-plugin/loaders/index.js +30 -0
- package/pack/class-wrapper-plugin/loaders/input-system.js +31 -0
- package/pack/class-wrapper-plugin/loaders/object-pool.js +79 -0
- package/pack/class-wrapper-plugin/package.json +8 -0
- package/pack/class-wrapper-plugin/utils.js +79 -0
- package/pack/rollup-config-plugin/build/index.d.ts +3 -0
- package/pack/rollup-config-plugin/build/index.js +34 -0
- package/pack/rollup-config-plugin/package.json +8 -0
- package/pack/rollup-config-plugin/src/index.ts +47 -0
- package/pack/rollup-config-plugin/tsconfig.json +31 -0
- package/pack/var-rename-plugin/index.js +74 -0
- package/pack/var-rename-plugin/package.json +8 -0
- package/package.json +83 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const { resolve, join } = require("path")
|
|
2
|
+
|
|
3
|
+
class AutoProviderPlugin {
|
|
4
|
+
|
|
5
|
+
constructor(entrys) {
|
|
6
|
+
this.entrys = entrys.map(entry => join(process.cwd(), entry))
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
validate(path) {
|
|
10
|
+
for (const entry of this.entrys) {
|
|
11
|
+
if (path.indexOf(entry) > -1) return true
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return false
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
provider(module) {
|
|
18
|
+
const custom = {
|
|
19
|
+
loader: resolve(__dirname, './loader'),
|
|
20
|
+
options: JSON.stringify({})
|
|
21
|
+
}
|
|
22
|
+
module.loaders.push(custom)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
compiler(module) {
|
|
26
|
+
if (!module.request) return
|
|
27
|
+
if (this.validate(module.request) === false) return
|
|
28
|
+
this.provider(module)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
apply(compiler) {
|
|
32
|
+
compiler.hooks.compilation.tap('auto-provider-plugin', (compilation) => {
|
|
33
|
+
compilation.hooks.buildModule.tap('auto-provider-plugin', (module) => this.compiler(module))
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = AutoProviderPlugin
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
const editorConfig = require('../../editor.config.json')
|
|
2
|
+
|
|
3
|
+
const extensions = [
|
|
4
|
+
editorConfig.browser.runtime,
|
|
5
|
+
...editorConfig.browser.extensions,
|
|
6
|
+
...editorConfig.browser.remote,
|
|
7
|
+
...editorConfig.browser.services.map(service => service.name),
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
module.exports = function (source) {
|
|
11
|
+
const options = this.getOptions()
|
|
12
|
+
|
|
13
|
+
const imports = [
|
|
14
|
+
`import axios from 'axios'`,
|
|
15
|
+
`import { Locale } from '@vyr/locale'`,
|
|
16
|
+
`const libs = [`,
|
|
17
|
+
]
|
|
18
|
+
for (let i = 0; i < extensions.length; i++) {
|
|
19
|
+
const extension = extensions[i]
|
|
20
|
+
imports.push(` { name:'__VYR_RUNTIME_${extension}',load:async () => import('${extension}')},`)
|
|
21
|
+
}
|
|
22
|
+
imports.push(`]`)
|
|
23
|
+
|
|
24
|
+
const codes = [
|
|
25
|
+
`const getConfig = async()=> {`,
|
|
26
|
+
` const res = await axios.get('/cli/getConfig')`,
|
|
27
|
+
` return res.data`,
|
|
28
|
+
`}`,
|
|
29
|
+
`const extensions = {}`,
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
codes.push(
|
|
33
|
+
`const loadExtensions = async () => {`,
|
|
34
|
+
` const config = await getConfig()`,
|
|
35
|
+
` for(const provider of config.languageProviders) Locale.register(provider)`,
|
|
36
|
+
` Locale.use(config.language)`,
|
|
37
|
+
` const tasks = []`,
|
|
38
|
+
` for (const lib of libs) {`,
|
|
39
|
+
` const task = lib.load().then(res => window[lib.name] = res)`,
|
|
40
|
+
` tasks.push(task)`,
|
|
41
|
+
` } `,
|
|
42
|
+
` await Promise.all(tasks)`,
|
|
43
|
+
` return config`,
|
|
44
|
+
`}`,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
const code = source
|
|
48
|
+
.replace('//__VYR_IMPORT', imports.join('\n'))
|
|
49
|
+
.replace('//__VYR_DEFINE', codes.join('\n'))
|
|
50
|
+
.replace('//__VYR_CONFIG', `const config = await loadExtensions()`)
|
|
51
|
+
|
|
52
|
+
return code
|
|
53
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const { join, resolve } = require("path")
|
|
2
|
+
|
|
3
|
+
class ClassWrapperPlugin {
|
|
4
|
+
|
|
5
|
+
constructor(rules = []) {
|
|
6
|
+
const handlers = [
|
|
7
|
+
{ path: join(__dirname, '../../packages/universal/engine'), className: 'ObjectPool' },
|
|
8
|
+
{ path: join(__dirname, '../../packages/universal/engine'), className: 'Descriptor' },
|
|
9
|
+
{ path: join(__dirname, '../../packages/universal/engine'), className: 'InputSystem' },
|
|
10
|
+
{ path: join(__dirname, '../../packages/universal/engine'), className: 'DynamicInterpreter' },
|
|
11
|
+
]
|
|
12
|
+
this.rules = handlers.filter(handler => rules.includes(handler.className))
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
validate(path) {
|
|
16
|
+
for (const rule of this.rules) {
|
|
17
|
+
if (path.indexOf(rule.path) > -1 && path.indexOf(rule.className) > -1) return rule
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
wrapper(module, rule) {
|
|
22
|
+
const custom = {
|
|
23
|
+
loader: resolve(__dirname, './loaders/index'),
|
|
24
|
+
options: JSON.stringify({ className: rule.className })
|
|
25
|
+
}
|
|
26
|
+
module.loaders.push(custom)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
compiler(module) {
|
|
30
|
+
if (!module.request) return
|
|
31
|
+
const rule = this.validate(module.request)
|
|
32
|
+
if (rule) return this.wrapper(module, rule)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
apply(compiler) {
|
|
36
|
+
compiler.hooks.compilation.tap('class-wrapper-plugin', (compilation) => {
|
|
37
|
+
compilation.hooks.buildModule.tap('class-wrapper-plugin', (module) => this.compiler(module))
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports = ClassWrapperPlugin
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
const types = require('@babel/types');
|
|
2
|
+
const { default: traverse } = require('@babel/traverse')
|
|
3
|
+
const { vueImportDeclaration, wrapperDeclaration, wrapperIdentifier, wrapperCall, returnwrapper } = require('../utils')
|
|
4
|
+
|
|
5
|
+
const pushRetuenStatement = (block) => {
|
|
6
|
+
// 假设block是一个BlockStatement节点
|
|
7
|
+
if (!types.isBlockStatement(block)) return
|
|
8
|
+
// 获取BlockStatement的最后一个语句
|
|
9
|
+
const lastStatement = block.body[block.body.length - 1];
|
|
10
|
+
// 检查这个语句是否是ReturnStatement
|
|
11
|
+
if (types.isReturnStatement(lastStatement)) return
|
|
12
|
+
//添加 return 语句
|
|
13
|
+
block.body.push(returnwrapper)
|
|
14
|
+
}
|
|
15
|
+
const wrapperConstructor = (p) => {
|
|
16
|
+
p.traverse({
|
|
17
|
+
CallExpression(path) {
|
|
18
|
+
if (
|
|
19
|
+
types.isMemberExpression(path.node.callee) &&
|
|
20
|
+
path.node.callee.object.type === 'ThisExpression' &&
|
|
21
|
+
path.node.callee.property.name === 'add'
|
|
22
|
+
) {
|
|
23
|
+
|
|
24
|
+
const newCallee = types.memberExpression(wrapperCall, types.identifier('add'));
|
|
25
|
+
path.node.callee = newCallee;
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
ReturnStatement(path) {
|
|
29
|
+
path.replaceWith(returnwrapper)
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
pushRetuenStatement(p.node.body)
|
|
33
|
+
p.stop()
|
|
34
|
+
}
|
|
35
|
+
const validateConstructor = (p, options) => {
|
|
36
|
+
if (types.isClassMethod(p.node) === false) return false
|
|
37
|
+
if (p.node.kind !== 'constructor') return false
|
|
38
|
+
return p.parentPath.parent.id.name === options.className
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const wrapperMethod = (p) => {
|
|
42
|
+
const instance = p.node.params[0]
|
|
43
|
+
p.traverse({
|
|
44
|
+
MemberExpression(path) {
|
|
45
|
+
if (
|
|
46
|
+
path.node.object.type === 'Identifier' &&
|
|
47
|
+
path.node.object.name === 'instance' &&
|
|
48
|
+
!path.parentPath.isMemberExpression()
|
|
49
|
+
) {
|
|
50
|
+
const vueCallInstance = types.callExpression(wrapperIdentifier, [instance]);
|
|
51
|
+
const newMemberExpression = types.memberExpression(vueCallInstance, path.node.property);
|
|
52
|
+
path.replaceWith(newMemberExpression);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
p.stop()
|
|
57
|
+
}
|
|
58
|
+
const validateMethod = (p, options) => {
|
|
59
|
+
if (types.isClassMethod(p.node) === false) return false
|
|
60
|
+
if (p.node.kind !== 'method') return false
|
|
61
|
+
if (p.node.key.name !== 'beenInstantiated') return false
|
|
62
|
+
return p.parentPath.parent.id.name === options.className
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const wrapperDescriptor = (ast, options) => {
|
|
66
|
+
//添加导入语句
|
|
67
|
+
ast.program.body.splice(2, 0, vueImportDeclaration)
|
|
68
|
+
ast.program.body.splice(3, 0, wrapperDeclaration)
|
|
69
|
+
|
|
70
|
+
traverse(ast, {
|
|
71
|
+
enter: (p) => {
|
|
72
|
+
if (validateConstructor(p, options)) wrapperConstructor(p)
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
traverse(ast, {
|
|
77
|
+
enter: (p) => {
|
|
78
|
+
if (validateMethod(p, options)) wrapperMethod(p)
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
const validateDescriptor = (options) => {
|
|
83
|
+
return options.className === 'Descriptor'
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
module.exports = {
|
|
87
|
+
wrapperDescriptor,
|
|
88
|
+
validateDescriptor,
|
|
89
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const types = require('@babel/types');
|
|
2
|
+
const { parse } = require('@babel/parser')
|
|
3
|
+
const { default: traverse } = require('@babel/traverse')
|
|
4
|
+
|
|
5
|
+
const wrapperMethod = (p) => {
|
|
6
|
+
const newCode = `
|
|
7
|
+
function checkCode(){
|
|
8
|
+
if (this._currentDepth > 3000) {
|
|
9
|
+
observer.trigger('__VYR_RUNTIME@remote', { type: 'Dynamic', uuid: this.unit.uuid })
|
|
10
|
+
return
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
`;
|
|
14
|
+
|
|
15
|
+
// 解析新代码为AST
|
|
16
|
+
const newAst = parse(newCode, {
|
|
17
|
+
sourceType: 'module',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// 获取函数声明中的函数体语句
|
|
21
|
+
const functionDeclaration = newAst.program.body[0];
|
|
22
|
+
const functionBodyStatements = functionDeclaration.body.body;
|
|
23
|
+
|
|
24
|
+
// 获取目标方法体的语句数组
|
|
25
|
+
const methodBody = p.node.body.body;
|
|
26
|
+
|
|
27
|
+
// 将函数体中的语句插入到目标方法体的开头
|
|
28
|
+
methodBody.unshift(...functionBodyStatements);
|
|
29
|
+
|
|
30
|
+
p.stop()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const validateMethod = (p, options) => {
|
|
34
|
+
if (types.isClassMethod(p.node) === false) return false
|
|
35
|
+
if (p.node.kind !== 'method') return false
|
|
36
|
+
if (p.node.key.name !== '_markSubDynamic') return false
|
|
37
|
+
return p.parentPath.parent.id.name === options.className
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const wrapperDynamicInterpreter = (ast, options) => {
|
|
41
|
+
traverse(ast, {
|
|
42
|
+
enter: (p) => {
|
|
43
|
+
if (validateMethod(p, options)) wrapperMethod(p)
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
const validateDynamicInterpreter = (options) => {
|
|
48
|
+
return options.className === 'DynamicInterpreter'
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports = {
|
|
52
|
+
wrapperDynamicInterpreter,
|
|
53
|
+
validateDynamicInterpreter,
|
|
54
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const { parse } = require('@babel/parser')
|
|
2
|
+
const { default: generate } = require('@babel/generator');
|
|
3
|
+
const { validateObjectPool, wrapperObjectPool } = require('./object-pool');
|
|
4
|
+
const { validateDescriptor, wrapperDescriptor } = require('./descriptor');
|
|
5
|
+
const { validateInputSystem, wrapperInputSystem } = require('./input-system');
|
|
6
|
+
const { validateDynamicInterpreter, wrapperDynamicInterpreter } = require('./dynamic-interpreter')
|
|
7
|
+
|
|
8
|
+
const wrappers = [
|
|
9
|
+
{ validate: validateObjectPool, executor: wrapperObjectPool },
|
|
10
|
+
{ validate: validateDescriptor, executor: wrapperDescriptor },
|
|
11
|
+
{ validate: validateInputSystem, executor: wrapperInputSystem },
|
|
12
|
+
{ validate: validateDynamicInterpreter, executor: wrapperDynamicInterpreter },
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
module.exports = function (source) {
|
|
16
|
+
const options = this.getOptions()
|
|
17
|
+
|
|
18
|
+
const ast = parse(source, { sourceType: 'module', plugins: ['typescript'] })
|
|
19
|
+
|
|
20
|
+
for (const wrapper of wrappers) {
|
|
21
|
+
if (wrapper.validate(options)) {
|
|
22
|
+
wrapper.executor(ast, options)
|
|
23
|
+
break
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const { code } = generate(ast, { retainLines: false, concise: false, jsescOption: { minimal: true, sourceType: 'module' } })
|
|
28
|
+
|
|
29
|
+
return code
|
|
30
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const types = require("@babel/types");
|
|
2
|
+
const { default: traverse } = require("@babel/traverse");
|
|
3
|
+
const { ifInputSystemStatement } = require("../utils");
|
|
4
|
+
|
|
5
|
+
const wrapperMethod = (p) => {
|
|
6
|
+
p.node.body.body.unshift(ifInputSystemStatement);
|
|
7
|
+
p.stop();
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const validateMethod = (p, options) => {
|
|
11
|
+
if (types.isClassMethod(p.node) === false) return false;
|
|
12
|
+
if (p.node.kind !== "method") return false;
|
|
13
|
+
if (p.node.key.name !== "listen") return false;
|
|
14
|
+
return p.parentPath.parent.id.name === options.className;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const wrapperInputSystem = (ast, options) => {
|
|
18
|
+
const onEnter = (p) => {
|
|
19
|
+
if (validateMethod(p, options)) wrapperMethod(p);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
traverse(ast, { enter: onEnter });
|
|
23
|
+
};
|
|
24
|
+
const validateInputSystem = (options) => {
|
|
25
|
+
return options.className === "InputSystem";
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
module.exports = {
|
|
29
|
+
wrapperInputSystem,
|
|
30
|
+
validateInputSystem,
|
|
31
|
+
};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
const types = require('@babel/types');
|
|
2
|
+
const { default: traverse } = require('@babel/traverse')
|
|
3
|
+
const { vueImportDeclaration, wrapperDeclaration, wrapperIdentifier } = require('../utils')
|
|
4
|
+
|
|
5
|
+
const replaceMethodGet = (path) => {
|
|
6
|
+
const left = path.node.argument.left;
|
|
7
|
+
const right = path.node.argument.right;
|
|
8
|
+
if (types.isNullLiteral(right)) {
|
|
9
|
+
// 提取 instance.deref() 表达式
|
|
10
|
+
const derefCall = left;
|
|
11
|
+
// 创建 const ref = instance.deref(); 语句
|
|
12
|
+
const refDeclaration = types.variableDeclaration('const', [
|
|
13
|
+
types.variableDeclarator(
|
|
14
|
+
types.identifier('ref'),
|
|
15
|
+
derefCall
|
|
16
|
+
)
|
|
17
|
+
]);
|
|
18
|
+
// 创建 ref? v(ref) : null; 表达式
|
|
19
|
+
const conditionalExpression = types.conditionalExpression(
|
|
20
|
+
types.identifier('ref'),
|
|
21
|
+
types.callExpression(wrapperIdentifier, [types.identifier('ref')]),
|
|
22
|
+
types.nullLiteral()
|
|
23
|
+
);
|
|
24
|
+
// 替换原语句
|
|
25
|
+
path.replaceWith(refDeclaration);
|
|
26
|
+
path.insertAfter(types.returnStatement(conditionalExpression))
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const wrapperMethod = (p, method) => {
|
|
31
|
+
p.traverse({
|
|
32
|
+
CallExpression(path) {
|
|
33
|
+
const { node } = path;
|
|
34
|
+
|
|
35
|
+
// 检查是否是 instance.deref() 调用
|
|
36
|
+
if (types.isMemberExpression(node.callee) &&
|
|
37
|
+
types.isIdentifier(node.callee.property, { name: "deref" }) &&
|
|
38
|
+
types.isIdentifier(node.callee.object, { name: "instance" }) &&
|
|
39
|
+
node.arguments.length === 0) {
|
|
40
|
+
|
|
41
|
+
const wrappedCall = types.callExpression(
|
|
42
|
+
wrapperIdentifier,
|
|
43
|
+
[node]
|
|
44
|
+
);
|
|
45
|
+
path.replaceWith(wrappedCall);
|
|
46
|
+
|
|
47
|
+
path.skip();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
const validateMethod = (p, options) => {
|
|
53
|
+
if (types.isClassMethod(p.node) === false) return false
|
|
54
|
+
if (p.node.static === false) return false
|
|
55
|
+
if (p.parentPath.parent.id.name !== options.className) return
|
|
56
|
+
return ['get'].includes(p.node.key.name) ? p.node.key.name : false
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const wrapperObjectPool = (ast, options) => {
|
|
60
|
+
//添加导入语句
|
|
61
|
+
ast.program.body.splice(2, 0, vueImportDeclaration)
|
|
62
|
+
ast.program.body.splice(3, 0, wrapperDeclaration)
|
|
63
|
+
|
|
64
|
+
traverse(ast, {
|
|
65
|
+
enter: (p) => {
|
|
66
|
+
const result = validateMethod(p, options)
|
|
67
|
+
if (result === false) return
|
|
68
|
+
wrapperMethod(p, result)
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
const validateObjectPool = (options) => {
|
|
73
|
+
return options.className === 'ObjectPool'
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
module.exports = {
|
|
77
|
+
wrapperObjectPool,
|
|
78
|
+
validateObjectPool,
|
|
79
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
const types = require('@babel/types');
|
|
2
|
+
|
|
3
|
+
// 创建具名导入的标识符
|
|
4
|
+
const reactiveIdentifier = types.identifier("reactive")
|
|
5
|
+
|
|
6
|
+
// 构建 import { reactive } from 'vue'
|
|
7
|
+
const vueImportDeclaration = types.importDeclaration(
|
|
8
|
+
[
|
|
9
|
+
types.importSpecifier(
|
|
10
|
+
reactiveIdentifier, // 导入的变量名
|
|
11
|
+
reactiveIdentifier // 如果重命名,可以用 types.identifier('newName')
|
|
12
|
+
)
|
|
13
|
+
],
|
|
14
|
+
types.stringLiteral('vue')
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
// 1. 构建条件表达式 (window['Runtime'] === 'editor')
|
|
18
|
+
const windowRuntime = types.memberExpression(
|
|
19
|
+
types.identifier('window'),
|
|
20
|
+
types.stringLiteral('__VYR_RUNTIME_MODE'),
|
|
21
|
+
true // computed: true 因使用方括号访问
|
|
22
|
+
);
|
|
23
|
+
const runtimeCheck = types.binaryExpression(
|
|
24
|
+
'===',
|
|
25
|
+
windowRuntime,
|
|
26
|
+
types.stringLiteral('editor')
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
// 2. 构建 reactive 调用 (reactive(raw))
|
|
30
|
+
const reactiveCall = types.callExpression(reactiveIdentifier, [types.identifier('raw')])
|
|
31
|
+
|
|
32
|
+
// 3. 组装三元表达式
|
|
33
|
+
const conditionalExpr = types.conditionalExpression(
|
|
34
|
+
runtimeCheck,
|
|
35
|
+
reactiveCall,
|
|
36
|
+
types.identifier('raw') // 直接返回 raw
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
// 4. 构建箭头函数体
|
|
40
|
+
const returnStatement = types.returnStatement(conditionalExpr);
|
|
41
|
+
const functionBody = types.blockStatement([returnStatement]);
|
|
42
|
+
|
|
43
|
+
// 5. 创建箭头函数表达式
|
|
44
|
+
const arrowFunction = types.arrowFunctionExpression(
|
|
45
|
+
[types.identifier('raw')], // 参数列表
|
|
46
|
+
functionBody
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
// 6. 组装变量声明
|
|
50
|
+
const wrapperIdentifier = types.identifier('wrapper');
|
|
51
|
+
const wrapperDeclarator = types.variableDeclarator(wrapperIdentifier, arrowFunction)
|
|
52
|
+
const wrapperDeclaration = types.variableDeclaration('const', [wrapperDeclarator])
|
|
53
|
+
const wrapperCall = types.callExpression(wrapperIdentifier, [types.thisExpression()])
|
|
54
|
+
const returnwrapper = types.returnStatement(wrapperCall);
|
|
55
|
+
|
|
56
|
+
const inputRuntime = types.memberExpression(
|
|
57
|
+
types.identifier('window'),
|
|
58
|
+
types.stringLiteral('__VYR_RUNTIME.DISABLED_INPUT'),
|
|
59
|
+
true
|
|
60
|
+
);
|
|
61
|
+
const disabledInputSystem = types.binaryExpression(
|
|
62
|
+
"===",
|
|
63
|
+
inputRuntime,
|
|
64
|
+
types.booleanLiteral(true)
|
|
65
|
+
)
|
|
66
|
+
const ifInputSystemStatement = types.ifStatement(
|
|
67
|
+
disabledInputSystem,
|
|
68
|
+
types.returnStatement(),
|
|
69
|
+
null
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
module.exports = {
|
|
73
|
+
vueImportDeclaration,
|
|
74
|
+
wrapperDeclaration,
|
|
75
|
+
wrapperIdentifier,
|
|
76
|
+
wrapperCall,
|
|
77
|
+
returnwrapper,
|
|
78
|
+
ifInputSystemStatement,
|
|
79
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createRollupConfigFactory = exports.getRollupConfigContent = void 0;
|
|
4
|
+
const fs = require('fs-extra');
|
|
5
|
+
const getRollupConfigContent = (outputFile, input, outputPath, external) => {
|
|
6
|
+
const configObj = {};
|
|
7
|
+
const config = [
|
|
8
|
+
`{`,
|
|
9
|
+
` input: ${JSON.stringify(input)},`,
|
|
10
|
+
` output: {`,
|
|
11
|
+
` file: ${JSON.stringify(outputPath)},`,
|
|
12
|
+
` format: 'cjs',`,
|
|
13
|
+
` inlineDynamicImports: true,`,
|
|
14
|
+
` },`,
|
|
15
|
+
` external: ${JSON.stringify(external)},`,
|
|
16
|
+
` plugins: [`,
|
|
17
|
+
` nodeResolve({ preferBuiltins: true}),`,
|
|
18
|
+
` commonjs({ ignoreDynamicRequires: true }),`,
|
|
19
|
+
` esbuild(${JSON.stringify(configObj)}),`,
|
|
20
|
+
` varRename(${JSON.stringify(external)}, ${JSON.stringify(outputFile)}),`,
|
|
21
|
+
` json(),`,
|
|
22
|
+
` postcss({ extract: false, minimize: true })`,
|
|
23
|
+
` ],`,
|
|
24
|
+
` treeshake: false,`,
|
|
25
|
+
`}`,
|
|
26
|
+
].join('\n');
|
|
27
|
+
return config;
|
|
28
|
+
};
|
|
29
|
+
exports.getRollupConfigContent = getRollupConfigContent;
|
|
30
|
+
const createRollupConfigFactory = (config) => {
|
|
31
|
+
const factory = new Function('nodeResolve', 'commonjs', 'json', 'postcss', 'esbuild', 'varRename', `return ${config}`);
|
|
32
|
+
return factory;
|
|
33
|
+
};
|
|
34
|
+
exports.createRollupConfigFactory = createRollupConfigFactory;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const fs = require('fs-extra')
|
|
2
|
+
|
|
3
|
+
const getRollupConfigContent = (outputFile: string, input: string, outputPath: string, external: string[]) => {
|
|
4
|
+
const configObj = {
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const config = [
|
|
8
|
+
`{`,
|
|
9
|
+
` input: ${JSON.stringify(input)},`,
|
|
10
|
+
` output: {`,
|
|
11
|
+
` file: ${JSON.stringify(outputPath)},`,
|
|
12
|
+
` format: 'cjs',`,
|
|
13
|
+
` inlineDynamicImports: true,`,
|
|
14
|
+
` },`,
|
|
15
|
+
` external: ${JSON.stringify(external)},`,
|
|
16
|
+
` plugins: [`,
|
|
17
|
+
` nodeResolve({ preferBuiltins: true}),`,
|
|
18
|
+
` commonjs({ ignoreDynamicRequires: true }),`,
|
|
19
|
+
` esbuild(${JSON.stringify(configObj)}),`,
|
|
20
|
+
` varRename(${JSON.stringify(external)}, ${JSON.stringify(outputFile)}),`,
|
|
21
|
+
` json(),`,
|
|
22
|
+
` postcss({ extract: false, minimize: true })`,
|
|
23
|
+
` ],`,
|
|
24
|
+
` treeshake: false,`,
|
|
25
|
+
`}`,
|
|
26
|
+
].join('\n')
|
|
27
|
+
|
|
28
|
+
return config
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const createRollupConfigFactory = (config: string) => {
|
|
32
|
+
const factory = new Function(
|
|
33
|
+
'nodeResolve',
|
|
34
|
+
'commonjs',
|
|
35
|
+
'json',
|
|
36
|
+
'postcss',
|
|
37
|
+
'esbuild',
|
|
38
|
+
'varRename',
|
|
39
|
+
`return ${config}`)
|
|
40
|
+
|
|
41
|
+
return factory
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export {
|
|
45
|
+
getRollupConfigContent,
|
|
46
|
+
createRollupConfigFactory,
|
|
47
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"module": "CommonJS",
|
|
5
|
+
"moduleResolution": "node",
|
|
6
|
+
"lib": [
|
|
7
|
+
"ESNext",
|
|
8
|
+
"DOM",
|
|
9
|
+
"DOM.Iterable"
|
|
10
|
+
],
|
|
11
|
+
"outDir": "build",
|
|
12
|
+
"strict": true,
|
|
13
|
+
"jsx": "preserve",
|
|
14
|
+
"declaration": true,
|
|
15
|
+
"skipLibCheck": true,
|
|
16
|
+
"esModuleInterop": true,
|
|
17
|
+
"allowSyntheticDefaultImports": true,
|
|
18
|
+
"forceConsistentCasingInFileNames": true,
|
|
19
|
+
"useDefineForClassFields": true,
|
|
20
|
+
"sourceMap": false,
|
|
21
|
+
"baseUrl": "",
|
|
22
|
+
"types": [
|
|
23
|
+
"webpack-env"
|
|
24
|
+
],
|
|
25
|
+
"paths": {}
|
|
26
|
+
},
|
|
27
|
+
"include": [
|
|
28
|
+
"src/**/*.ts",
|
|
29
|
+
],
|
|
30
|
+
"exclude": []
|
|
31
|
+
}
|