added support for current branch, and some cleanup
This commit is contained in:
@@ -3,7 +3,7 @@ const chalk = require('chalk');
|
||||
const { Input, Confirm } = require('enquirer');
|
||||
import { Octokit } from "@octokit/core";
|
||||
import { GluegunPrint } from 'gluegun';
|
||||
import { defaultMenuSettings } from '../../../../globals';
|
||||
import { defaultMenuSettings, getSettings } from '../../../../globals';
|
||||
const os = require("os");
|
||||
|
||||
const STACK_DEFAULTS = {
|
||||
@@ -119,20 +119,12 @@ module.exports = {
|
||||
const { system, strings, print, filesystem } = toolbox;
|
||||
|
||||
// Load settings
|
||||
const config = await filesystem.readAsync(`${os.homedir()}/.pwcli_settings`, "json");
|
||||
const config = await getSettings(toolbox);
|
||||
if (!config) {
|
||||
print.error(`
|
||||
|
||||
No config found, please run [ ${chalk.cyan('pwcli s')} ] or setup from the menu.
|
||||
|
||||
`);
|
||||
if (toolbox.fromMenu()) {
|
||||
await toolbox.menu.showMenu(null, defaultMenuSettings)
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
await toolbox.menu.showMenu('setup', defaultMenuSettings);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
let branchName = null;
|
||||
while (!branchName) {
|
||||
branchName = await getBranchName(print, config.gh_token);
|
||||
@@ -238,11 +230,11 @@ module.exports = {
|
||||
print.fancy(await system.run(createCommand, {cwd: '/tmp/', trim: true}));
|
||||
}
|
||||
} catch (e) {
|
||||
console.log(`e`, e)
|
||||
console.log(`e`, e);
|
||||
}
|
||||
|
||||
if (toolbox.fromMenu()) {
|
||||
await toolbox.menu.showMenu('deployment testservers', defaultMenuSettings)
|
||||
await toolbox.menu.showMenu('deployment testservers', defaultMenuSettings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ const chalk = require('chalk');
|
||||
const { AutoComplete, Input, Confirm } = require('enquirer');
|
||||
import { Octokit } from "@octokit/core";
|
||||
import { GluegunPrint } from 'gluegun';
|
||||
import { defaultMenuSettings } from '../../../../globals';
|
||||
import { defaultMenuSettings, getCurrentBranch, getSettings } from '../../../../globals';
|
||||
const os = require("os");
|
||||
|
||||
const STACK_DEFAULTS = {
|
||||
@@ -68,11 +68,14 @@ const getUpdateStackCommand = (stackName: string, branch: string, templateFile:
|
||||
return cmd.join(' ');
|
||||
}
|
||||
|
||||
const getBranchName = async (print: GluegunPrint, token: string) => {
|
||||
const getBranchName = async (toolbox: GluegunMenuToolbox, token: string, repoPath: string) => {
|
||||
const {print} = toolbox;
|
||||
const currentBranch = await getCurrentBranch(repoPath, toolbox);
|
||||
const input = new Input({
|
||||
type: 'input',
|
||||
name: 'branch',
|
||||
message: 'What github branch should be deployed?'
|
||||
message: 'What github branch should be deployed?',
|
||||
initial: currentBranch,
|
||||
});
|
||||
const responseBranch = await input.run();
|
||||
|
||||
@@ -114,26 +117,18 @@ module.exports = {
|
||||
description: 'Update stack with different branch (u)',
|
||||
hidden: false,
|
||||
run: async (toolbox: GluegunMenuToolbox) => {
|
||||
const { system, strings, print, filesystem } = toolbox;
|
||||
const { system, strings, print } = toolbox;
|
||||
|
||||
// Load settings
|
||||
const config = await filesystem.readAsync(`${os.homedir()}/.pwcli_settings`, "json");
|
||||
const config = await getSettings(toolbox);
|
||||
if (!config) {
|
||||
print.error(`
|
||||
|
||||
No config found, please run [ ${chalk.cyan('pwcli s')} ] or setup from the menu.
|
||||
|
||||
`);
|
||||
if (toolbox.fromMenu()) {
|
||||
await toolbox.menu.showMenu(null, defaultMenuSettings)
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
await toolbox.menu.showMenu('setup', defaultMenuSettings);
|
||||
return;
|
||||
}
|
||||
|
||||
let branchName = null;
|
||||
while (!branchName) {
|
||||
branchName = await getBranchName(print, config.gh_token);
|
||||
branchName = await getBranchName(toolbox, config.gh_token, config.photowall_repo);
|
||||
}
|
||||
|
||||
const stacks = JSON.parse(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';
|
||||
import chalk = require('chalk');
|
||||
import { system } from 'gluegun';
|
||||
import { defaultMenuSettings } from '../../../globals';
|
||||
import { defaultMenuSettings, getSettings } from '../../../globals';
|
||||
const { Confirm, Input } = require('enquirer');
|
||||
|
||||
const checkCLIProgram = async (toolbox: GluegunMenuToolbox, cmd: string) => {
|
||||
@@ -33,6 +33,8 @@ module.exports = {
|
||||
|
||||
`));
|
||||
|
||||
let config = await getSettings(toolbox);
|
||||
|
||||
// Check if brew is installed
|
||||
// if (await checkCLIProgram(toolbox, 'brew')) {
|
||||
// print.info(`\nDetected ${chalk.green('brew')}`);
|
||||
@@ -100,17 +102,21 @@ module.exports = {
|
||||
|
||||
await system.run('touch ~/.pwcli_settings');
|
||||
print.info(`Created configuration file ${chalk.yellow(`~/.pwcli_settings`)}`);
|
||||
const config = {
|
||||
gh_token: '',
|
||||
photowall_repo: '',
|
||||
};
|
||||
if (!config) {
|
||||
config = {
|
||||
gh_token: '',
|
||||
photowall_repo: '',
|
||||
};
|
||||
}
|
||||
|
||||
config.gh_token = await (new Input({
|
||||
message: `A github accesstoken is required with ${chalk.yellow('Full control of private repositories')}, please insert the key >`
|
||||
message: `A github accesstoken is required with ${chalk.yellow('Full control of private repositories')}, please insert the key >`,
|
||||
initial: config.gh_token,
|
||||
})).run();
|
||||
|
||||
config.photowall_repo = await (new Input({
|
||||
message: `If you want to be able to push active branch in your photowall repository, please insert the absolute path to the project >`
|
||||
message: `If you want to be able to use current branch in your photowall repository\nwhen creating or updating testservers, please insert\nthe absolute path to the project or leave blank >`,
|
||||
initial: config.photowall_repo,
|
||||
})).run();
|
||||
|
||||
print.info(`
|
||||
|
||||
@@ -1,4 +1,36 @@
|
||||
import chalk = require("chalk");
|
||||
const os = require("os");
|
||||
|
||||
export const defaultMenuSettings = {
|
||||
showHelp: false
|
||||
};
|
||||
|
||||
export type TConfig = {
|
||||
gh_token: string;
|
||||
photowall_repo: string;
|
||||
};
|
||||
export const getSettings = async (toolbox): Promise<TConfig | null> => {
|
||||
const { filesystem, print } = toolbox;
|
||||
try {
|
||||
return await filesystem.readAsync(`${os.homedir()}/.pwcli_settings`, "json");
|
||||
} catch {
|
||||
print.error(`
|
||||
|
||||
No config found, please run [ ${chalk.cyan('pwcli s se')} ] or setup > settings from the menu.
|
||||
|
||||
`);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
export const getCurrentBranch = async (path: string, toolbox): Promise<string | null> => {
|
||||
const { system } = toolbox;
|
||||
const config = await getSettings(toolbox);
|
||||
if (config.photowall_repo) {
|
||||
// git rev-parse --abbrev-ref HEAD
|
||||
const branch = await system.run('git rev-parse --abbrev-ref HEAD', {cwd: config.photowall_repo, trim: true});
|
||||
console.log(`branch`, branch);
|
||||
return branch;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user