Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Commit

Permalink
CI
Browse files Browse the repository at this point in the history
  • Loading branch information
NewFuture committed Feb 23, 2019
1 parent 6a5e83c commit 609587f
Show file tree
Hide file tree
Showing 11 changed files with 131 additions and 71 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,6 @@ typings/
# next.js build output
.next

dist/
dist/

package-lock.json
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sudo: false
language: node_js
node_js:
- "4"
- "6"
- "8"
- "10"
- "latest"
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ A command line tool to build & watch MiniProgram.

### quick start

show all commands

```
npx miniprogram-build -h
```
Expand Down Expand Up @@ -44,8 +46,8 @@ Options:
```
--version show version number <查看本版号> [boolean]
--release production mode <发布模式会优化压缩> [boolean] [default: false]
--src source folder <源文件目录> [string] [default: "./src"]
--dist output folder <编译输出目录> [string] [default: "./dist"]
--src source folder <源文件目录> [string] [default: "src"]
--dist output folder <编译输出目录> [string] [default: "dist"]
--exclude ignored files <编译忽略文件(夹)> [array]
--tsconfig typescript config file <TS配置,未设置会自动查找tsconfig.json>
--copy files to copy <复制的文件>
Expand Down Expand Up @@ -79,7 +81,7 @@ mp-build build --config=./config.prod.json --release
"src": "src",
"dist": "dist",
"assets": "assets",
"copy": "copy",
"copy": "",
"exclude": [],
"tsconfig": "tsconfig.json",
"var": {
Expand Down
5 changes: 4 additions & 1 deletion bin/mp-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
var config = require("../src/load-config");
var tasks = require("../src/task");
var argv = require("yargs")
.scriptName("miniprogram-build")
.scriptName("mp")
.usage("\nMiniProgram build tools <小程序编译打包工具>")
.usage("Usage <用法>:\n $0 [command...] [--option]")
.usage("FullName <完整名称>:\n miniprogram-build [command...] [--option]")
.example("$0 dev", "编译并监测文件变化")
.example("$0 --config=mpconfig.json", "指定配置文件")
.example("$0 --release --var.APP_ID=1234", "优化编译")
Expand Down Expand Up @@ -65,6 +66,8 @@ var argv = require("yargs")
.command("clean", "remove all files in dist <清理dist>")
.command("compile", "compile all source files to dist <编译所有源文件>")
.command("js", "compile ts/js files to `.js` <编译生成js>")
.command("typescript", "compile ts files to `.js` <编译ts>")
.command("javascript", "compile js <编译js>")
.command("wxss", "compile scss/sass/css/wxss to `.wxss` <编译生成wxss>")
.command("wxml", "compile html/wxml files to `.wxml` <编译生成wxml>")
.command("json", "compile all json/jsonc files to json <编译生成json>")
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"bin/"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "npm test --prefix=test"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -53,7 +53,6 @@
"gulp-sourcemaps": "^2.6.5",
"gulp-typescript": "^5.0.0",
"json5": "^2.1.0",
"merge-stream": "^1.0.1",
"mime": "^2.4.0",
"through2": "^3.0.0",
"yargs": "^13.2.1"
Expand Down
1 change: 1 addition & 0 deletions src/compiler/compile-typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function compileTS(config, tsFile) {
var src = tsFile ? gulp.src(tsFile, { base: config.src, sourcemaps: !config.release }) : tsProject.src();
// console.log(tsFile,src)
return src
.on("error", error(TITLE))
.pipe(debug({ title: TITLE }))
.pipe(config.release ? empty() : sourcemaps.init())
.pipe(replace(config.var, undefined, "{{", "}}"))
Expand Down
19 changes: 14 additions & 5 deletions src/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ var colors = require('ansi-colors');
var path = require('path');

var taskLog = require('./log/task-log');
var error = require('./log/error');


var typescript = require('./tasks/typescript');
var javascript = require('./tasks/javascript');

var js = require('./tasks/js');
var wxss = require('./tasks/wxss');
var json = require('./tasks/json');
var wxml = require('./tasks/wxml');
Expand Down Expand Up @@ -41,16 +45,19 @@ exports.$execute = function (tasks) {
}
});
}

gulp.task('js', js.build(exports.$config));
gulp.task('typescript', typescript.build(exports.$config));
gulp.task('javascript', javascript.build(exports.$config));
gulp.task('js', gulp.parallel('typescript', 'javascript'));
gulp.task('wxss', wxss.build(exports.$config));
gulp.task('wxml', wxml.build(exports.$config));
gulp.task('json', json.build(exports.$config));
gulp.task('image', image.build(exports.$config));
gulp.task('copy', copy.build(exports.$config));
gulp.task('npm', npm.build(exports.$config));

gulp.task('js-watch', js.watch(exports.$config));
gulp.task('typescript-watch', typescript.watch(exports.$config));
gulp.task('javascript-watch', javascript.watch(exports.$config));
gulp.task('js-watch', gulp.parallel('typescript-watch', 'javascript-watch'));
gulp.task('wxss-watch', wxss.watch(exports.$config));
gulp.task('wxml-watch', wxml.watch(exports.$config));
gulp.task('json-watch', json.watch(exports.$config));
Expand All @@ -75,4 +82,6 @@ gulp.task('watch', gulp.series(
);

//开发模式
gulp.task('dev', gulp.series('build', 'watch'));
gulp.task('dev', gulp.series('build', 'watch'));

gulp.on('error', error('gulp'));
39 changes: 39 additions & 0 deletions src/tasks/javascript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
///@ts-check
"use strict";
var gulp = require("gulp");
var fs = require("fs");
var path = require("path");
var compileJs = require("../compiler/compile-javascript");
var unlink = require("../lib/unlink");
var extToGlob = require("../lib/ext-to-glob");
var watchLog = require("../log/watch");

var JS_EXTS = ["js", "wxs"];
/**
* @param {object} config
*/
exports.build = function (config) {
return function () {
return compileJs(config, extToGlob(config, JS_EXTS));
};
};


/**
* @param {object} config
*/
exports.watch = function (config) {
return function (cb) {
var glob = extToGlob(config, JS_EXTS);
watchLog("js", glob);
gulp.watch(glob)
.on("change", function (file) {
return compileJs(config, file);
})
.on("add", function (file) {
return compileJs(config, file);
})
.on("unlink", unlink(config.src, config.dist, ".js"));
cb && cb();
};
};
57 changes: 0 additions & 57 deletions src/tasks/js.js

This file was deleted.

54 changes: 54 additions & 0 deletions src/tasks/typescript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
///@ts-check
"use strict";
var gulp = require("gulp");
var fs = require("fs");

var log = require('fancy-log');
var colors = require('ansi-colors');

var compileTs = require("../compiler/compile-typescript");
var unlink = require("../lib/unlink");
var extToGlob = require("../lib/ext-to-glob");
var watchLog = require("../log/watch");

var TS_EXTS = ["ts"];
/**
* @param {object} config
*/
exports.build = function (config) {
if (config.tsconfig || fs.existsSync("tsconfig.json")) {
return function () {
config.tsconfig = config.tsconfig || "tsconfig.json";
return compileTs(config);
}
} else {
log(
colors.cyan('npm:'),
colors.gray('`tsconfig.json` was found. Skip typescript compilation!'),
);
return function (cb) {
cb && cb();
}
}
};

/**
* @param {object} config
*/
exports.watch = function (config) {
return function (cb) {
var glob = extToGlob(config, TS_EXTS);
watchLog("js", glob);
gulp.watch(glob, {
ignored: config.src + "/*/**.d.ts",
})
.on("change", function (file) {
return compileTs(config, file);
})
.on("add", function (file) {
return compileTs(config, file);
})
.on("unlink", unlink(config.src, config.dist, ".js"));
cb && cb();
};
};
4 changes: 2 additions & 2 deletions test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"description": "",
"main": "index.js",
"scripts": {
"build": "node ../bin/mp-build.js",
"test": "echo \"Error: no test specified\" && exit 1"
"start": "node ../bin/mp-build.js",
"test": "npm start build"
},
"keywords": [],
"author": "",
Expand Down

0 comments on commit 609587f

Please sign in to comment.