Skip to content

Commit

Permalink
Merge pull request #2 from icaife/release/v1.6
Browse files Browse the repository at this point in the history
Release/v1.6
  • Loading branch information
小菜 committed Feb 8, 2018
2 parents 6ee25ad + 67e4942 commit dae7ed3
Show file tree
Hide file tree
Showing 27 changed files with 7,617 additions and 11,650 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Based on webpack@3.x
- [x] ES6 Support
- [x] VUE Supported
- [ ] Mock Server
- [x] Parallel
- [ ] TODO MORE...


Expand All @@ -53,8 +54,10 @@ tailor -e test

- ### Options
- **e**: environment,`dev`、`test`、`prod`,default `dev`
- **c**: config, json config in CLI
- **c**: config, json config in CLI,will rewrite the default config
- **f**: config file
- **r**: regexp for modules which are compiled
- **p**: parallel,multiple threads support

- ### Env config
- tailor.config.json
Expand All @@ -69,4 +72,6 @@ tailor -e test
tailor -e dev (default)
tailor -e test -f custom.env.json
tailor -e test -c {output:{path:'custom-dest'},input:{path:'custom-src'}}
tailor -r product
tailor -p parallel
```
147 changes: 84 additions & 63 deletions bin/tailor.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,75 +9,95 @@
* tailor -e dev
*/

const
Yargs = require("yargs"),
Path = require("path"),
FSE = require("fs-extra"),
Log = require("../lib/util/log"),
_ = require("lodash"),
tryRequire = require("try-require"),
pkg = require("../package.json"),
tailor = require("../index.js"),
preCommit = require("../lib/hook/pre-commit.js"),
ENV = require("../constant/env.js"),
OPTIONS = {
e: "env",
h: "help",
f: "file",
r: "r",
c: "config"
},
CONFIG_FILE = "tailor.config.json",
configDir = Path.join(process.cwd(), "config"),
argv = Yargs
.usage("Usage: $0 <command> [options]")
.default("e", ENV.dev) //default development
.default("c", {})
.default("f", CONFIG_FILE)
.default("r", false)
.alias("h", "help")
.alias("f", "file")
.alias("e", "env")
.alias("c", "config")
.alias("v", "version")
.alias("r", "reg")
.epilog("toursforfun.com copyright 2017 ")
.argv;

const Yargs = require("yargs"),
Path = require("path"),
FSE = require("fs-extra"),
Log = require("../lib/util/log"),
_ = require("lodash"),
tryRequire = require("try-require"),
pkg = require("../package.json"),
tailor = require("../index.js"),
preCommit = require("../lib/hook/pre-commit.js"),
ENV = require("../constant/env.js"),
OPTIONS = {
e: "env",
h: "help",
f: "file",
r: "reg",
c: "config",
p: "parallel"
},
CONFIG_FILE = "tailor.config.json",
configDir = Path.join(process.cwd(), "config"),
date = new Date(),
argv = Yargs.usage("Usage: $0 <command> [options]")
.option("help", {
alias: "h"
})
.option("file", {
alias: "f",
default: CONFIG_FILE,
describe: "Config file to use"
})
.option("env", {
alias: "e",
default: ENV.dev,
describe: "Current evnironment"
})
.option("config", {
alias: "c",
default: {},
describe: "Config in command, JSON like"
})
.option("version", {
alias: "v"
})
.option("reg", {
alias: "r",
default: false,
describe: "Entry name matched to build"
})
.option("parallel", {
alias: "p",
default: true,
describe: "Multiple thread support"
})
.epilog("toursforfun.com copyright " + date.getFullYear()).argv;

if (argv.version) {
Log.info(`${pkg.version}`);
process.exit(0);
Log.info(`${pkg.version}`);
process.exit(0);
}

if (argv.help) {
Log.info(`please see: https://github.com/icaife/tailor for help.`);
process.exit(0);
Log.info(`please see: https://github.com/icaife/tailor for help.`);
process.exit(0);
}

argv.parallel = argv.parallel + "" === "true" || false;

if (!tryRequire(Path.join(configDir, argv.file))) {
Log.error(`not found the ${argv.file} in ${configDir},please check.`);
process.exit(1);
Log.error(`not found the ${argv.file} in ${configDir},please check.`);
process.exit(1);
}

let
config = {};
let config = {};

