diff --git a/packages/chameleon-tool-utils/src/index.js b/packages/chameleon-tool-utils/src/index.js
index 846e78d5446db253203bbcde0cb06ea75e0ea5dc..9989645a44bc78f35dc762ec7b1bdcc1fb2bdcde 100644
--- a/packages/chameleon-tool-utils/src/index.js
+++ b/packages/chameleon-tool-utils/src/index.js
@@ -1040,55 +1040,40 @@ function getPluginKey(type, key) {
// 获取export模式的入口cml文件
_.getExportEntry = function (cmlType, context, entry = []) {
let exportFiles = [];
+ function addExport(filePath) {
+ if (_.isFile(filePath) && !~exportFiles.indexOf(filePath)) {
+ exportFiles.push(filePath);
+ }
+ }
if (entry && entry.length > 0) {
entry.forEach(item => {
let filePath = path.join(context, item);
+ // cml文件插入
if (_.isFile(filePath)) {
- exportFiles.push(filePath);
+ if (path.extname(filePath) === '.cml') {
+ exportFiles.push(filePath);
+ } else if (path.extname(filePath) === '.interface') {
+ let content = fs.readFileSync(filePath, {encoding: 'utf-8'});
+ let cmlFilePath = _.findPolymorphicComponent(filePath, content, cmlType);
+ addExport(cmlFilePath);
+ }
} else if (_.isDirectory(filePath)) {
let cmlFilePath = path.join(filePath, '**/*.cml');
let interfaceFilePath = path.join(filePath, '**/*.interface');
- // 需要忽略掉的组件
- // let ignoreComponents = ['web', 'weex', 'wx', 'alipay', 'baidu'];
- // if (~ignoreComponents.indexOf(cmlType)) {
- // ignoreComponents.splice(ignoreComponents.indexOf(cmlType), 1);
- // }
- // ignoreComponents = ignoreComponents.map(item => `\\.${item}\\.cml`);
-
- // let ignoreReg = new RegExp(`(${ignoreComponents.join('|')})`);
-
- // glob.sync(filePath).forEach(cmlPath => {
- // // 其他端的多态cml组件排除在外
- // if (!ignoreReg.test(cmlPath)) {
- // exportFiles.push(cmlPath);
- // }
- // })
- // 多态组件有了include语法之后不能采用上面的方法
// 1 先找interface指定的多态组件
- // 2 再找cml文件 不能根据文件名称区分端,如果所有cml文件 也会把其他端多态组件引入,所以取只有一个逗号的cml文件
- // todo
+ // 2 再找cml文件 不能根据文件名称区分端,如果所有cml文件 也会把其他端多态组件引入,所以取只有一个逗号的cml文件为非多态组件
+ // 获取重复添加入口时有校验
glob.sync(interfaceFilePath).forEach(interfacePath => {
// 其他端的多态cml组件排除在外
let content = fs.readFileSync(interfacePath, {encoding: 'utf-8'});
let cmlFilePath = _.findPolymorphicComponent(interfacePath, content, cmlType);
-
- if (_.isFile(cmlFilePath)) {
- // 组件的名称是interface文件的名称
- if (!~exportFiles.indexOf(cmlFilePath)) {
- exportFiles.push(cmlFilePath);
- }
- }
+ addExport(cmlFilePath);
})
glob.sync(cmlFilePath).forEach(item => {
- if (_.isFile(item)) {
- let basename = path.basename(item);
- if (basename.split('.').length === 2) {
- // 组件的名称是interface文件的名称
- if (!~exportFiles.indexOf(cmlFilePath)) {
- exportFiles.push(cmlFilePath);
- }
- }
+ let basename = path.basename(item);
+ if (basename.split('.').length === 2) {
+ addExport(item);
}
})
}
diff --git a/packages/chameleon-tool-utils/test/index.test.js b/packages/chameleon-tool-utils/test/index.test.js
index 2bdb61512475c28f74f969c1128e806882894a2d..a9f83b1c4994d8364410e0ab0f6fd1ee6abb9490 100644
--- a/packages/chameleon-tool-utils/test/index.test.js
+++ b/packages/chameleon-tool-utils/test/index.test.js
@@ -378,7 +378,6 @@ describe('index.js', function () {
var cmlFilePath = path.join(__dirname, 'testlib/demo-project/src/pages/page1/page1.cml');
var comrefPath = 'vant-weapp/test'
- debugger
let result = _.handleComponentUrl(cml.projectRoot, cmlFilePath, comrefPath, 'wx');
expect(result.refUrl).to.equal('./../../npm/vant-weapp/test');
})
@@ -685,4 +684,20 @@ describe('index.js', function () {
expect(result3).to.be.equal('name');
})
+
+ it(`getExportEntry`, function () {
+ global.cml = {};
+ _.setCli(true);
+ global.cml.event = new EventEmitter();
+ global.cml.utils = _;
+ global.projectRoot = path.join(__dirname, 'testlib/demo-project');
+ let result = _.getExportEntry('web',global.projectRoot, [
+ 'src/components',
+ 'src/notfinr.cml',
+ 'src/components/com2/com2.interface'
+ ]);
+ console.log(result)
+ expect(result.length).to.be.equal(2);
+ })
+
})
diff --git a/packages/chameleon-tool-utils/test/testlib/demo-project/src/components/com2/com2.interface b/packages/chameleon-tool-utils/test/testlib/demo-project/src/components/com2/com2.interface
new file mode 100644
index 0000000000000000000000000000000000000000..a3aff7e46c5568161d1bf13e5fa5f6203ecede25
--- /dev/null
+++ b/packages/chameleon-tool-utils/test/testlib/demo-project/src/components/com2/com2.interface
@@ -0,0 +1,2 @@
+
+
\ No newline at end of file
diff --git a/packages/mvvm-script-parser/test/a.js b/packages/chameleon-tool-utils/test/testlib/demo-project/src/components/com2/com2.web.cml
similarity index 100%
rename from packages/mvvm-script-parser/test/a.js
rename to packages/chameleon-tool-utils/test/testlib/demo-project/src/components/com2/com2.web.cml
diff --git a/packages/mvvm-script-parser/test/b.js b/packages/chameleon-tool-utils/test/testlib/demo-project/src/components/com2/com2.wx.cml
similarity index 100%
rename from packages/mvvm-script-parser/test/b.js
rename to packages/chameleon-tool-utils/test/testlib/demo-project/src/components/com2/com2.wx.cml
diff --git a/packages/mvvm-script-parser/test/c.js b/packages/chameleon-tool-utils/test/testlib/demo-project/src/components/com3/com3.interface
similarity index 100%
rename from packages/mvvm-script-parser/test/c.js
rename to packages/chameleon-tool-utils/test/testlib/demo-project/src/components/com3/com3.interface
diff --git a/packages/mvvm-babel-parser/package.json b/packages/mvvm-babel-parser/package.json
index 971f163d8957cbb16f81c3cf86add2940cc2abb9..0bba7038e4ac6e9aaa24c3429bad11553504583c 100644
--- a/packages/mvvm-babel-parser/package.json
+++ b/packages/mvvm-babel-parser/package.json
@@ -10,11 +10,12 @@
"dependencies": {
"babel-generator": "6.26.1",
"babel-traverse": "6.26.0",
- "babel-types": "6.26.0"
+ "babel-types": "6.26.0",
+ "chai": "^4.2.0"
},
"scripts": {
"test": "mocha"
},
"author": "",
"license": "ISC"
-}
\ No newline at end of file
+}
diff --git a/packages/mvvm-script-parser/.eslintrc b/packages/mvvm-script-parser/.eslintrc
deleted file mode 100644
index 9465c0edbdac46405b52fc0bfb5807caab5b2765..0000000000000000000000000000000000000000
--- a/packages/mvvm-script-parser/.eslintrc
+++ /dev/null
@@ -1,566 +0,0 @@
-{
- // 在配置文件里配置全局变量时,使用 globals 指出你要使用的全局变量。将变量设置为 true 将允许变量被重写,或 false 将不允许被重写
- "globals": {
- "cml": false
- },
- // 环境定义了预定义的全局变量。
- "env": {
- //环境定义了预定义的全局变量。更多在官网查看
- "browser": true,
- "node": true,
- "commonjs": true,
- "amd": true,
- "es6": true,
- "mocha": true
- },
- // JavaScript 语言选项
- "parserOptions": {
- // ECMAScript 版本
- "ecmaVersion": 9,
- "sourceType": "module", //设置为 "script" (默认) 或 "module"(如果你的代码是 ECMAScript 模块)。
- //想使用的额外的语言特性:
- "ecmaFeatures": {
- // 允许在全局作用域下使用 return 语句
- "globalReturn": true,
- // impliedStric
- "impliedStrict": true,
- // 启用 JSX
- "jsx": true,
- "modules": true
- }
- },
- //-----让eslint支持 JSX start
- "plugins": [
-
- ],
- "extends": [
- "eslint:recommended"
- ],
- //-----让eslint支持 JSX end
-
-
- /**
- * "off" 或 0 - 关闭规则
- * "warn" 或 1 - 开启规则,使用警告级别的错误:warn (不会导致程序退出),
- * "error" 或 2 - 开启规则,使用错误级别的错误:error (当被触发的时候,程序会退出)
- */
- "rules": {
-
- ////////////////
- // 可能的错误 //
- ////////////////
-
- // 禁止条件表达式中出现赋值操作符
- "no-cond-assign": 2,
- // 禁用 console
- "no-console": 0,
- // 禁止在条件中使用常量表达式
- // if (false) {
- // doSomethingUnfinished();
- // } //cuowu
- "no-constant-condition": 2,
- // 禁止在正则表达式中使用控制字符 :new RegExp("\x1f")
- "no-control-regex": 2,
- // 数组和对象键值对最后一个逗号, never参数:不能带末尾的逗号, always参数:必须带末尾的逗号,
- // always-multiline:多行模式必须带逗号,单行模式不能带逗号
- "comma-dangle": [1, "never"],
- // 禁用 debugger
- "no-debugger": 2,
- // 禁止 function 定义中出现重名参数
- "no-dupe-args": 2,
- // 禁止对象字面量中出现重复的 key
- "no-dupe-keys": 2,
- // 禁止重复的 case 标签
- "no-duplicate-case": 2,
- // 禁止空语句块
- "no-empty": 2,
- // 禁止在正则表达式中使用空字符集 (/^abc[]/)
- "no-empty-character-class": 2,
- // 禁止对 catch 子句的参数重新赋值
- "no-ex-assign": 2,
- // 禁止不必要的布尔转换
- "no-extra-boolean-cast": 2,
- // 禁止不必要的括号 //(a * b) + c;//报错
- "no-extra-parens": 0,
- // 禁止不必要的分号
- "no-extra-semi": 2,
- // 禁止对 function 声明重新赋值
- "no-func-assign": 2,
- // 禁止在嵌套的块中出现 function 或 var 声明
- "no-inner-declarations": [2, "functions"],
- // 禁止 RegExp 构造函数中无效的正则表达式字符串
- "no-invalid-regexp": 2,
- // 禁止在字符串和注释之外不规则的空白
- "no-irregular-whitespace": 2,
- // 禁止在 in 表达式中出现否定的左操作数
- "no-negated-in-lhs": 2,
- // 禁止把全局对象 (Math 和 JSON) 作为函数调用 错误:var math = Math();
- "no-obj-calls": 2,
- // 禁止直接使用 Object.prototypes 的内置属性
- "no-prototype-builtins": 0,
- // 禁止正则表达式字面量中出现多个空格
- "no-regex-spaces": 2,
- // 禁用稀疏数组
- "no-sparse-arrays": 2,
- // 禁止出现令人困惑的多行表达式
- "no-unexpected-multiline": 2,
- // 禁止在return、throw、continue 和 break语句之后出现不可达代码
- "no-unreachable": 2,
- // 要求使用 isNaN() 检查 NaN
- "use-isnan": 2,
- // 强制使用有效的 JSDoc 注释
- "valid-jsdoc": 0,
- // 强制 typeof 表达式与有效的字符串进行比较
- // typeof foo === "undefimed" 错误
- "valid-typeof": 2,
-
-
- //////////////
- // 最佳实践 //
- //////////////
-
- // 定义对象的set存取器属性时,强制定义get
- "accessor-pairs": 2,
- // 强制数组方法的回调函数中有 return 语句
- "array-callback-return": 0,
- // 强制把变量的使用限制在其定义的作用域范围内
- "block-scoped-var": 0,
- // 限制圈复杂度,也就是类似if else能连续接多少个
- "complexity": [2, 20],
- // 要求 return 语句要么总是指定返回的值,要么不指定
- "consistent-return": 0,
- // 强制所有控制语句使用一致的括号风格
- "curly": [2, "all"],
- // switch 语句强制 default 分支,也可添加 // no default 注释取消此次警告
- "default-case": 2,
- // 强制object.key 中 . 的位置,参数:
- // property,'.'号应与属性在同一行
- // object, '.' 号应与对象名在同一行
- "dot-location": [2, "property"],
- // 强制使用.号取属性
- // 参数: allowKeywords:true 使用保留字做属性名时,只能使用.方式取属性
- // false 使用保留字做属性名时, 只能使用[]方式取属性 e.g [2, {"allowKeywords": false}]
- // allowPattern: 当属性名匹配提供的正则表达式时,允许使用[]方式取值,否则只能用.号取值 e.g [2, {"allowPattern": "^[a-z]+(_[a-z]+)+$"}]
- "dot-notation": [2, {
- "allowKeywords": false
- }],
- // 使用 === 替代 == allow-null允许null和undefined==
- "eqeqeq": [0, "allow-null"],
- // 要求 for-in 循环中有一个 if 语句
- "guard-for-in": 2,
- // 禁用 alert、confirm 和 prompt
- "no-alert": 0,
- // 禁用 arguments.caller 或 arguments.callee
- "no-caller": 2,
- // 不允许在 case 子句中使用词法声明
- "no-case-declarations": 2,
- // 禁止除法操作符显式的出现在正则表达式开始的位置
- "no-div-regex": 2,
- // 禁止 if 语句中有 return 之后有 else
- "no-else-return": 0,
- // 禁止出现空函数.如果一个函数包含了一条注释,它将不会被认为有问题。
- "no-empty-function": 2,
- // 禁止使用空解构模式no-empty-pattern
- "no-empty-pattern": 2,
- // 禁止在没有类型检查操作符的情况下与 null 进行比较
- "no-eq-null": 1,
- // 禁用 eval()
- "no-eval": 2,
- // 禁止扩展原生类型
- "no-extend-native": 2,
- // 禁止不必要的 .bind() 调用
- "no-extra-bind": 2,
- // 禁用不必要的标签
- "no-extra-label:": 0,
- // 禁止 case 语句落空
- "no-fallthrough": 2,
- // 禁止数字字面量中使用前导和末尾小数点
- "no-floating-decimal": 2,
- // 禁止使用短符号进行类型转换(!!fOO)
- "no-implicit-coercion": 0,
- // 禁止在全局范围内使用 var 和命名的 function 声明
- "no-implicit-globals": 1,
- // 禁止使用类似 eval() 的方法
- "no-implied-eval": 2,
- // 禁止 this 关键字出现在类和类对象之外
- "no-invalid-this": 0,
- // 禁用 __iterator__ 属性
- "no-iterator": 2,
- // 禁用标签语句
- "no-labels": 2,
- // 禁用不必要的嵌套块
- "no-lone-blocks": 2,
- // 禁止在循环中出现 function 声明和表达式
- "no-loop-func": 1,
- // 禁用魔术数字(3.14什么的用常量代替)
- "no-magic-numbers": [1, {
- "ignore": [0, -1, 1]
- }],
- // 禁止使用多个空格
- "no-multi-spaces": 2,
- // 禁止使用多行字符串,在 JavaScript 中,可以在新行之前使用斜线创建多行字符串
- "no-multi-str": 2,
- // 禁止对原生对象赋值
- "no-native-reassign": 2,
- // 禁止在非赋值或条件语句中使用 new 操作符
- "no-new": 2,
- // 禁止对 Function 对象使用 new 操作符
- "no-new-func": 0,
- // 禁止对 String,Number 和 Boolean 使用 new 操作符
- "no-new-wrappers": 2,
- // 禁用八进制字面量
- "no-octal": 2,
- // 禁止在字符串中使用八进制转义序列
- "no-octal-escape": 2,
- // 不允许对 function 的参数进行重新赋值
- "no-param-reassign": 0,
- // 禁用 __proto__ 属性
- "no-proto": 2,
- // 禁止使用 var 多次声明同一变量
- "no-redeclare": 2,
- // 禁用指定的通过 require 加载的模块
- "no-return-assign": 0,
- // 禁止使用 javascript: url
- "no-script-url": 0,
- // 禁止自我赋值
- "no-self-assign": 2,
- // 禁止自身比较
- "no-self-compare": 2,
- // 禁用逗号操作符
- "no-sequences": 2,
- // 禁止抛出非异常字面量
- "no-throw-literal": 2,
- // 禁用一成不变的循环条件
- "no-unmodified-loop-condition": 2,
- // 禁止出现未使用过的表达式
- "no-unused-expressions": 0,
- // 禁用未使用过的标签
- "no-unused-labels": 2,
- // 禁止不必要的 .call() 和 .apply()
- "no-useless-call": 2,
- // 禁止不必要的字符串字面量或模板字面量的连接
- "no-useless-concat": 0,
- // 禁用不必要的转义字符
- "no-useless-escape": 0,
- // 禁用 void 操作符
- "no-void": 0,
- // 禁止在注释中使用特定的警告术语
- "no-warning-comments": 0,
- // 禁用 with 语句
- "no-with": 2,
- // 强制在parseInt()使用基数参数
- "radix": 2,
- // 要求所有的 var 声明出现在它们所在的作用域顶部
- "vars-on-top": 0,
- // 要求 IIFE 使用括号括起来
- "wrap-iife": [2, "any"],
- // 要求或禁止 “Yoda” 条件
- "yoda": [2, "never"],
- // 要求或禁止使用严格模式指令
- "strict": 0,
-
-
- //////////////
- // 变量声明 //
- //////////////
-
- // 要求或禁止 var 声明中的初始化(初值)
- "init-declarations": 0,
- // 不允许 catch 子句的参数与外层作用域中的变量同名
- "no-catch-shadow": 0,
- // 禁止删除变量
- "no-delete-var": 2,
- // 不允许标签与变量同名
- "no-label-var": 2,
- // 禁用特定的全局变量
- "no-restricted-globals": 0,
- // 禁止 var 声明 与外层作用域的变量同名
- "no-shadow": 0,
- // 禁止覆盖受限制的标识符
- "no-shadow-restricted-names": 2,
- // 禁用未声明的变量,除非它们在 /*global */ 注释中被提到
- "no-undef": 2,
- // 禁止将变量初始化为 undefined
- "no-undef-init": 2,
- // 禁止将 undefined 作为标识符
- "no-undefined": 0,
- // 禁止出现未使用过的变量
- "no-unused-vars": [2, {
- "vars": "all",
- "args": "none"
- }],
- // 不允许在变量定义之前使用它们
- "no-use-before-define": 0,
-
- //////////////////////////
- // Node.js and CommonJS //
- //////////////////////////
-
- // require return statements after callbacks
- "callback-return": 0,
- // 要求 require() 出现在顶层模块作用域中
- "global-require": 1,
- // 要求回调函数中有容错处理
- "handle-callback-err": [2, "^(err|error)$"],
- // 禁止混合常规 var 声明和 require 调用
- "no-mixed-requires": 0,
- // 禁止调用 require 时使用 new 操作符
- "no-new-require": 2,
- // 禁止对 __dirname 和 __filename进行字符串连接
- "no-path-concat": 0,
- // 禁用 process.env
- "no-process-env": 0,
- // 禁用 process.exit()
- "no-process-exit": 0,
- // 禁用同步方法
- "no-sync": 0,
-
- //////////////
- // 风格指南 //
- //////////////
-
- // 指定数组的元素之间要以空格隔开(, 后面), never参数:[ 之前和 ] 之后不能带空格,always参数:[ 之前和 ] 之后必须带空格
- "array-bracket-spacing": [2, "never"],
- // 禁止或强制在单行代码块中使用空格(禁用)
- "block-spacing": [1, "never"],
- //强制使用一致的缩进 第二个参数为 "tab" 时,会使用tab,
- // if while function 后面的{必须与if在同一行,java风格。
- "brace-style": [2, "1tbs", {
- "allowSingleLine": true
- }],
- // 双峰驼命名格式
- "camelcase": 2,
- // 控制逗号前后的空格
- "comma-spacing": [2, {
- "before": false,
- "after": true
- }],
- // 控制逗号在行尾出现还是在行首出现 (默认行尾)
- // http://eslint.org/docs/rules/comma-style
- "comma-style": [2, "last"],
- //"SwitchCase" (默认:0) 强制 switch 语句中的 case 子句的缩进水平
- // 以方括号取对象属性时,[ 后面和 ] 前面是否需要空格, 可选参数 never, always
- "computed-property-spacing": [2, "never"],
- // 用于指统一在回调函数中指向this的变量名,箭头函数中的this已经可以指向外层调用者,应该没卵用了
- // e.g [0,"that"] 指定只能 var that = this. that不能指向其他任何值,this也不能赋值给that以外的其他值
- "consistent-this": [1, "that"],
- // 强制使用命名的 function 表达式
- "func-names": 0,
- // 文件末尾强制换行
- "eol-last": 2,
- "indent": [2, 2, {
- "SwitchCase": 1
- }],
- // 强制在对象字面量的属性中键和值之间使用一致的间距
- "key-spacing": [2, {
- "beforeColon": false,
- "afterColon": true
- }],
- // 强制使用一致的换行风格
- "linebreak-style": [1, "unix"],
- // 要求在注释周围有空行 ( 要求在块级注释之前有一空行)
- "lines-around-comment": [1, {
- "beforeBlockComment": true
- }],
- // 强制一致地使用函数声明或函数表达式,方法定义风格,参数:
- // declaration: 强制使用方法声明的方式,function f(){} e.g [2, "declaration"]
- // expression:强制使用方法表达式的方式,var f = function() {} e.g [2, "expression"]
- // allowArrowFunctions: declaration风格中允许箭头函数。 e.g [2, "declaration", { "allowArrowFunctions": true }]
- "func-style": 0,
- // 强制回调函数最大嵌套深度 5层
- "max-nested-callbacks": [1, 5],
- // 禁止使用指定的标识符
- "id-blacklist": 0,
- // 强制标识符的最新和最大长度
- "id-length": 0,
- // 要求标识符匹配一个指定的正则表达式
- "id-match": 0,
- // 强制在 JSX 属性中一致地使用双引号或单引号
- "jsx-quotes": 0,
- // 强制在关键字前后使用一致的空格 (前后腰需要)
- "keyword-spacing": 2,
- // 强制一行的最大长度
- "max-len": [1, 200],
- // 强制最大行数
- "max-lines": 0,
- // 强制 function 定义中最多允许的参数数量
- "max-params": [1, 7],
- // 强制 function 块最多允许的的语句数量
- "max-statements": [1, 200],
- // 强制每一行中所允许的最大语句数量
- "max-statements-per-line": 0,
- // 要求构造函数首字母大写 (要求调用 new 操作符时有首字母大小的函数,允许调用首字母大写的函数时没有 new 操作符。)
- "new-cap": [2, {
- "newIsCap": true,
- "capIsNew": false
- }],
- // 要求调用无参构造函数时有圆括号
- "new-parens": 2,
- // 要求或禁止 var 声明语句后有一行空行
- "newline-after-var": 0,
- // 禁止使用 Array 构造函数
- "no-array-constructor": 2,
- // 禁用按位运算符
- "no-bitwise": 0,
- // 要求 return 语句之前有一空行
- "newline-before-return": 0,
- // 要求方法链中每个调用都有一个换行符
- "newline-per-chained-call": 1,
- // 禁用 continue 语句
- "no-continue": 0,
- // 禁止在代码行后使用内联注释
- "no-inline-comments": 0,
- // 禁止 if 作为唯一的语句出现在 else 语句中
- "no-lonely-if": 0,
- // 禁止混合使用不同的操作符
- "no-mixed-operators": 0,
- // 不允许空格和 tab 混合缩进
- "no-mixed-spaces-and-tabs": 2,
- // 不允许多个空行
- "no-multiple-empty-lines": [2, {
- "max": 2
- }],
- // 不允许否定的表达式
- "no-negated-condition": 0,
- // 不允许使用嵌套的三元表达式
- "no-nested-ternary": 0,
- // 禁止使用 Object 的构造函数
- "no-new-object": 2,
- // 禁止使用一元操作符 ++ 和 --
- "no-plusplus": 0,
- // 禁止使用特定的语法
- "no-restricted-syntax": 0,
- // 禁止 function 标识符和括号之间出现空格
- "no-spaced-func": 2,
- // 不允许使用三元操作符
- "no-ternary": 0,
- // 禁用行尾空格
- "no-trailing-spaces": 2,
- // 禁止标识符中有悬空下划线_bar
- "no-underscore-dangle": 0,
- // 禁止可以在有更简单的可替代的表达式时使用三元操作符
- "no-unneeded-ternary": 2,
- // 禁止属性前有空白
- "no-whitespace-before-property": 0,
- // 强制花括号内换行符的一致性
- "object-curly-newline": 0,
- // 强制在花括号中使用一致的空格
- "object-curly-spacing": 0,
- // 强制将对象的属性放在不同的行上
- "object-property-newline": 0,
- // 强制函数中的变量要么一起声明要么分开声明
- "one-var": [2, {
- "initialized": "never"
- }],
- // 要求或禁止在 var 声明周围换行
- "one-var-declaration-per-line": 0,
- // 要求或禁止在可能的情况下要求使用简化的赋值操作符
- "operator-assignment": 0,
- // 强制操作符使用一致的换行符
- "operator-linebreak": [2, "after", {
- "overrides": {
- "?": "before",
- ":": "before"
- }
- }],
- // 要求或禁止块内填充
- "padded-blocks": 0,
- // 要求对象字面量属性名称用引号括起来
- "quote-props": 0,
- // 强制使用一致的反勾号、双引号或单引号
- // "quotes": [2, "single", "avoid-escape"],
- // 要求使用 JSDoc 注释
- "require-jsdoc": 0,
- // 要求或禁止使用分号而不是 ASI(这个才是控制行尾部分号的,)
- "semi": [0, "always"],
- // 强制分号之前和之后使用一致的空格
- "semi-spacing": 0,
- // 要求同一个声明块中的变量按顺序排列
- "sort-vars": 0,
- // 强制在块之前使用一致的空格
- "space-before-blocks": [2, "always"],
- // 强制在 function的左括号之前使用一致的空格
- "space-before-function-paren": [0, "always"],
- // 强制在圆括号内使用一致的空格
- "space-in-parens": [2, "never"],
- // 要求操作符周围有空格
- "space-infix-ops": 2,
- // 强制在一元操作符前后使用一致的空格
- "space-unary-ops": [2, {
- "words": true,
- "nonwords": false
- }],
- // 强制在注释中 // 或 /* 使用一致的空格
- "spaced-comment": [2, "always", {
- "markers": ["global", "globals", "eslint", "eslint-disable", "*package", "!"]
- }],
- // 要求或禁止 Unicode BOM
- "unicode-bom": 0,
- // 要求正则表达式被括号括起来
- "wrap-regex": 0,
-
- //////////////
- // ES6.相关 //
- //////////////
-
- // 要求箭头函数体使用大括号
- "arrow-body-style": 2,
- // 要求箭头函数的参数使用圆括号
- "arrow-parens": 0,
- "arrow-spacing": [2, {
- "before": true,
- "after": true
- }],
- // 强制在子类构造函数中用super()调用父类构造函数,TypeScrip的编译器也会提示
- "constructor-super": 0,
- // 强制 generator 函数中 * 号周围使用一致的空格
- "generator-star-spacing": [2, {
- "before": true,
- "after": true
- }],
- // 禁止修改类声明的变量
- "no-class-assign": 2,
- // 不允许箭头功能,在那里他们可以混淆的比较
- "no-confusing-arrow": 0,
- // 禁止修改 const 声明的变量
- "no-const-assign": 2,
- // 禁止类成员中出现重复的名称
- "no-dupe-class-members": 2,
- // 不允许复制模块的进口
- "no-duplicate-imports": 0,
- // 禁止 Symbol 的构造函数
- "no-new-symbol": 2,
- // 允许指定模块加载时的进口
- "no-restricted-imports": 0,
- // 禁止在构造函数中,在调用 super() 之前使用 this 或 super
- "no-this-before-super": 2,
- // 禁止不必要的计算性能键对象的文字
- "no-useless-computed-key": 0,
- // 要求使用 let 或 const 而不是 var
- "no-var": 0,
- // 要求或禁止对象字面量中方法和属性使用简写语法
- "object-shorthand": 0,
- // 要求使用箭头函数作为回调
- "prefer-arrow-callback": 0,
- // 要求使用 const 声明那些声明后不再被修改的变量
- "prefer-const": 0,
- // 要求在合适的地方使用 Reflect 方法
- "prefer-reflect": 0,
- // 要求使用扩展运算符而非 .apply()
- "prefer-spread": 0,
- // 要求使用模板字面量而非字符串连接
- "prefer-template": 0,
- // Suggest using the rest parameters instead of arguments
- "prefer-rest-params": 0,
- // 要求generator 函数内有 yield
- "require-yield": 0,
- // enforce spacing between rest and spread operators and their expressions
- "rest-spread-spacing": 0,
- // 强制模块内的 import 排序
- "sort-imports": 0,
- // 要求或禁止模板字符串中的嵌入表达式周围空格的使用
- "template-curly-spacing": 1,
- // 强制在 yield* 表达式中 * 周围使用空格
- "yield-star-spacing": 2
- }
-}
diff --git a/packages/mvvm-script-parser/.gitignore b/packages/mvvm-script-parser/.gitignore
deleted file mode 100644
index 2e258fc5d353ecf9bb4e165e77e2172f3ecc613c..0000000000000000000000000000000000000000
--- a/packages/mvvm-script-parser/.gitignore
+++ /dev/null
@@ -1,69 +0,0 @@
-# Editor directories and files
-.DS_Store
-.idea
-*.suo
-*.ntvs*
-*.njsproj
-*.sln
-.vscode
-
-# Logs
-logs
-*.log
-npm-debug.log*
-yarn-debug.log*
-yarn-error.log*
-
-# Runtime data
-pids
-*.pid
-*.seed
-*.pid.lock
-
-# Directory for instrumented libs generated by jscoverage/JSCover
-lib-cov
-
-# Coverage directory used by tools like istanbul
-coverage
-
-# nyc test coverage
-.nyc_output
-
-# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
-.grunt
-
-# Bower dependency directory (https://bower.io/)
-bower_components
-
-# node-waf configuration
-.lock-wscript
-
-# Compiled binary addons (https://nodejs.org/api/addons.html)
-build/Release
-
-# Dependency directories
-jspm_packages/
-
-# Typescript v1 declaration files
-typings/
-
-# Optional npm cache directory
-.npm
-
-# Optional eslint cache
-.eslintcache
-
-# Optional REPL history
-.node_repl_history
-
-# Output of 'npm pack'
-*.tgz
-
-# Yarn Integrity file
-.yarn-integrity
-
-# dotenv environment variables file
-.env
-
-# ///////////////////////////
-
diff --git a/packages/mvvm-script-parser/README.md b/packages/mvvm-script-parser/README.md
deleted file mode 100644
index 2acc2eafebe670c872d1adb870843817e418012e..0000000000000000000000000000000000000000
--- a/packages/mvvm-script-parser/README.md
+++ /dev/null
@@ -1 +0,0 @@
-#### mvvm协议标准中处理cml文件script部分与js文件
\ No newline at end of file
diff --git a/packages/mvvm-script-parser/index.js b/packages/mvvm-script-parser/index.js
deleted file mode 100644
index ff390ecf912756d660c73d7c4f4ede15d84fcc44..0000000000000000000000000000000000000000
--- a/packages/mvvm-script-parser/index.js
+++ /dev/null
@@ -1,190 +0,0 @@
-/** 编译源码
- * 分析依赖
- * */
-'use strict';
-
-const {parsePlugins} = require('runtime-check');
-const parser = require('@babel/parser');
-const babel = require('@babel/core');
-const traverse = require('@babel/traverse');
-const t = require('@babel/types');
-const cmlUtils = require('chameleon-tool-utils');
-const {getCheckCode} = require('./lib/check');
-const interfaceParser = require('mvvm-interface-parser');
-const getInterfaceCode = require('mvvm-interface-parser/lib/getInterfaceCode.js');
-const generator = require("@babel/generator");
-const path = require('path');
-
-const defaultResolve = function(filePath, relativePath) {
- return path.resolve(path.dirname(filePath), relativePath)
-}
-// 标准的script部分处理
-exports.standardParser = function({cmlType, media, source, filePath, check, resolve = defaultResolve }) {
- let devDeps = [];
- let reg = new RegExp(`\\.${cmlType}\\.cml$`);
-
- // 多态组件 获取interface文件并拼接
- if (reg.test(filePath)) {
- let interfacePath = cmlUtils.RecordCml2Interface[filePath];
- if (!interfacePath) {
- throw new Error(`not find interface for ${filePath}`)
- }
- let {content: interfaceCode, devDeps: interfaceDevDeps, contentFilePath} = getInterfaceCode({interfacePath});
- devDeps = interfaceDevDeps;
- if (media === 'dev' && check.enable === true) {
- try {
- source = getCheckCode(interfaceCode, source, contentFilePath, filePath, cmlType, check.enableTypes);
- } catch (e) {
- // 当有语法错误 babel parse会报错,报错信息不友好
- cmlUtils.log.error(`mvvm-interface-parser: ${filePath} or ${contentFilePath} syntax error!`)
- }
- }
- }
- // .interface文件
- else if (/\.interface$/.test(filePath)) {
- let interfaceResult = interfaceParser({cmlType, media, source, filePath, check, resolve });
- source = interfaceResult.result;
- devDeps = interfaceResult.devDeps;
- }
- return {source, devDeps};
-
-}
-
-
-// 源代码的ast
-exports.JSCompile = function({source, filePath, compiler}) {
- const ast = exports.getAST({source});
- const dependencies = exports.getDependenciesAndReplace({ast, filePath, compiler});
- const output = generator["default"](ast);
- return {
- ast,
- dependencies,
- output
- };
-}
-
-// 获取ast
-exports.getAST = function({source}) {
- const ast = parser.parse(source, {
- sourceType: 'module',
- plugins: parsePlugins
- });
- return ast;
-}
-
-// 获取dependencies
-exports.getDependenciesAndReplace = function({ast, filePath, compiler}) {
- let dependencies = [];
- traverse["default"](ast, {
- enter: (path) => {
- let node = path.node;
- if (t.isImportDeclaration(node) && node.source.value) {
- let {realPath, modId} = getJSModId(node.source.value);
- node.source.value = modId;
- node.source.raw = `'${modId}'`;
- dependencies.push(realPath);
-
- }
- if (t.isVariableDeclaration(node)) {
- node.declarations.forEach(item => {
- if (item && item.init && item.init.callee && item.init.callee.name === 'require' && item.init.arguments && item.init.arguments[0] && item.init.arguments[0].value) {
- let {realPath, modId} = getJSModId(item.init.arguments[0].value);
- item.init.arguments[0].value = modId;
- item.init.arguments[0].raw = `'${modId}'`;
- dependencies.push(realPath);
- }
- })
- }
- if (t.isExpressionStatement(node) && node.expression && node.expression.callee && node.expression.callee.name === 'require' && node.expression.arguments && node.expression.arguments[0]) {
- let {realPath, modId} = getJSModId(node.expression.arguments[0].value);
- node.expression.arguments[0].value = modId;
- node.expression.arguments[0].raw = `'${modId}'`;
- dependencies.push(realPath);
- }
- }
- })
-
- function getJSModId(dependPath) {
- if (compiler) {
- let realDependPath = compiler.resolve(filePath, dependPath);
- return {
- realPath: realDependPath,
- modId: compiler.createModId(realDependPath)
- };
- } else {
- return {
- realPath: dependPath,
- modId: dependPath
- }
- }
- }
- return dependencies;
-}
-
-
-// 获取dependencies
-exports.getDependencies = function({ast}) {
- let dependencies = [];
- traverse["default"](ast, {
- enter: (path) => {
- let node = path.node;
- if (t.isImportDeclaration(node) && node.source.value) {
- dependencies.push(node.source.value);
- }
- if (t.isVariableDeclaration(node)) {
- node.declarations.forEach(item => {
- if (item && item.init && item.init.callee && item.init.callee.name === 'require' && item.init.arguments && item.init.arguments[0] && item.init.arguments[0].value) {
- dependencies.push(item.init.arguments[0].value);
- }
- })
- }
- if (t.isExpressionStatement(node) && node.expression && node.expression.callee && node.expression.callee.name === 'require' && node.expression.arguments && node.expression.arguments[0]) {
- dependencies.push(node.expression.arguments[0].value);
- }
- }
- })
- return dependencies;
-}
-
-// 提供标准的jsbabel方法
-exports.standardBabel = function({source, options}) {
- // options 这里需要兼容
- options = options || exports.standardBabelOptions;
- let output = babel.transformSync(source, options); // => { code, map, ast }
- return output;
-}
-
-exports.standardBabelOptions = {
- "presets": [
- "flow",
- [
- "env",
- {
- "targets": {
- "browsers": [
- "> 1%",
- "last 2 versions",
- "not ie <= 8"
- ]
- }
- }
- ],
- "stage-0"
- ],
- "plugins": [
- "transform-remove-strict-mode",
- ["transform-runtime", {
- "helpers": false,
- "polyfill": false,
- "regenerator": true,
- "moduleName": "babel-runtime"
- }],
- ["babel-plugin-chameleon-import", {
- "libraryName": "chameleon-api",
- "libraryDirectory": "src/interfaces",
- "libraryFileName": "index.js",
- "defaulLibraryDirectory": "",
- "defaulLibraryFileName": "index.js"
- }]
- ]
-}
diff --git a/packages/mvvm-script-parser/lib/check.js b/packages/mvvm-script-parser/lib/check.js
deleted file mode 100644
index 3f229624dd4c6b2f7d28dd362c5278a5185982c6..0000000000000000000000000000000000000000
--- a/packages/mvvm-script-parser/lib/check.js
+++ /dev/null
@@ -1,381 +0,0 @@
-
-/* eslint-disable */
-/**
- * cml多态组件 interface校验
- * 1 拿到interface的校验
- * 2 写好处理default对象的方法
- * 3 拼接代码
- */
-const path = require('path');
-const parser = require('@babel/parser');
-const traverse = require('@babel/traverse');
-const generate = require("@babel/generator");
-const {getDefines, parsePlugins} = require('runtime-check');
-const cmlUtils = require('chameleon-tool-utils');
-
-/**
- * 处理对象的函数
- * @param {*} obj
- */
-function wrapper(obj) {
- const className = obj.constructor.name;
- const interfaceDefines = __INTERFAE__DEFINES__;
- const enableTypes = __enableTypes__; // ['Object','Array','Nullable']
- const types = interfaceDefines.types;
- const interfaceKey = Object.keys(interfaceDefines.interfaces)[0]; // interface Name
- const interfaceObj = interfaceDefines.interfaces[interfaceKey];
- const cmlDefines = __CML__DEFINES__;
- let isImplementInterface = false;
- // 找到class
- if (cmlDefines.classes[className]) {
- // class 的interface数组中有interface中的定义
- if (~cmlDefines.classes[className].indexOf(interfaceKey)) {
- isImplementInterface = true;
- } else {
- console.error(`class ${className} not implements interface ${interfaceKey}`);
- }
- }
-
-
- let props = [];
- let events = {};
-
- Object.keys(interfaceObj).forEach(key => {
- let item = interfaceObj[key];
- if (is(item, 'Object')) {
- // 是事件 有output和input
- events[key] = item;
- } else {
- // 是属性
- props.push({
- key,
- value: item
- })
- }
- })
-
- // created 时做props校验 同时建立watch属性检测props类型
- // 包装this.$cmlEmit 校验自定义事件参数类型
- function isFunc(target) {
- return target && is(target, 'Function')
- }
-
- function is(source, type) {
- return Object.prototype.toString.call(source) === '[object ' + type + ']';
- }
-
- const getType = function (value) {
- const type = Object.prototype.toString.call(value);
- return type.replace(/\[object\s(.*)\]/g, '$1').replace(/( |^)[a-z]/g, (L) => L.toUpperCase());
- };
-
- // beforeCreate时 vue中还获取不到mixins的this.$cmlEmit方法
- let oldCreated = obj.created || function() {};
- obj.created = function(...args) {
- checkProps.call(this);
- oldCreated.call(this);
- }
-
- obj.methods = obj.methods || {};
-
- obj.methods.$__checkCmlEmit__ = function(eventName, eventDetail) {
- if (events[eventName]) {
- let {input} = events[eventName];
- let detailType = input[0];
- let errList = checkType(eventDetail, detailType, []);
- if (errList && errList.length) {
- showErrorMessage(`errorinfo: event ${eventName} detail verification fails
- ${errList.join('\n')}
- `)
- }
- } else {
- showErrorMessage(`errorinfo: event ${eventName} is not defined in interface
- ${errList.join('\n')}
- `)
- }
- }
-
- function checkProps() {
- props.forEach(item => {
- let errList = checkType(this[item.key], item.value, []);
- if (errList && errList.length) {
- showErrorMessage(`error: prop [${item.key}] verification fails
- ${errList.join('\n')}
- `)
- }
-
- })
- }
-
- obj.watch = obj.watch || {};
-
- props.forEach(item => {
- let oldWatch = obj.watch[item.key];
- obj.watch[item.key] = function (newVal, oldVal) {
- let errList = checkType(newVal, item.value, []);
- if (errList && errList.length) {
- showErrorMessage(`errorinfo: prop [${item.key}] verification fails
- ${errList.join('\n')}
- `)
- }
- if (isFunc(oldWatch)) {
- oldWatch.call(this, newVal, oldVal);
- }
- }
-
- })
-
-
- /**
- * 校验类型 两个loader共用代码
- *
- * @param {*} value 实际传入的值
- * @param {string} type 静态分析时候得到的值得类型
- * @param {array[string]} errList 校验错误信息 类型
- * @return {bool} 校验结果
- */
- const checkType = function(value, originType, errList = []) {
- let isNullableReg = /_cml_nullable_lmc_/g;
- let type = originType.replace('_cml_nullable_lmc_', '');
- (type === "Void") && (type = "Undefined")
- let currentType = getType(value);// Undefined Null Object Array Number String Function只可能是这几种类型;
- // 但是对于type的值则可能是 Undefined Null Number String NullUndefinedStiring
- // Object Array Function EventDetail(...这种自定义的复杂数据类型) 这几种;
- // 判断nullable类型的参数
- // 如果 currentType === type 那么就会直接返回 [];
- let canUseNullable = enableTypes.includes("Nullable");
- let canUseObject = enableTypes.includes("Object");
- let canUseArray = enableTypes.includes("Array");
- if (currentType == 'Null') { // 如果传入的值是 null类型,那么可能的情况是该值在接口处的被定义为Null或者是 ?string 这种可选参数的形式;
- if (type == "Null") {// 如果定义的参数的值就是 Null,那么校验通过
- errList = [];
- } else { // 实际定义的参数的值不是 Null ?string这种形式的定义,type = new String('String') ?Callback type = new String('Callback')
- // 那么判断是否是可选参数的情况
- (canUseNullable && isNullableReg.test(originType)) ? errList = [] : errList.push(`定义了${type}类型的参数,传入的却是${currentType},请确认是否开启nullable配置`)
- }
- return errList;
-
- }
- if (currentType == 'Undefined') { // 如果运行时传入的真实值是undefined,那么可能改值在接口处就是被定义为 Undefined类型或者是 ?string 这种可选参数 nullable的情况;
- if (type == "Undefined") {
- errList = [];
- } else {
- (canUseNullable && isNullableReg.test(originType)) ? errList = [] : errList.push(`定义了${type}类型的参数,传入的却是${currentType},请确认是否开启nullable配置或者检查所传参数是否和接口定义的一致`)
- }
- return errList;
- }
- if (currentType == 'String') {
- if (type == 'String') {
- errList = [];
- } else {
- errList.push(`定义了${type}类型的参数,传入的却是${currentType},请检查所传参数是否和接口定义的一致`)
- }
- return errList;
- }
- if (currentType == 'Boolean') {
- if (type == 'Boolean') {
- errList = [];
- } else {
- errList.push(`定义了${type}类型的参数,传入的却是${currentType},请检查所传参数是否和接口定义的一致`)
- }
- return errList;
- }
- if (currentType == 'Number') {
- if (type == 'Number') {
- errList = [];
- } else {
- errList.push(`定义了${type}类型的参数,传入的却是${currentType},请检查所传参数是否和接口定义的一致`)
- }
- return errList;
- }
- if (currentType == 'Object') {
- if (type == 'Object') {
- (!canUseObject) ? errList.push(`不能直接定义类型${type},需要使用符合类型定义,请确认是否开启了可以直接定义 Object 类型参数;`) : (errList = []);
- } else if (type == 'CMLObject') {
- errList = [];
- } else { // 这种情况的对象就是自定义的对象;
- if (types[type]) {
- const keys = Object.keys(types[type]);
- // todo 这里是同样的问题,可能多传递
- keys.forEach(key => {
- let subError = checkType(value[key], types[type][key], []);
- if (subError && subError.length) {
- errList = errList.concat(subError)
- }
- });
- if (Object.keys(value).length > keys.length) {
- errList.push(`type [${type}] 参数个数与定义不符`)
- }
- } else {
- errList.push('找不到定义的type [' + type + ']!');
- }
- }
- return errList;
- }
- if (currentType == 'Array') {
- if (type == 'Array') {
- (!canUseObject) ? errList.push(`不能直接定义类型${type},需要使用符合类型定义,请确认是否开启了可以直接定义 Array 类型参数;`) : (errList = []);
- } else {
- if (types[type]) {
- // 数组元素的类型
- let itemType = types[type][0];
- for (let i = 0; i < value.length; i++) {
- let subError = checkType(value[i], itemType, []);
- if (subError && subError.length) {
- errList = errList.concat(subError)
- }
- }
- } else {
- errList.push('找不到定义的type [' + type + ']!');
-
- }
- }
-
- return errList;
- }
- if (currentType == 'Function') {
- if (types[type]) {
- if (!types[type].input && !types[type].output) {
- errList.push(`找不到${types[type]} 函数定义的输入输出`);
- }
- } else {
- errList.push('找不到定义的type [' + type + ']!');
- }
- }
- if (currentType == 'Promise') {
- if (type == 'Promise') {
- errList = [];
- } else {
- errList.push(`定义了${type}类型的参数,传入的却是${currentType},请检查所传参数是否和接口定义的一致`)
- }
- return errList;
- }
- if (currentType == 'Date') {
- if (type == 'Date') {
- errList = [];
- } else {
- errList.push(`定义了${type}类型的参数,传入的却是${currentType},请检查所传参数是否和接口定义的一致`)
- }
- return errList;
- }
- if (currentType == 'RegExp') {
- if (type == 'RegExp') {
- errList = [];
- } else {
- errList.push(`定义了${type}类型的参数,传入的却是${currentType},请检查所传参数是否和接口定义的一致`)
- }
- return errList;
- }
-
-
- return errList;
- }
-
- return obj;
-
-
-}
-
-
-/**
- * 处理ast导出表达式
- *
- * @param {Object} ast ast
- * @return {Object} ast
- */
-const handlExport = function (ast) {
- traverse["default"](ast, {
- enter(path) {
- if (path.node.type === 'ExportDefaultDeclaration') {
- // 拿到export ddefault new Method(); 这一行代码
- let exportCode = generate["default"](path.node);
- // 拿到 new Method(); 这一段代码
- let declarationCode = generate["default"](path.node.declaration);
- // 得到 export default __OBJECT__WARPPER__(new Method());
- let codeSeg = exportCode.code.replace(declarationCode.code, '__CML__WRAPPER__(' + declarationCode.code + ')');
- // 转成ast
- let replacement = parser.parse(codeSeg, {
- plugins: parsePlugins,
- sourceType: 'module'
- });
- traverse["default"].removeProperties(replacement);
- // 替换
- path.replaceWith(replacement.program.body[0]);
- path.stop();
- }
- }
- });
-
- return ast;
-};
-
-/**
- *
- * @param {*} interfaceCode interface的代码
- * @param {*} cmlCode cml的代码
- * @param {*} interfacePath interface的文件路径
- * @param {*} cmlPath cml的文件路径
- * @param {*} cmlType web weex
- * @param {*} enableTypes 启动的类型
- */
-function getCheckCode(interfaceCode, cmlCode, interfacePath, cmlPath, cmlType, enableTypes) {
- let interfaceDefines = getDefines(interfaceCode, interfacePath).defines;
- let interfaceNumber = Object.keys(interfaceDefines.interfaces).length;
- if (interfaceNumber === 0) {
- throw new Error(`${interfacePath}中未定义interface`)
- } else if (interfaceNumber > 1) {
- throw new Error(`${interfacePath}中只能定义一个interface`)
- }
-
- // 为了拿到expot 对象的class implements 的interface
- let cmlDefines = getDefines(cmlCode, cmlPath);
-
- const newCode = generate["default"](handlExport(cmlDefines.ast)).code;
- let result = '';
- let wrapperCode = '';
- if (interfacePath) {
- interfacePath = path.resolve(interfacePath);
- interfacePath = cmlUtils.handleWinPath(interfacePath);
-
- result += `const __INTERFACE__FILEPATH="${interfacePath}"`;
- }
- if (cmlType === 'weex') {
- function throwError(content) {
- var modal = weex.requireModule('modal')
- modal.alert({
- message: `文件位置: ${__INTERFACE__FILEPATH}
- ${content}`
- })
- }
- result += `
- const __CML_ERROR__ = ${throwError.toString()}
- `
- } else {
- function throwError(content) {
- throw new Error(`文件位置: ${__INTERFACE__FILEPATH}
- ${content}`)
- }
- result += `
- const __CML_ERROR__ = ${throwError.toString()}
- `
- }
-
- wrapperCode = `
- ${wrapper.toString().replace(/showErrorMessage/g, '__CML_ERROR__')}`
-
- result += `
- const __enableTypes__ = ${JSON.stringify(enableTypes)}
- const __INTERFAE__DEFINES__ = ${JSON.stringify(interfaceDefines, null, 2)};
- const __CML__DEFINES__ = ${JSON.stringify(cmlDefines.defines, null, 2)};
- const __CML__WRAPPER__ = ${wrapperCode};
- ${newCode}
- `
- return result;
-
-}
-
-module.exports = {
- getCheckCode
-}
-
-
diff --git a/packages/mvvm-script-parser/package.json b/packages/mvvm-script-parser/package.json
deleted file mode 100644
index 21a1a52752121629ea0b0321ec26e10b7386ee96..0000000000000000000000000000000000000000
--- a/packages/mvvm-script-parser/package.json
+++ /dev/null
@@ -1,21 +0,0 @@
-{
- "name": "mvvm-script-parser",
- "version": "0.4.0-mvvm.2",
- "description": "",
- "main": "index.js",
- "scripts": {
- "test": "echo \"Error: no test specified\" && exit 1"
- },
- "author": "",
- "license": "ISC",
- "dependencies": {
- "@babel/core": "^7.3.4",
- "@babel/generator": "^7.4.0",
- "@babel/parser": "^7.3.4",
- "@babel/traverse": "^7.3.4",
- "@babel/types": "^7.3.4",
- "chameleon-tool-utils": "0.4.0-mvvm.2",
- "mvvm-interface-parser": "0.4.0-mvvm.2",
- "runtime-check": "0.4.0-mvvm.2"
- }
-}
\ No newline at end of file
diff --git a/packages/mvvm-script-parser/test/d.js b/packages/mvvm-script-parser/test/d.js
deleted file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000
diff --git a/packages/mvvm-script-parser/test/dependencies.js b/packages/mvvm-script-parser/test/dependencies.js
deleted file mode 100644
index 214f798b75f65b42a3efffddca261f7ee7638582..0000000000000000000000000000000000000000
--- a/packages/mvvm-script-parser/test/dependencies.js
+++ /dev/null
@@ -1,29 +0,0 @@
-let source = `import a from './a.js'
-import {b,c} from './b.js'
-import * as d from './c.js'
-const e = require('./d.js');
-require('./e.js')`
-
-
-const mvvmpack = require('../../mvvm-pack/index.js');
-const path = require('path');
-
-let compiler = new mvvmpack({
- config: {
- check: {
- enable: true, // 是否开启接口校验
- enableTypes: [] // 接口校验支持的类型 可以开启["Object","Array","Nullable"]
- }
- },
- logLevel: 3,
- cmlType: 'web',
- media: 'dev',
- cmlRoot: path.resolve('./'),
- projectRoot: path.resolve(__dirname, '../')
-})
-
-
-let parser = require('../index.js');
-
-
-let result = parser.JSCompile({source, compiler, realPath: path.join(__dirname, './dependencies.js')})
diff --git a/packages/mvvm-script-parser/test/e.js b/packages/mvvm-script-parser/test/e.js
deleted file mode 100644
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000