提交 4d8cce14 编写于 作者: Y yylgit

mvvm-cml-loader

上级 4cf448d5
......@@ -117,7 +117,6 @@ module.exports = function createHelpers (
) {
// console.log(fileType)
const rawRequest = getRawRequest(loaderContext, options.excludedPreLoaders)
const {
defaultLoaders,
loaders,
......
#! /usr/bin/env node
#! /usr/bin/env node --inspect-brk
// --inspect-brk
require('./lib/index.js');
......
module.exports = function({type, media}) {
const utils = require('./utils.js');
cml.media = media;
utils.startReleaseOne(media, type);
}
\ No newline at end of file
......@@ -20,6 +20,7 @@ exports.getBuildPromise = async function (media, type) {
if (~['wx', 'baidu', 'alipay'].indexOf(type)) {
// 异步删除output目录
var outputpath = webpackConfig.output.path;
if (outputpath) {
await new Promise(function(resolve, reject) {
fse.remove(outputpath, function(err) {
if (err) {
......@@ -32,6 +33,7 @@ exports.getBuildPromise = async function (media, type) {
cml.log.error(message);
throw new Error(e)
})
}
}
return new Promise(function(resolve, reject) {
......@@ -73,6 +75,13 @@ exports.getBuildPromise = async function (media, type) {
* @param {*} type wx web weex
*/
exports.getOptions = function (media, type) {
if (!~['web','weex','alipay','baidu','wx'].indexOf(type)) {
return {
type: type,
media,
root: cml.projectRoot
};
}
let chameleonConfig = cml.config.get()[type][media];
if (!chameleonConfig) {
......
......@@ -33,6 +33,9 @@ module.exports = function (options) {
}
publicPath = options.publicPath || defaultPublichPathMap[type];
if(!publicPath) {
publicPath =`http://${config.ip}:${webServerPort}/${type}/`
}
let commonConfig = {
......
......@@ -5,6 +5,7 @@ const getWeexDevConfig = require('./getWeexDevConfig.js');
const getWeexBuildConfig = require('./getWeexBuildConfig.js');
const getMiniAppDevConfig = require('./getMiniAppDevConfig.js');
const getMiniAppBuildConfig = require('./getMiniAppBuildConfig.js');
const getExtendConfig = require('./mvvm/getExtendConfig.js');
const utils = require('./utils');
/**
......@@ -20,6 +21,10 @@ module.exports = async function (options) {
await utils.setFreePort();
let {type, media} = options;
let webpackConfig;
debugger
if (cml.config.get().extPlatform && ~Object.keys(cml.config.get().extPlatform).indexOf(type)) {
webpackConfig = getExtendConfig(options);
} else {
switch (type) {
case 'wx':
case 'alipay':
......@@ -45,9 +50,9 @@ module.exports = async function (options) {
}
break;
default:
break;
}
}
cml.utils.applyPlugin('webpackConfig', { type, media, webpackConfig }, function(params) {
if (type === params.type && media === params.media) {
......
const loaderUtils = require('loader-utils')
module.exports = function(source) {
const self = this;
const rawOptions = loaderUtils.getOptions(this) || {};
const context = (
this.rootContext ||
(this.options && this.options.context) ||
process.cwd()
)
function getPartLoaders(part) {
let loaders = self.loaders.map(loader => {
let loaderOptions = loader.options || {}
let options = {
part
}
return {
loader: loader.path,
options: {
...loaderOptions,
...options
}
}
})
let stringLoaders = stringifyLoaders(loaders);
let resourcePath = self.resourcePath;
return '!'+stringLoaders + '!' + resourcePath;
}
if (!rawOptions.part) {
debugger
source = `
var template = require('${getPartLoaders('template')}');
var style = require('${getPartLoaders('style')}');
var json = require('${getPartLoaders('json')}');
var script = require('${getPartLoaders('script')}');
module.exports = {
template,
style,
json,
script
}
`
console.log(source);
debugger
} else {
debugger
source = rawOptions.part
}
return source;
}
function stringifyLoaders (loaders) {
return loaders
.map(
obj =>
obj && typeof obj === 'object' && typeof obj.loader === 'string'
? obj.loader +
(obj.options ? '?' + JSON.stringify(obj.options) : '')
: obj
)
.join('!')
}
\ No newline at end of file
const merge = require('webpack-merge')
const path = require('path');
// const cmlLoader = path.join(__dirname, './extCmlLoader.js');
const getCommonConfig = require('../getCommonConfig');
const utils = require('../utils.js');
module.exports = function(options) {
let {type, media} = options;
let extendConfig = {
entry: {
app: path.join(cml.projectRoot, 'src/app/app.cml')
},
output: {
path: path.join(cml.projectRoot, 'dist/' + type)
},
module: {
rules: [
...utils.styleLoaders({type}),
{
test: /\.cml$/,
use: [{
loader: 'mvvm-cml-loader',
options: {
loaders: utils.cssLoaders({type, media}),
cmlType: type,
media,
check: cml.config.get().check,
}
}]
}
]
},
plugins: [
{
apply(compiler) {
compiler.plugin('should-emit', function(compilation) {
debugger
})
}
}
]
};
return merge(getCommonConfig(options), extendConfig);
}
\ No newline at end of file
// https://github.com/michael-ciniawsky/postcss-load-config
module.exports = {
"plugins": {
// to edit target browsers: use "browserslist" field in package.json
"postcss-import": {},
}
}
\ No newline at end of file
......@@ -63,6 +63,22 @@ exports.cssLoaders = function (options) {
// generate loader string to be used with extract text plugin
function generateLoaders(loader, loaderOptions) {
// 扩展流程
if (cml.config.get().extPlatform && ~Object.keys(cml.config.get().extPlatform).indexOf(options.type)) {
let extLoaders = [
getPostCssLoader('extend'),
{
loader: loader + '-loader',
options: Object.assign({}, loaderOptions, {
sourceMap: false
})
}
]
addMediaLoader(extLoaders, options.type);
return extLoaders;
}
var loaders = [cssLoader];
let result = [];
......
......@@ -24,11 +24,21 @@ module.exports.run = function () {
// commanderInstance.registerCommander({commander: subCommander})
// })
// }
// 扩展端
const extendPlatform = require('../commanders/extendPlatform.js');
if (cml.config.get().platformPlugin && cml.config.get().platformPlugin[first]) {
extendPlatform({platform: first, media: argv[3]});
} else {
// const extendPlatform = require('../commanders/extendPlatform.js');
// if (cml.config.get().platformPlugin && cml.config.get().platformPlugin[first]) {
// extendPlatform({platform: first, media: argv[3]});
// }
const extPlatform = require('../commanders/extPlatform.js');
if (cml.config.get().extPlatform && ~Object.keys(cml.config.get().extPlatform).indexOf(first)) {
extPlatform({type: first, media: argv[3]});
}
else {
commander.usage('[command] [options]')
commander.version(`${cmlpackage.name}@${cmlpackage.version}`)
let cmdList = ['init', 'dev', 'build', 'server', 'web', 'weex', 'wx', 'baidu', 'alipay'];
......
......@@ -197,11 +197,6 @@
"@babel/types": "7.2.2"
}
},
"@babel/helper-plugin-utils": {
"version": "7.0.0",
"resolved": "http://registry.npm.xiaojukeji.com/@babel/helper-plugin-utils/download/@babel/helper-plugin-utils-7.0.0.tgz",
"integrity": "sha1-u7P77phmHFaQNCN8wDlnupm08lA="
},
"@babel/helper-split-export-declaration": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.0.0.tgz",
......@@ -648,7 +643,8 @@
"asap": {
"version": "2.0.6",
"resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz",
"integrity": "sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY="
"integrity": "sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY=",
"optional": true
},
"asn1": {
"version": "0.2.4",
......@@ -2213,7 +2209,6 @@
"resolved": "http://registry.npm.xiaojukeji.com/rework/download/rework-1.0.1.tgz",
"integrity": "sha1-MIBqhBNCtUUQqkEQhQzUhTQUSqc=",
"requires": {
"convert-source-map": "0.3.5",
"css": "2.2.4"
}
},
......@@ -2278,7 +2273,6 @@
"requires": {
"@babel/parser": "7.2.3",
"@babel/traverse": "7.2.3",
"bulk-require": "1.0.1",
"chalk": "2.4.2",
"chameleon-tool-utils": "0.3.0-alpha.2",
"cml-component-parser": "0.3.0-alpha.2",
......@@ -2316,10 +2310,8 @@
"resolved": "https://registry.npmjs.org/cml-htmllint/-/cml-htmllint-0.3.0-alpha.2.tgz",
"integrity": "sha512-oD/i71ivAGWppPmKAdsKj/jK1BvepHTAEOTqmdKwSpwLPFpzm2mHQdaBq9omLWflXkFE4JMH01aaeMtMRM7wgQ==",
"requires": {
"bulk-require": "1.0.1",
"htmlparser2": "3.10.0",
"lodash": "4.17.11",
"promise": "8.0.2"
"htmlparser2": "3.10.1",
"lodash": "4.17.11"
}
},
"cml-interface-parser": {
......@@ -2340,7 +2332,6 @@
"requires": {
"@babel/parser": "7.2.3",
"@babel/traverse": "7.2.3",
"bulk-require": "1.0.1",
"chameleon-tool-utils": "0.3.0-alpha.2"
}
},
......@@ -2504,7 +2495,6 @@
"requires": {
"@babel/generator": "7.2.2",
"@babel/parser": "7.4.3",
"@babel/plugin-syntax-jsx": "7.2.0",
"@babel/traverse": "7.2.3",
"@babel/types": "7.2.2",
"babylon": "6.18.0",
......@@ -7336,10 +7326,13 @@
"resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.7.tgz",
"integrity": "sha1-MHXOk7whuPq0PhvE2n6BFe0ee6s="
},
"mvvm-pack": {
"mvvm-cml-loader": {
"version": "0.0.1",
"resolved": "http://registry.npm.xiaojukeji.com/mvvm-pack/download/mvvm-pack-0.0.1.tgz",
"integrity": "sha1-vz6f751GJYc8pn2cmKrjBa22+vk="
"resolved": "https://registry.npmjs.org/mvvm-cml-loader/-/mvvm-cml-loader-0.0.1.tgz",
"integrity": "sha512-bUzxfNzMq/mcqAOlx03JIzyZNrrtUFrm1XF4zJm51bGrkEk0TfhaZkaCVo+Z/qQjSfSY0yqJD8pQ4OZtbUmJSA==",
"requires": {
"loader-utils": "1.2.3"
}
},
"nan": {
"version": "2.13.2",
......@@ -11462,14 +11455,6 @@
"integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==",
"dev": true
},
"promise": {
"version": "8.0.3",
"resolved": "http://registry.npm.xiaojukeji.com/promise/download/promise-8.0.3.tgz",
"integrity": "sha1-9ZLgmcbN3AANU47nKDuxkEUrC/Y=",
"requires": {
"asap": "2.0.6"
}
},
"promise-inflight": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/promise-inflight/-/promise-inflight-1.0.1.tgz",
......
......@@ -74,6 +74,7 @@
"less": "3.0.4",
"less-loader": "4.1.0",
"minimist": "1.2.0",
"mvvm-cml-loader": "0.0.1",
"mvvm-pack": "0.3.0-alpha.2",
"node-phpcgi": "0.3.7",
"node-watch": "^0.5.9",
......
......@@ -450,8 +450,8 @@ module.exports = function (content) {
output += 'module.exports.el = \'' + params.entry + '\'\n' +
'new Vue(module.exports)\n'
}
// console.log(output)
console.log(output)
debugger
// done
return output
}
......@@ -26,6 +26,7 @@ function convertLength (k, v) {
}
function genStyleString (input, loader) {
debugger
var output = '{}'
styler.parse(input, function (err, obj) {
if (err) {
......
......@@ -9,7 +9,6 @@ module.exports = function (source) {
let {cmlType, media, check = {}} = options;
const filePath = this.resourcePath;
let self = this;
debugger
const resolve = function(filePath, relativePath) {
let context = path.dirname(filePath);
......
{
// 在配置文件里配置全局变量时,使用 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, 40],
// 要求 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","double", "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
}
}
# Editor directories and files
.DS_Store
.idea
*.suo
*.ntvs*
*.njsproj
*.sln
# 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
dist/
# ///////////////////////////
const path = require('path');
exports.stringifyLoaders = function (loaders) {
return loaders
.map(
obj =>
obj && typeof obj === 'object' && typeof obj.loader === 'string'
? obj.loader +
(obj.options ? '?' + JSON.stringify(obj.options) : '')
: obj
)
.join('!')
}
exports.getSelector = function() {
return path.resolve(__dirname, './selector.js')
}
exports.getPartLoaders = function({selectorOptions, partType, lang, loaders, resourcePath}) {
selectorOptions.partType = partType;
let resultLoaders = [
{
loader: exports.getSelector(),
options: selectorOptions
}
]
switch (partType) {
case 'style':
var styleLoader = loaders[lang];
resultLoaders = styleLoader.concat(resultLoaders);
break;
case 'script':
var jsLoader = loaders.js;
resultLoaders = jsLoader.concat(resultLoaders);
break;
default:
break;
}
let stringLoaders = exports.stringifyLoaders(resultLoaders);
return '!' + stringLoaders + '!' + resourcePath;
}
const loaderUtils = require('loader-utils')
const helper = require('./helper.js');
const cmlUtils = require('chameleon-tool-utils');
module.exports = function(source) {
let output = '';
const self = this;
const rawOptions = loaderUtils.getOptions(this) || {};
let {loaders, cmlType, media, check} = rawOptions;
const resourcePath = this.resourcePath;
// const context = (
// this.rootContext ||
// (this.options && this.options.context) ||
// process.cwd()
// )
let selectorOptions = {
cmlType,
media,
check
}
let parts = cmlUtils.splitParts({content: source});
if (parts.style.length > 0) {
throw new Error(`${resourcePath} only allow has one <style></style>`)
}
if (parts.style && parts.style[0]) {
let part = parts.style[0];
let lang = part.attrs && part.attrs.lang || 'less';
output += `
var style = require('${helper.getPartLoaders({selectorOptions, partType: 'style', lang, loaders, resourcePath})}');
`
}
output += `
var template = require('${helper.getPartLoaders({selectorOptions, partType: 'template', loaders, resourcePath})}');
`
output += `
var json = require('${helper.getPartLoaders({selectorOptions, partType: 'json', loaders, resourcePath})}');
`
output += `
var script = require('${helper.getPartLoaders({selectorOptions, partType: 'script', loaders, resourcePath})}');
`
debugger
return output;
}
{
"name": "mvvm-cml-loader",
"version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Chameleon-Team",
"license": "Apache",
"dependencies": {
"chameleon-tool-utils": "^0.3.0-alpha.2",
"loader-utils": "^1.2.3"
}
}
const loaderUtils = require('loader-utils')
const cmlUtils = require('chameleon-tool-utils');
module.exports = function(source) {
const rawOptions = loaderUtils.getOptions(this) || {};
let {partType} = rawOptions;
let parts = cmlUtils.splitParts({content: source});
let output = '';
switch (partType) {
case 'style':
output = parts.style[0].content;
break;
case 'script':
parts.script.forEach(item => {
if (item.cmlType !== 'json') {
output = item.content;
}
})
break;
case 'template':
output = parts.template && parts.template[0] && parts.template[0].content;
break;
case 'json':
parts.script.forEach(item => {
if (item.cmlType === 'json') {
output = item.content;
}
})
break;
default:
break;
}
return output;
}
\ No newline at end of file
......@@ -74,6 +74,7 @@ class Compile {
]
this.resolve = this.resolve.bind(this);
this.outputFileList = {}; // 输出对象
}
// path 是源文件路径 request是要解析的路径
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册