2017新年大酬宾,七折!

New Blog Celebration

站点搬迁,算上这次,已经是第三次了,
Blogger -> Wordpress@Linode (for more flexible customizations and accessible)
Wordpress@Linode -> Hexo@Linode(严格意义上叫技术升级,由于多次被攻击,在白爷再三建议下更替成静态的hexo),
Hexo@Linode -> Hexo@Coding.net (Linode的访问速度让我十分渴望被看见的愿望不能实现,而且每月都有10$的费用)

再次特别鸣谢伟大的白爷,您就是我的掌中宝,您就是我的引魂幡,是遗失千年的金虎符,是历久弥新的打神鞭。

linode在取消账户的一瞬间,又扣除了我10$的费用,我于是Skype去问询,我才反应过来这个是post-paid order,你要走利索之前得把现在这月已经用了的给结了。

The right way to initialize your node js dev environment.

Just follow the steps below, if you already installed node from the official website by the .pkg file or by home brew, You might still have some trivia problems like:

1
-bash npm: command not found

The hexo official site claim that the most reliable way to set up a node js env is to install the whole workspace by nvm. Please remove your current node js completely first, by commands below:

1
2
3
4
5
6
sudo npm uninstall npm -g
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
sudo rm -rf /usr/local/include/node /Users/$USER/.npm
sudo rm /usr/local/bin/node
sudo rm /usr/local/share/man/man1/node.1
sudo rm /usr/local/lib/dtrace/node.d

After these , install nvm by curl

1
curl https://raw.github.com/creationix/nvm/master/install.sh | sh

Or by wget

1
wget -qO- https://raw.github.com/creationix/nvm/master/install.sh | sh

If you don’t have wget installed ,run

1
brew install wget

Then, run this to install node js:

1
nvm install stable

After this you should have installed the correct environment .

Gulp

在学习了两天Grunt之后,我发现自己完全没有将其应用在现有项目中的兴趣。在Andy忽然问起有什么好的适合做js开发体系的自动化体系时,我忽然想起与grunt其名的另外一个体系,Gulp,嗯,都是拟声词,都是node阵营中的明星产品,事后证明,人还是有自己的倾向性的,就像我逃过了暴雪的三板斧,Star Craft,War Craft,Diablo,却还是没能躲过Overwatch一样,我没能热衷Ant,无法投入Grunt,最后还是一头扎进了Gulp的盆地。

相比较于Grunt,Gulp让人感觉更像是在跟人说话。先录入第一天试玩的部分问题。我要实现的:
任务流1,本地发布调试:

  1. 读取配置文件
  2. 编译egret项目,
  3. 按照配置版本发布egret项目
  4. 在发布项目的路径启动一个webserver服务。
  5. 在浏览器中打开启动好了的项目文件。
  6. 监控配置文件,发现有变动时重新执行上述2-4步。

任务流2,部署到远程服务器。
包含上述的1-3步。
4. 上传发布好的版本文件到远程sftp。
5. 在浏览器中打开远程的可访问地址。

百花齐放的类库,让我十分容易地找到了满足上述任务的所有类库。

以下为代码部分:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
let gulp = require('gulp');
let data = require('gulp-data');
let exec = require('gulp-exec');
let webserver = require('gulp-webserver');
let rename = require("gulp-rename");
let pkg = require('./package.json');
let config;
let reportOptions = {
err: true,
stderr: true,
stdout: true
};
let serverOptions = {
livereload: {
enable: true, // need this set to true to enable livereload
filter: function (fileName) {
if (fileName == 'index.html') { // exclude all source maps from livereload
return true;
} else {
return false;
}
}
},
directoryListing: false,
open: true,
};


//Task for local release

gulp.task('config', function () {
return gulp.src('./gulpconfig.json')
.pipe(data(function (file) {
config = require(file.path);
}));
})
gulp.task('egret_b', ['config'], function () {
return gulp.src('./gulpconfig.json')
.pipe(exec('egret build'))
.pipe(exec.reporter(reportOptions))
});

