Skip to content

Commit 85f1ebd

Browse files
committed
:add: deploy function
1 parent c67adf3 commit 85f1ebd

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,6 @@ dist
8686
*.njsproj
8787
*.sln
8888
*.sw*
89+
90+
91+
/micro-app.config.js

bin/micro-app.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ program
1717
.option('-l, --list', 'Show micros list')
1818
.option('-s, --show <show>', 'Show alias & shared list')
1919
.option('-u, --update <update>', 'Update moicros')
20+
.option('-d, --deploy', 'Deploy current commit to container')
2021
.parse(process.argv);
2122

2223
global.extraArgs = program.args;
@@ -54,3 +55,8 @@ if (program.update) {
5455
const name = program.update;
5556
require('../libs/update')(name);
5657
}
58+
59+
if (program.deploy) {
60+
const args = {};
61+
require('../libs/deploy')(args);
62+
}

libs/deploy.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const microApp = require('@micro-app/core');
77
const chalk = require('chalk').default;
88
const logger = microApp.logger;
99

10-
module.exports = () => {
10+
module.exports = args => {
1111
const microAppConfig = microApp.self();
1212
if (!microAppConfig) return;
1313

@@ -25,9 +25,11 @@ module.exports = () => {
2525
const gitPath = gitURL.replace(/^git\+/ig, '').split('#')[0];
2626
const gitBranch = deployCfg.branch || gitURL.split('#')[1] || 'master';
2727

28-
const commitHash = ((shelljs.exec('git rev-parse --verify HEAD', { silent: true }) || {}).stdout || '').trim();
28+
const currBranch = ((shelljs.exec('git rev-parse --abbrev-ref HEAD', { silent: true }) || {}).stdout || '').trim();
29+
const commitHash = ((shelljs.exec(`git rev-parse origin/${currBranch}`, { silent: true }) || {}).stdout || '').trim();
30+
// const commitHash = ((shelljs.exec('git rev-parse --verify HEAD', { silent: true }) || {}).stdout || '').trim();
2931

30-
const gitRoot = path.resolve(microAppConfig.root, '.gittest');
32+
const gitRoot = path.resolve(microAppConfig.root, '.git');
3133
if (fs.statSync(gitRoot).isDirectory()) {
3234
const deployDir = path.resolve(gitRoot, 'micro-deploy');
3335
if (fs.existsSync(deployDir)) {
@@ -38,6 +40,7 @@ module.exports = () => {
3840
const execStr = `git clone "${gitPath}" -b ${gitBranch} "${deployDir}"`;
3941
logger.logo(`Deploy: ${chalk.blueBright(gitPath)}`);
4042
logger.logo(`Branch: ${chalk.blueBright(gitBranch)}`);
43+
logger.logo(`Hash: ${chalk.blueBright(commitHash)}`);
4144
const result = shelljs.exec(execStr, { silent: true });
4245
if (result.code) {
4346
logger.logo(`${result.code}: ${chalk.yellow(result.stderr.trim().split('\n').reverse()[0])}`);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@micro-app/cli",
3-
"version": "0.0.18",
3+
"version": "0.0.19",
44
"description": "micro app cli",
55
"bin": {
66
"micro-app": "./bin/micro-app.js",

0 commit comments

Comments
 (0)