Skip to content

Commit 51d6325

Browse files
committed
✨ first blood
0 parents  commit 51d6325

File tree

10 files changed

+1805
-0
lines changed

10 files changed

+1805
-0
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 4
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false

.eslintignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
coverage
3+
.vscode
4+
# test

.eslintrc.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
node: true
5+
},
6+
extends: [
7+
"eslint-config-2o3t"
8+
],
9+
parserOptions: {
10+
parser: "babel-eslint"
11+
},
12+
}

.gitignore

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### Node template
3+
# Logs
4+
logs
5+
*.log
6+
npm-debug.log*
7+
yarn-debug.log*
8+
yarn-error.log*
9+
10+
# Runtime data
11+
pids
12+
*.pid
13+
*.seed
14+
*.pid.lock
15+
16+
# Directory for instrumented libs generated by jscoverage/JSCover
17+
lib-cov
18+
19+
# Coverage directory used by tools like istanbul
20+
coverage
21+
22+
# nyc test coverage
23+
.nyc_output
24+
25+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
26+
.grunt
27+
28+
# Bower dependency directory (https://bower.io/)
29+
bower_components
30+
31+
# node-waf configuration
32+
.lock-wscript
33+
34+
# Compiled binary addons (https://nodejs.org/api/addons.html)
35+
build/Release
36+
37+
# Dependency directories
38+
node_modules/
39+
jspm_packages/
40+
41+
# TypeScript v1 declaration files
42+
typings/
43+
44+
# Optional npm cache directory
45+
.npm
46+
47+
# Optional eslint cache
48+
.eslintcache
49+
50+
# Optional REPL history
51+
.node_repl_history
52+
53+
# Output of 'npm pack'
54+
*.tgz
55+
56+
# Yarn Integrity file
57+
.yarn-integrity
58+
59+
# dotenv environment variables file
60+
.env
61+
62+
# parcel-bundler cache (https://parceljs.org/)
63+
.cache
64+
65+
# next.js build output
66+
.next
67+
68+
# nuxt.js build output
69+
.nuxt
70+
71+
# Nuxt generate
72+
dist
73+
74+
# vuepress build output
75+
.vuepress/dist
76+
77+
# Serverless directories
78+
.serverless
79+
80+
# IDE
81+
.idea
82+
83+
.vscode
84+
*.suo
85+
*.ntvs*
86+
*.njsproj
87+
*.sln
88+
*.sw*

bin/micro-app-build.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env node
2+
'use strict';
3+
4+
const program = require('commander');
5+
const microApp = require('@micro-app/core');
6+
const chalk = require('chalk').default;
7+
8+
program
9+
.version(require('../package').version, '-v, --version')
10+
.option('-t, --type <type>', 'Choose a build type')
11+
.parse(process.argv);
12+
13+
global.extraArgs = program.args;
14+
15+
const type = program.type;
16+
if (type === 'vusion') {
17+
microApp.vusion.build().then(() => {
18+
console.info('>>> Build Success >>>');
19+
}).catch(e => {
20+
console.error('>>> Build Error >>>', e);
21+
});
22+
} else if (!type || type === 'webpack') {
23+
// webpack build ...
24+
microApp.webpack.build().then(() => {
25+
console.info('>>> Build Success >>>');
26+
}).catch(e => {
27+
console.error('>>> Build Error >>>', e);
28+
});
29+
} else {
30+
console.warn(chalk.red(`Not Support < ${type} >`));
31+
}

bin/micro-app-dev.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env node
2+
'use strict';
3+
4+
const program = require('commander');
5+
const opn = require('opn');
6+
const chalk = require('chalk').default;
7+
8+
const microApp = require('@micro-app/core');
9+
10+
program
11+
.version(require('../package').version, '-v, --version')
12+
.option('-t, --type <type>', 'Choose a build type')
13+
.option('-H, --host <host>', 'Web url when open browser')
14+
.option('-p, --port <port>', 'Web Server Port', parseInt)
15+
.option('-o, --open-browser', 'Open browser when start server')
16+
.option('-n, --only-node', 'Only launch server')
17+
.parse(process.argv);
18+
19+
process.env.NODE_ENV = 'development';
20+
21+
global.extraArgs = program.args;
22+
23+
microApp.koa.devServer(program, url => {
24+
// success
25+
if (program.openBrowser) {
26+
opn(url);
27+
}
28+
29+
console.info(`Open Browser, URL: ${chalk.yellow(url)}`);
30+
});

