added support for current branch, and some cleanup
This commit is contained in:
Vendored
+15
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"sqltools.connections": [
|
||||||
|
{
|
||||||
|
"previewLimit": 50,
|
||||||
|
"server": "localhost",
|
||||||
|
"port": 5432,
|
||||||
|
"driver": "PostgreSQL",
|
||||||
|
"name": "Local photowall",
|
||||||
|
"group": "Photowall",
|
||||||
|
"database": "photowall",
|
||||||
|
"username": "arwidthornstrom",
|
||||||
|
"password": ""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@ const chalk = require('chalk');
|
|||||||
const { Input, Confirm } = require('enquirer');
|
const { Input, Confirm } = require('enquirer');
|
||||||
import { Octokit } from "@octokit/core";
|
import { Octokit } from "@octokit/core";
|
||||||
import { GluegunPrint } from 'gluegun';
|
import { GluegunPrint } from 'gluegun';
|
||||||
import { defaultMenuSettings } from '../../../../globals';
|
import { defaultMenuSettings, getSettings } from '../../../../globals';
|
||||||
const os = require("os");
|
const os = require("os");
|
||||||
|
|
||||||
const STACK_DEFAULTS = {
|
const STACK_DEFAULTS = {
|
||||||
@@ -119,20 +119,12 @@ module.exports = {
|
|||||||
const { system, strings, print, filesystem } = toolbox;
|
const { system, strings, print, filesystem } = toolbox;
|
||||||
|
|
||||||
// Load settings
|
// Load settings
|
||||||
const config = await filesystem.readAsync(`${os.homedir()}/.pwcli_settings`, "json");
|
const config = await getSettings(toolbox);
|
||||||
if (!config) {
|
if (!config) {
|
||||||
print.error(`
|
await toolbox.menu.showMenu('setup', defaultMenuSettings);
|
||||||
|
return;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let branchName = null;
|
let branchName = null;
|
||||||
while (!branchName) {
|
while (!branchName) {
|
||||||
branchName = await getBranchName(print, config.gh_token);
|
branchName = await getBranchName(print, config.gh_token);
|
||||||
@@ -238,11 +230,11 @@ module.exports = {
|
|||||||
print.fancy(await system.run(createCommand, {cwd: '/tmp/', trim: true}));
|
print.fancy(await system.run(createCommand, {cwd: '/tmp/', trim: true}));
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(`e`, e)
|
console.log(`e`, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toolbox.fromMenu()) {
|
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');
|
const { AutoComplete, Input, Confirm } = require('enquirer');
|
||||||
import { Octokit } from "@octokit/core";
|
import { Octokit } from "@octokit/core";
|
||||||
import { GluegunPrint } from 'gluegun';
|
import { GluegunPrint } from 'gluegun';
|
||||||
import { defaultMenuSettings } from '../../../../globals';
|
import { defaultMenuSettings, getCurrentBranch, getSettings } from '../../../../globals';
|
||||||
const os = require("os");
|
const os = require("os");
|
||||||
|
|
||||||
const STACK_DEFAULTS = {
|
const STACK_DEFAULTS = {
|
||||||
@@ -68,11 +68,14 @@ const getUpdateStackCommand = (stackName: string, branch: string, templateFile:
|
|||||||
return cmd.join(' ');
|
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({
|
const input = new Input({
|
||||||
type: 'input',
|
type: 'input',
|
||||||
name: 'branch',
|
name: 'branch',
|
||||||
message: 'What github branch should be deployed?'
|
message: 'What github branch should be deployed?',
|
||||||
|
initial: currentBranch,
|
||||||
});
|
});
|
||||||
const responseBranch = await input.run();
|
const responseBranch = await input.run();
|
||||||
|
|
||||||
@@ -114,26 +117,18 @@ module.exports = {
|
|||||||
description: 'Update stack with different branch (u)',
|
description: 'Update stack with different branch (u)',
|
||||||
hidden: false,
|
hidden: false,
|
||||||
run: async (toolbox: GluegunMenuToolbox) => {
|
run: async (toolbox: GluegunMenuToolbox) => {
|
||||||
const { system, strings, print, filesystem } = toolbox;
|
const { system, strings, print } = toolbox;
|
||||||
|
|
||||||
// Load settings
|
// Load settings
|
||||||
const config = await filesystem.readAsync(`${os.homedir()}/.pwcli_settings`, "json");
|
const config = await getSettings(toolbox);
|
||||||
if (!config) {
|
if (!config) {
|
||||||
print.error(`
|
await toolbox.menu.showMenu('setup', defaultMenuSettings);
|
||||||
|
return;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let branchName = null;
|
let branchName = null;
|
||||||
while (!branchName) {
|
while (!branchName) {
|
||||||
branchName = await getBranchName(print, config.gh_token);
|
branchName = await getBranchName(toolbox, config.gh_token, config.photowall_repo);
|
||||||
}
|
}
|
||||||
|
|
||||||
const stacks = JSON.parse(
|
const stacks = JSON.parse(
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';
|
import { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';
|
||||||
import chalk = require('chalk');
|
import chalk = require('chalk');
|
||||||
import { system } from 'gluegun';
|
import { system } from 'gluegun';
|
||||||
import { defaultMenuSettings } from '../../../globals';
|
import { defaultMenuSettings, getSettings } from '../../../globals';
|
||||||
const { Confirm, Input } = require('enquirer');
|
const { Confirm, Input } = require('enquirer');
|
||||||
|
|
||||||
const checkCLIProgram = async (toolbox: GluegunMenuToolbox, cmd: string) => {
|
const checkCLIProgram = async (toolbox: GluegunMenuToolbox, cmd: string) => {
|
||||||
@@ -33,6 +33,8 @@ module.exports = {
|
|||||||
|
|
||||||
`));
|
`));
|
||||||
|
|
||||||
|
let config = await getSettings(toolbox);
|
||||||
|
|
||||||
// Check if brew is installed
|
// Check if brew is installed
|
||||||
// if (await checkCLIProgram(toolbox, 'brew')) {
|
// if (await checkCLIProgram(toolbox, 'brew')) {
|
||||||
// print.info(`\nDetected ${chalk.green('brew')}`);
|
// print.info(`\nDetected ${chalk.green('brew')}`);
|
||||||
@@ -100,17 +102,21 @@ module.exports = {
|
|||||||
|
|
||||||
await system.run('touch ~/.pwcli_settings');
|
await system.run('touch ~/.pwcli_settings');
|
||||||
print.info(`Created configuration file ${chalk.yellow(`~/.pwcli_settings`)}`);
|
print.info(`Created configuration file ${chalk.yellow(`~/.pwcli_settings`)}`);
|
||||||
const config = {
|
if (!config) {
|
||||||
gh_token: '',
|
config = {
|
||||||
photowall_repo: '',
|
gh_token: '',
|
||||||
};
|
photowall_repo: '',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
config.gh_token = await (new Input({
|
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();
|
})).run();
|
||||||
|
|
||||||
config.photowall_repo = await (new Input({
|
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();
|
})).run();
|
||||||
|
|
||||||
print.info(`
|
print.info(`
|
||||||
|
|||||||
@@ -1,4 +1,36 @@
|
|||||||
|
import chalk = require("chalk");
|
||||||
|
const os = require("os");
|
||||||
|
|
||||||
export const defaultMenuSettings = {
|
export const defaultMenuSettings = {
|
||||||
showHelp: false
|
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