Skip to content

Commit 97aa573

Browse files
author
AceMood
committed
update neo and tplloader
1 parent f89f1bd commit 97aa573

File tree

97 files changed

+702
-997
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+702
-997
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@
1010

1111
.idea/
1212
.DS_Store
13+
# local packages
1314
node_modules
1415
private
16+
# files during development
17+
lib/command/install.js
18+
lib/command/server.js
19+
samples/install
1520

1621
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
1722
hs_err_pid*

README.md

+16-11
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,50 @@
1010

1111
![sloc stats](./doc/assets/sloc.png "sloc stats")
1212

13-
**s.o.i** 是一个前端项目构建打包构建工具内部集成了 [neo](https://github.com/AceMood/neo) 作为其资源扫描器soi相当于neo的后处理服务提供常见的打包插件如压缩、合并、文件指纹、CommonJS包装、less解析等等
13+
**s.o.i** 是一个前端项目构建打包构建工具, 内部集成了 [neo](https://github.com/AceMood/neo) 作为其资源扫描器, soi相当于neo的后处理服务, 提供常见的打包插件, 如压缩、合并、文件指纹、CommonJS包装、less解析等等.
1414

1515
## 安装
16-
确保本地安装了 node 安装包大于v1.0.0版本),通过包管理器 npm 进行安装
16+
确保本地安装了 node 安装包(大于v1.0.0版本), 通过包管理器 npm 进行安装.
1717

1818
**注意**
1919

20-
若安装过v0.14.0之前版本的 **soi**需要通过以下命令卸载依赖的 soi-cli
20+
若安装过v0.14.0之前版本的 **soi**, 需要通过以下命令卸载依赖的 soi-cli
2121

2222
```
2323
npm uninstall -g soi-cli
2424
```
25-
原因是老版本的 **soi** 绑定命令行执行是由 soi-cli 模块实现的而新版的 **soi** 内部就直接通过 package.json 的 bin 字段绑定了不再需要 soi-cli 模块
25+
原因是老版本的 **soi** 绑定命令行执行是由 soi-cli 模块实现的, 而新版的 **soi** 内部就直接通过 package.json 的 bin 字段绑定了, 不再需要 soi-cli 模块.
2626

27-
如第一次安装 **soi**或者之前没有安装过 soi-cli则直接运行以下脚本:
27+
如第一次安装 **soi**, 或者之前没有安装过 soi-cli, 则直接运行以下脚本:
2828

2929
```
3030
npm install -g soi
3131
```
3232

33-
安装新版本 **soi** 切记加 -g 全局安装标志这样可以在任意目录使用 **soi** 构建前端项目
33+
安装新版本 **soi** 切记加 -g 全局安装标志, 这样可以在任意目录使用 **soi** 构建前端项目.
3434

35-
接着安装 soi 依赖模块进入 soi 模块的安装目录运行
35+
接着安装 soi 依赖模块, 进入 soi 模块的安装目录, 运行
3636

3737
```
3838
npm install
3939
```
4040

4141
## 使用
42-
在任意目录建立你的代码仓库开发完毕后在此目录添加配置文件:
42+
在任意目录建立你的代码仓库, 开发完毕后在此目录添加配置文件:
4343
```
4444
soi.conf.js
4545
```
46-
在 soi 的安装目录 samples 下会有示例项目,分别对应 **soi release** 任务和 **soi deploy** 任务。
46+
在 soi 的安装目录 samples 下会有示例项目, 分别对应 **soi release** 任务和 **soi deploy** 任务.
47+
48+
**注意**
49+
资源扫描器在扫描目录的时候默认会跳过`_`开头的文件名, 在一些预处理插件中可以把诸如提供假数据的js文件或者抽想出来的变量、函数
50+
的less文件名改成`_`开头, 在产出时不会产生空文件. 另一种做法是配置扫描器的ignorePaths属性或者插件的ignore属性(内置插件都
51+
支持), 这个函数可以接受文件的工程路径作为参数, 返回true则表示忽略此资源.
4752

4853
## 未来
49-
**soi** 力求future proof包括其插件体系的实现分离编译工具为资源扫描和后处理服务插件正是为此灵感和启发来自于 Facebook 的 **Haste Internals**国内方面前辈有百度的 **F.I.S**
54+
**soi** 力求future proof, 包括其插件体系的实现. 分离编译工具为资源扫描和后处理服务插件正是为此. 灵感和启发来自于 Facebook 的 **Haste Internals**, 国内方面前辈有百度的 **F.I.S**.
5055

51-
未实现的部分或者还不满意的部分[参见todo](./doc/todos.md)其中最迫不及待就是对于html静态资源的扫描和基于ipc方式实现的编译缓存
56+
未实现的部分或者还不满意的部分[参见todo](./doc/todos.md), 其中最迫不及待就是对于html静态资源的扫描和基于ipc方式实现的编译缓存.
5257

5358

5459
[travis-image]: https://img.shields.io/travis/Saber-Team/soi.svg?style=flat-square

lib/Task.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,10 @@ function insertQueue(queue, resource) {
392392
let requires;
393393
let attr;
394394

395-
if (resource.type === 'JS') {
395+
if (resource.type === 'js') {
396396
requires = resource.requiredModules;
397397
attr = 'requiredModules';
398-
} else if (resource.type === 'CSS') {
398+
} else if (resource.type === 'css') {
399399
attr = 'requiredCSS';
400400
requires = resource.requiredCSS;
401401
}

lib/compiler/js.js

+16-14
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,10 @@ const exec = exports.exec = function(resource, map, rule, emitter) {
6767
return $0;
6868
}
6969

70-
// original id may be changed, but getModuleIDByOrigin
71-
// still record the old path as module Id.
72-
let originalModuleId = resource.getModuleIDByOrigin($1);
73-
let inlineResource = map.getResource('JS', originalModuleId) ||
74-
map.getResourceByPath(originalModuleId);
70+
// original id may be changed, but getModulePathByOrigin
71+
// still record the old module's path.
72+
let modulePath = resource.getModulePathByOrigin($1);
73+
let inlineResource = map.getResourceByPath(modulePath);
7574

7675
if (inlineResource) {
7776
if (!inlineResource.isCompiled) {
@@ -89,8 +88,10 @@ const exec = exports.exec = function(resource, map, rule, emitter) {
8988
}
9089
return $0.replace($1, inlineResource.id);
9190
} else {
92-
soi.log.warn('JS file refer to [' + $1 + '] in file [' +
93-
resource.path + '] Not found');
91+
soi.log.error(
92+
`JS file refer to [${$1}] in file [${resource.path}] Not found`
93+
);
94+
process.exit(0);
9495
}
9596

9697
return $0;
@@ -108,20 +109,21 @@ const exec = exports.exec = function(resource, map, rule, emitter) {
108109
return;
109110
}
110111

111-
// original id may be changed, but getModuleIDByOrigin
112-
// still record the old path as module Id.
113-
let originalModuleId = resource.getModuleIDByOrigin(dep);
114-
let inlineResource = map.getResource('JS', originalModuleId) ||
115-
map.getResourceByPath(originalModuleId);
112+
// original id may be changed, but getModulePathByOrigin
113+
// still record the old module's path.
114+
let originalModuleId = resource.getModulePathByOrigin(dep);
115+
let inlineResource = map.getResourceByPath(originalModuleId);
116116

117117
if (inlineResource) {
118118
if (!inlineResource.isCompiled) {
119119
exec(inlineResource, map, rule, emitter);
120120
}
121121
ret.push('"' + inlineResource.id + '"');
122122
} else {
123-
soi.log.warn('JS file refer to [' + $1 + '] in file [' +
124-
resource.path + '] Not found');
123+
soi.log.error(
124+
`JS file refer to [${$1}] in file [${resource.path}] Not found`
125+
);
126+
process.exit(0);
125127
}
126128
});
127129

lib/name2plugin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
'use strict';
2929

3030
module.exports = {
31-
'css' : './plugin/csscompress',
31+
'css' : './plugin/css',
3232
'less' : './plugin/lesscompiler',
3333
'hash' : './plugin/fingerprint',
3434
'uglify' : './plugin/uglifier',

lib/plugin/csscompress.js lib/plugin/css.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class Compressor {
4949
}
5050

5151
exec(resource) {
52-
if (resource.type === 'CSS' && !this.ignore(resource.path)) {
52+
if (resource.type === 'css' && !this.ignore(resource.path)) {
5353
let code = resource.getContent();
5454
let ast;
5555
try {

lib/plugin/fingerprint.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class Fingerprint {
4242
this.options.noname = !!options.noname;
4343
this.options.connector = options.connector || '.';
4444
this.ignore = options.ignore || soi.fn.FALSE;
45-
this.ext = options.ext || ['Image', 'JS', 'CSS'];
45+
this.ext = options.ext || ['image', 'js', 'css'];
4646
}
4747

4848
init(task) {

lib/plugin/idgenerator.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class IdGenerator {
4040
this.options.encoding = options.encoding || 'base64';
4141
this.options.length = options.length || 5;
4242
this.ignore = options.ignore || soi.fn.FALSE;
43-
this.ext = options.ext || ['Image', 'JS', 'CSS'];
43+
this.ext = options.ext || ['image', 'js', 'css'];
4444
}
4545

4646
init(task) {
@@ -75,21 +75,21 @@ class IdGenerator {
7575
map.getAllResources().forEach(resource => {
7676
if (resource.requiredCSS) {
7777
resource.requiredCSS = resource.requiredCSS.map(id => {
78-
let r = map.resourceMap.CSS[id];
78+
let r = map.resourceMap.css[id];
7979
return r.sid || r.id;
8080
});
8181
}
8282

8383
if (resource.requiredModules) {
8484
resource.requiredModules = resource.requiredModules.map(id => {
85-
let r = map.resourceMap.JS[id];
85+
let r = map.resourceMap.js[id];
8686
return r.sid || r.id;
8787
});
8888
}
8989

9090
if (resource.requiredAsyncModules) {
9191
resource.requiredAsyncModules = resource.requiredAsyncModules.map(id => {
92-
let r = map.resourceMap.JS[id];
92+
let r = map.resourceMap.js[id];
9393
return r.sid || r.id;
9494
});
9595
}

lib/plugin/lesscompiler.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ let defaultOptions = {
4141

4242
class LessCompiler {
4343
constructor(options) {
44-
options = options || {};
44+
options = options || {};
4545
this.options = soi.util.merge({}, defaultOptions, options);
46+
this.ignore = options.ignore || soi.fn.FALSE;
4647
}
4748

4849
init(task) {
@@ -53,16 +54,19 @@ class LessCompiler {
5354

5455
exec(resource) {
5556
let plug = this;
56-
if (resource.type === 'CSS' && /\.less$/.test(resource.path)) {
57+
if (resource.type === 'css'
58+
&& /\.less$/.test(resource.path)
59+
&& !this.ignore(resource.path)) {
60+
5761
// 需要替换filename为真正编译的文件路径,否则import指令相对路径找不到
5862
plug.options.filename = node_path.resolve(resource.path);
59-
lessc.render(resource.getContent(), plug.options, function(err, output) {
63+
lessc.render(resource.getContent(), plug.options, (err, output) => {
6064
if (err) {
61-
soi.log.error(`Parse less[${resource.path}], [${err.message}]`);
65+
soi.log.error(`Parse file [${resource.path}], [${err.message}]`);
6266
process.exit();
6367
}
6468

65-
resource.setContent(output.css)
69+
resource.setContent(output.css);
6670
});
6771
}
6872
}

lib/plugin/modulewrapper.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class CommonJSWrapper {
5050
}
5151

5252
exec(resource) {
53-
if (resource.type === 'JS' && !this.ignore(resource.path)) {
53+
if (resource.type === 'js' && !this.ignore(resource.path)) {
5454
if (resource.isModule) {
5555
let content =
5656
this.options.commentdoc + this.options.define + '("' +

lib/plugin/replacer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Replacer {
3232
options = options || {};
3333
this.options = options;
3434
this.ignore = options.ignore || soi.fn.FALSE;
35-
this.ext = options.ext || ['HTML', 'CSS', 'JS'];
35+
this.ext = options.ext || ['html', 'css', 'js'];
3636
}
3737

3838
init(task) {

lib/plugin/uglifier.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Uglifier {
4747

4848
exec(resource) {
4949
// 跳过permanent的资源
50-
if ((resource.type === 'JS')
50+
if ((resource.type === 'js')
5151
&& !this.ignore(resource.path)
5252
&& !resource.isPermanent) {
5353

lib/soi.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const queryCommand = function(command) {
7171

7272
// 配置相关, 默认配置如下
7373
var __CONFIG = {
74-
types: ['JS', 'CSS'],
74+
types: ['js', 'css'],
7575
forceRescan: false,
7676
logLevel: log.Level.INFO
7777
};
@@ -183,9 +183,9 @@ Object.defineProperties(soi, {
183183
});
184184

185185
// 添加默认编译函数
186-
soi.addCompiler('JS', jscompiler);
187-
soi.addCompiler('CSS', csscompiler);
188-
soi.addCompiler('Image', imgcompiler);
186+
soi.addCompiler('js', jscompiler);
187+
soi.addCompiler('css', csscompiler);
188+
soi.addCompiler('image', imgcompiler);
189189

190190
// 注册默认命令
191191
soi.registerCommand('release', release);

lib/util.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ const shimMap = exports.shimMap = function(resourceMap) {
370370
};
371371

372372
// 为资源保留异步加载
373-
if (item.type === 'JS' && item.isNonblocking) {
373+
if (item.type === 'js' && item.isNonblocking) {
374374
m.resource[type][item.id].async = true;
375375
}
376376

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"et-util-logger": "^1.1.0",
3131
"less": "^2.5.3",
3232
"minimatch": "^3.0.2",
33-
"neo-core": "^0.7.0",
33+
"neo-core": "^0.7.2",
3434
"uglify-js": "^2.6.1"
3535
},
3636
"devDependencies": {

0 commit comments

Comments
 (0)