bin/micro-app-start.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env node
2+
'use strict';
3+
4+
const program = require('commander');
5+
const chalk = require('chalk').default;
6+
7+
const microApp = require('@micro-app/core');
8+
9+
program
10+
.version(require('../package').version, '-v, --version')
11+
.option('-t, --type <type>', 'Choose a build type')
12+
.option('-B, --build', 'Build files in the beginning')
13+
.option('-p, --port <port>', 'Web Server Port', parseInt)
14+
.parse(process.argv);
15+
16+
process.env.NODE_ENV = 'production';
17+
18+
global.extraArgs = program.args;
19+
20+
let promise = Promise.resolve();
21+
if (program.build) {
22+
const type = program.type;
23+
if (type === 'vusion') {
24+
promise = microApp.vusion.build().then(() => {
25+
return Promise.resolve(true);
26+
});
27+
} else {
28+
// webpack build ...
29+
promise = microApp.webpack.build().then(() => {
30+
return Promise.resolve(true);
31+
});
32+
}
33+
}
34+
35+
promise.then(flag => {
36+
if (flag) {
37+
console.info(`Build files: ${chalk.green('Success')}`);
38+
}
39+
microApp.koa.runServer(program, url => {
40+
// success
41+
console.info(`Open Browser, URL: ${chalk.yellow(url)}`);
42+
});
43+
}).catch(e => {
44+
console.error(`Error: ${chalk.red(e)}`);
45+
});

bin/micro-app.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env node
2+
'use strict';
3+
4+
const program = require('commander');
5+
const shelljs = require('shelljs');
6+
const chalk = require('chalk').default;
7+
8+
const microApp = require('@micro-app/core');
9+
10+
const path = require('path');
11+
12+
program
13+
.version(require('../package').version, '-v, --version')
14+
.option('init', 'Init a config file')
15+
.option('micros', 'Show micros list')
16+
.parse(process.argv);
17+
18+
global.extraArgs = program.args;
19+
20+
if (program.init) {
21+
const mainPath = require.resolve('@micro-app/core');
22+
const configPath = path.resolve(mainPath, '../../', microApp.CONSTANT.CONFIG_NAME);
23+
const dest = path.resolve(process.cwd(), microApp.CONSTANT.CONFIG_NAME);
24+
shelljs.cp('-Rf', configPath, dest);
25+
26+
console.info(`Init ${chalk.green('Success')}: ${chalk.yellow(microApp.CONSTANT.CONFIG_NAME)}`);
27+
}
28+
if (program.micros) {
29+
const microAppConfig = microApp.self();
30+
const micros = microAppConfig.micros;
31+
32+
console.info(`${chalk.green('Micros List')}:`);
33+
if (micros.length) {
34+
micros.forEach(item => {
35+
console.info(`--> ${chalk.yellow(item)}`);
36+
});
37+
} else {
38+
console.info(' [ null ]');
39+
}
40+
}

package.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "@micro-app/cli",
3+
"version": "0.0.11",
4+
"description": "micro app cli",
5+
"bin": {
6+
"micro-app": "./bin/micro-app.js",
7+
"micro-app-dev": "./bin/micro-app-dev.js",
8+
"micro-app-build": "./bin/micro-app-build.js",
9+
"micro-app-start": "./bin/micro-app-start.js"
10+
},
11+
"scripts": {
12+
"test": "echo \"Error: no test specified\" && exit 1"
13+
},
14+
"files": [
15+
"bin"
16+
],
17+
"keywords": [
18+
"micro",
19+
"micro-app",
20+
"core",
21+
"cli"
22+
],
23+
"author": {
24+
"name": "Zyao89",
25+
"email": "[email protected]"
26+
},
27+
"license": "ISC",
28+
"devDependencies": {
29+
"babel-eslint": "^10.0.1",
30+
"eslint": "^5.15.0",
31+
"eslint-config-2o3t": "^1.1.4"
32+
},
33+
"dependencies": {
34+
"@micro-app/core": "^0.0.11",
35+
"chalk": "^2.4.2",
36+
"commander": "^2.19.0",
37+
"opn": "^5.4.0",
38+
"shelljs": "^0.8.3"
39+
}
40+
}

0 commit comments

Comments
 (0)