-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add cli tool
- Loading branch information
Showing
28 changed files
with
1,084 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,5 +18,4 @@ | |
## 文档 | ||
|
||
- [命令行客户端](//github.com/macacajs/reliable-cli) | ||
- [开发 Reliable](./docker/reliable-web#development) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
**/.* | ||
**/node_modules | ||
**/test | ||
coverage/ | ||
**/docs/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
extends: 'eslint-config-antife', | ||
rules: { | ||
semi: [2, 'always'], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Compiled source # | ||
################### | ||
*.com | ||
*.class | ||
*.dll | ||
*.exe | ||
*.o | ||
*.so | ||
|
||
# Packages # | ||
############ | ||
# it's better to unpack these files and commit the raw source | ||
# git has its own built in compression methods | ||
*.7z | ||
*.dmg | ||
*.gz | ||
*.iso | ||
*.jar | ||
*.rar | ||
*.tar | ||
*.zip | ||
|
||
# Logs and databases # | ||
###################### | ||
*.log | ||
*.sql | ||
*.sqlite | ||
|
||
# OS generated files # | ||
###################### | ||
.DS_Store | ||
._* | ||
node_modules | ||
coverage/ | ||
.nyc_output | ||
*.gz | ||
*.sw* | ||
*.un~ | ||
package-lock.json | ||
.vscode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# reliable-cli | ||
|
||
[![NPM version][npm-image]][npm-url] | ||
[![CI][CI-image]][CI-url] | ||
[![Test coverage][codecov-image]][codecov-url] | ||
[![node version][node-image]][node-url] | ||
[![npm download][download-image]][download-url] | ||
|
||
[npm-image]: https://img.shields.io/npm/v/reliable-cli.svg | ||
[npm-url]: https://npmjs.org/package/reliable-cli | ||
[CI-image]: https://github.com/macacajs/reliable-cli/actions/workflows/ci.yml/badge.svg | ||
[CI-url]: https://github.com/macacajs/reliable-cli/actions/workflows/ci.yml | ||
[codecov-image]: https://img.shields.io/codecov/c/github/macacajs/reliable-cli.svg | ||
[codecov-url]: https://codecov.io/gh/macacajs/reliable-cli | ||
[node-image]: https://img.shields.io/badge/node.js-%3E=_8-green.svg | ||
[node-url]: http://nodejs.org/download/ | ||
[download-image]: https://img.shields.io/npm/dm/reliable-cli.svg | ||
[download-url]: https://npmjs.org/package/reliable-cli | ||
|
||
> command-line interface for Reliable | ||
[Reliable Offlice Site](//macacajs.github.io/reliable) | ||
|
||
## License | ||
|
||
The MIT License (MIT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
const _ = require('../lib/helper'); | ||
const childProcess = require('child_process'); | ||
|
||
const platformType = _.getPlatformType(); | ||
|
||
let cmd = ''; | ||
const args = []; | ||
|
||
if (platformType === 'ios') { | ||
console.log('executing make process for ios'); | ||
console.log(process.argv); | ||
|
||
// args should be; [0]node, [1]js-file, [2]make-action....[3]configuration args | ||
if (process.argv.length < 3) { | ||
console.error('invalid arguments'); | ||
process.exit(0); | ||
} | ||
|
||
// check make action: 'build', 'release', 'test', 'pack' etc | ||
if (process.argv[2].indexOf('=') > 0) { | ||
console.error('invalid action'); | ||
console.log(process.argv[2]); | ||
process.exit(0); | ||
} | ||
|
||
cmd = process.argv[2]; | ||
args.push(cmd); | ||
|
||
// formalize extra args | ||
if (process.argv.length > 3) { | ||
args.push(`ARGS="--${process.argv.slice(3).join(' --')}"`); | ||
} | ||
|
||
console.log(`make ${args}`); | ||
} else if (platformType === 'android') { | ||
|
||
} else { | ||
|
||
} | ||
|
||
// execute cmd | ||
const buildProcess = childProcess.spawn('make', args, { | ||
stdio: [ | ||
process.stdin, | ||
process.stdout, | ||
2, | ||
'ipc', | ||
], | ||
}); | ||
|
||
buildProcess.on('close', code => { | ||
process.exit('process exited with code ' + code); | ||
}); | ||
|
||
buildProcess.on('exit', code => { | ||
process.exit(code); | ||
}); | ||
|
||
buildProcess.on('message', e => { | ||
if (e.signal === 'kill') { | ||
buildProcess.kill(); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/usr/bin/env node | ||
|
||
const ReportCommand = require('../lib/report-command'); | ||
|
||
new ReportCommand().run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
const { | ||
EOL, | ||
} = require('os'); | ||
const _ = require('xutil'); | ||
const path = require('path'); | ||
const { | ||
spawn, | ||
} = require('child_process'); | ||
const program = require('commander'); | ||
|
||
const pkg = require('../package'); | ||
|
||
const buildCmds = ['build', 'release', 'pack', 'lint', 'doc', 'coverage', 'setup', 'test']; | ||
const chalk = _.chalk; | ||
|
||
program | ||
.option('-v, --versions', 'show version and exit') | ||
.option('--verbose', 'show more debugging information') | ||
.usage('<command> [options] [arguments]') | ||
.helpInformation = function () { | ||
return [ | ||
'', | ||
' ' + chalk.white(pkg.description), | ||
'', | ||
' Usage:', | ||
'', | ||
' ' + this._name + ' ' + this.usage(), | ||
'', | ||
' Commands:', | ||
'', | ||
' report report to Reliable server', | ||
'', | ||
' Options:', | ||
'', | ||
'' + this.optionHelp().replace(/^/gm, ' '), | ||
'', | ||
'', | ||
].join(EOL); | ||
}; | ||
|
||
program.parse(process.argv); | ||
|
||
if (program.versions) { | ||
console.info('%s %s%s', EOL, pkg.version, EOL); | ||
process.exit(0); | ||
} | ||
|
||
let cmd = program.args[0]; | ||
|
||
if (!cmd) { | ||
return program.help(); | ||
} | ||
|
||
// for cmd which belongs to development process, all navigate to reliable-cli-make.js | ||
if (buildCmds.includes(cmd)) { | ||
program.rawArgs.splice(3, 0, cmd); | ||
cmd = 'make'; | ||
} | ||
|
||
const file = path.join(__dirname, `${pkg.name}-${cmd}.js`); | ||
|
||
if (!_.isExistedFile(file)) { | ||
console.log('%s command `%s` not found', EOL, chalk.yellow(cmd)); | ||
program.help(); | ||
return; | ||
} | ||
|
||
const args = program.rawArgs.slice(3); | ||
args.unshift(file); | ||
|
||
const bootstrap = spawn('node', args, { | ||
stdio: [ | ||
process.stdin, | ||
process.stdout, | ||
2, | ||
'ipc', | ||
], | ||
}); | ||
|
||
bootstrap.on('close', code => { | ||
process.exit('process exited with code ' + code); | ||
}); | ||
|
||
bootstrap.on('exit', code => { | ||
process.exit(code); | ||
}); | ||
|
||
bootstrap.on('message', e => { | ||
switch (e.signal) { | ||
case 'kill': | ||
bootstrap.kill(); | ||
break; | ||
default : | ||
break; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
'use strict'; | ||
|
||
exports.helper = require('./lib/helper'); | ||
exports.ReportCommand = require('./lib/report-command'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"source": { | ||
"include": [ | ||
"lib", | ||
"README.md" | ||
], | ||
"includePattern": ".js$" | ||
}, | ||
"opts": { | ||
"destination": "./docs/", | ||
"template": "node_modules/minami" | ||
}, | ||
"templates": { | ||
"cleverLinks": false, | ||
"monospaceLinks": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
const os = require('os'); | ||
|
||
const _ = require('./helper'); | ||
|
||
module.exports = () => { | ||
const env = process.env; | ||
return { | ||
platform: _.getPlatformType(), | ||
ci: { | ||
JOB_NAME: _.normalizeJobName(env.JOB_NAME), | ||
BUILD_NUMBER: env.BUILD_NUMBER, | ||
RUNNER_TYPE: 'JENKINS', // GITLAB_CI | ||
}, | ||
os: { | ||
nodeVersion: process.version, | ||
platform: os.platform(), | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
|
||
const LCL = require('last-commit-log'); | ||
|
||
module.exports = directory => { | ||
const lcl = new LCL(directory); | ||
return lcl.getLastCommitSync(); | ||
}; |
Oops, something went wrong.