gulp.task('egret_r_1920', ['egret_b'], function () {
return gulp.src('./html_temp/index_1920.html')
.pipe(rename('index.html'))
.pipe(gulp.dest('./',{overwrite:true}))
.pipe(exec('egret publish --version ' + config['version']+'_1920'))
.pipe(exec.reporter(reportOptions));
});

gulp.task('egret_r_1440', ['egret_r_1920'], function () {
return gulp.src('./html_temp/index_1440.html')
.pipe(rename('index.html'))
.pipe(gulp.dest('./',{overwrite:true}))
.pipe(exec('egret publish --version ' + config['version']+'_1440'))
.pipe(exec.reporter(reportOptions));
});
gulp.task('local_server', ['egret_r_1440'], function () {
return gulp.src('./bin-release/web/' + config['version']+ '_1920' + '/')
.pipe(webserver(serverOptions));
});

gulp.task('w_b_r_ls', ['local_server']);

gulp.watch('./gulpconfig.json', ['egret_b_r']);


//Task for deply
let gutil = require('gulp-util');
let sftp = require('gulp-sftp');
let open = require('gulp-open');
gulp.task('deploy', ['egret_r_1440'], function () {
console.log(process.argv);

var globs = [
'bin-release/web/' + config['version'] + '_1920/**',
'bin-release/web/' + config['version'] + '_1440/**'
];
return gulp.src(globs[0])
.pipe(sftp({
host: config['ftp_host'],
user: config['ftp_user'],
pass: config['ftp_pwd'],
remotePath: config["ftp_target_path"]+"/1920",
}))
.pipe(gulp.src(globs[1]))
.pipe(sftp({
host: config['ftp_host'],
user: config['ftp_user'],
pass: config['ftp_pwd'],
remotePath: config["ftp_target_path"]+"/1440",
callback: function () {
gulp.src(__filename)
.pipe(open({ uri: config['ftp_show_url']+"/1440"}));
setTimeout(function () {
process.exit();
}, 1000);
}
}));
});

小雷

需要注意的是,当执行任务有先后顺序时,不要依赖gulp.task中的deps参数,尤其是当依赖的任务是执行外部命令的任务的时候。
靠谱的做法是,建立一一对应的依赖关系,例如,当你想要做的是

1
2
3
gulp.task('taskC',['execA','execB'],function(){

});

execA与execB并未如预期一样顺序执行,而是taskC先执行了。
为了实现顺序执行的效果,应该实行如下定义方式

1
2
3
4
5
6
7
8
9
10
11
12
gulp.task('execA',function(){
return gulp.src(__filename)
.pipe(exec('cmd A'));
});

gulp.task('execB',['execA'],function(){
return gulp.src(__filename)
.pipe(exec('cmd B'));
});
gulp.task('taskC',['execB'],function(){

});

一定要return对应的gulp pipe,才会得到流式顺序执行的效果。

Overwatch

最近的Overwatch服务器,简直就是烂成了屎,正因为我是如此热爱这款游戏,现在才会在遭遇这样的情况时,想要呈现与路怒症类似的状态。简直就是要憋闷到死。

French

我有一搭没一搭的,在用一个感觉很业余,但是发音还算准确的App学习法语单词,现在也开始能发出喉舌音了,就是要吐痰的那种。

七折

该来的还是会来,今天下午全体股东先给技术部门的白名单成员开了会,从现在开始,到4月份的三个月内,我们所有人工资都按70%发,我可以看出公司在努力保留我们的核心团队,外面世道也确实是不好。难免也会让我有江河日下之感。

这是一篇,用来做新年开篇,十分不合格的Blog,好在在我十分郁闷的时候,有亲人和挚友的支持,刚刚也才发现,默默地形成了B(白爷)A(ndy)T(iger)组合。