try {
let projConfig = require(Path.join(configDir, argv.file));
let projConfig = require(Path.join(configDir, argv.file));

argv.env = ENV[argv.env] ? ENV[argv.env] : ENV.dev;

config = _.merge({},
require("../config/config.json"),
projConfig.base,
projConfig[argv.env] || {},
fixJson(argv.c)
);
argv.env = ENV[argv.env] ? ENV[argv.env] : ENV.dev;

config = _.merge(
{},
require("../config/config.json"),
projConfig.base,
projConfig[argv.env] || {},
fixJson(argv.c)
);
} catch (e) {
Log.error(e.message);
process.exit(1);
Log.error(e.message);
process.exit(1);
}

//set env
Expand All @@ -86,24 +106,25 @@ config.env = ENV[argv.env];
config.root = Path.resolve(process.cwd());
//set tailor config
config.tailor = {
path: Path.resolve(__dirname, "../")
path: Path.resolve(__dirname, "../")
};
//set reg
config.reg = argv.reg ? new RegExp(argv.reg, "img") : /./;
config.reg = typeof argv.reg === "string" ? new RegExp(argv.reg, "img") : /./;
config.parallel = argv.parallel;

let cmd = (argv._ || [])[0];

if (cmd === "hook") {
preCommit(config); //install hook
process.exit(0);
preCommit(config); //install hook
process.exit(0);
}

tailor(config);

function fixJson(str) {
if (typeof str !== "string" || !str) {
return {};
}
if (typeof str !== "string" || !str) {
return {};
}

return eval("(" + str + ")");
}
return eval("(" + str + ")");
}
75 changes: 44 additions & 31 deletions config/base/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,47 @@

"use strict";

const
_ = require("lodash"),
Glob = require("glob"),
Path = require("path");

module.exports = (config) => {
let entries = {},
inputConfig = config.input,
cwd = Path.join(config.root, inputConfig.path),
entryConfig = inputConfig.entry,
glob = "**",
prefix = entryConfig.prefix,
ext = entryConfig.ext,
options = {
cwd: cwd,
sync: true
},
globInstance = new Glob.Glob(`${glob}/${prefix}.${ext}`, options),
dirs = globInstance.found;

dirs.forEach(function(dir) {
let name = dir.replace(/\.[^.]+$/ig, "").replace(/\\/g, "/");

config.reg.lastIndex = 0;
if (config.reg.test(name)) {
entries[name] = [`./${dir}`];
}
});

return entries;
};
const _ = require("lodash"),
Glob = require("glob"),
Path = require("path"),
ENV = require("../../constant/env.js"),
FSE = require("fs-extra");

module.exports = config => {
let inputConfig = config.input,
cwd = Path.join(config.root, inputConfig.path),
entryConfig = inputConfig.entry,
glob = "**",
prefix = entryConfig.prefix,
ext = entryConfig.ext,
options = {
cwd: cwd,
sync: true
},
globInstance = new Glob.Glob(`${glob}/${prefix}.${ext}`, options),
dirs = globInstance.found,
entries = _.merge({}, entryConfig.include || {}),
htmlInputConfig = inputConfig.html,
pageInputExt = htmlInputConfig.ext[0];

if (config.env !== ENV.dll) {
dirs.forEach(function(dir) {
let name = dir.replace(/\.[^.]+$/gi, "").replace(/\\/g, "/");

config.reg.lastIndex = 0;

let template = `${name}.${pageInputExt}`;

if (
FSE.pathExistsSync(
`${config.root}/${inputConfig.path}/${template}`
) &&
config.reg.test(name)
) {
entries[name] = [`./${dir}`];
}
});
}

return entries;
};
20 changes: 20 additions & 0 deletions config/base/loaders/happypack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @description happypack lodaer
* @author Leon.Cai
*/

const name = "happypack/loader",
prefix = `${name}?id=`,
happyStyleLoaderName = "happy-style-loader",
happyJsLoaderName = "happy-js-loader",
happyStyleLoader = `${prefix}${happyStyleLoaderName}`,
happyJsLoader = `${prefix}${happyJsLoaderName}`;

module.exports = {
name,
prefix,
happyStyleLoaderName,
happyJsLoaderName,
happyStyleLoader,
happyJsLoader
};
Loading

0 comments on commit dae7ed3

Please sign in to comment.