Compare commits

...

1 Commits

Author SHA1 Message Date
Jani Eväkallio
80a799dff9 Prototype the foam init command 2020-07-16 11:11:27 +01:00
3 changed files with 186 additions and 1 deletions

View File

@@ -11,7 +11,9 @@
"@oclif/command": "^1",
"@oclif/config": "^1",
"@oclif/plugin-help": "^3",
"@types/inquirer": "^6.5.0",
"foam-core": "^0.2.0",
"inquirer": "^7.3.2",
"ora": "^4.0.4",
"tslib": "^1"
},

View File

@@ -0,0 +1,168 @@
/*eslint-disable no-unused-vars*/
import { Command, flags } from '@oclif/command';
import * as inquirer from 'inquirer';
import * as ora from 'ora';
// @todo implement this class, currently it does nothing but collect inputs
export default class Init extends Command {
static description = 'Initialize a new Foam workspace from template';
// @todo better examples
static examples = [`$ foam init`];
// @todo validate inputs
static flags = {
help: flags.help({ char: 'h' }),
name: flags.string({
char: 'n',
description: 'workspace name',
}),
scm: flags.string({
char: 's',
description: 'source control (github, git, local)'
}),
template: flags.string({
char: 't',
description: 'template'
}),
gitHubUser: flags.string({
char: 'u',
description: 'github username'
}),
gitHubPassword: flags.string({
description: 'github password'
}),
// @todo make flag
githubPages: flags.string({
char: 'p',
description: 'enable github pages'
}),
repoOwner: flags.string({
char: 'p',
description: 'github repo owner'
}),
visibility: flags.string({
char: 'v',
description: 'github repo visibility (public/private)'
}),
};
async run() {
const { flags } = this.parse(Init);
const name =
flags.name ||
(await inquirer.prompt({
name: 'name',
message: 'Give your workspace a name',
type: 'input',
default: 'foam',
})).name;
const template =
flags.template ||
(await inquirer.prompt({
name: 'template',
message: 'Choose from one of the available templates',
type: 'list',
choices: [
{ name: 'Default (foam-template)' },
{ name: 'Gatsby + GitHub Actions (foam-template-gatsby)' },
{ name: '11ty + Netlify (foam-template-eleventy)' },
{ name: 'MLH Fellowship Workspace (foam-template-mlh)' },
],
})).template;
const scm = (await inquirer.prompt([
{
name: 'scm',
message: 'How do you want to store your workspace?',
type: 'list',
default: 'GitHub',
choices: [
{ name: 'GitHub' },
{ name: 'Local git repository' },
{ name: 'Local directory (no source control)' },
],
},
])).scm;
if (scm === 'GitHub') {
const userName =
flags.gitHubUser ||
(await inquirer.prompt({
name: 'username',
message: 'GitHub username',
type: 'input'
})).username;
const password =
flags.gitHubPassword ||
(await inquirer.prompt({
name: 'password',
message: 'GitHub password',
type: 'password'
})).password;
const owner =
flags.repoOwner ||
(await inquirer.prompt({
name: 'owner',
message: 'GitHub repository owner',
type: 'input',
default: userName
})).owner;
const visibility =
flags.visibility ||
(await inquirer.prompt({
name: 'visibility',
message: 'Should the repository be public or private?',
type: 'list',
choices: [
{ name: 'Public' },
{ name: 'Private' }
],
})).visibility.toLowerCase();
const pages =
flags.githubPages ||
((await inquirer.prompt({
name: 'pages',
message: 'Publish automatically to GitHub pages?',
type: 'list',
choices: [
{ name: 'Yes' },
{ name: 'No' }
],
})).pages === 'Yes');
const sure = (await inquirer.prompt({
name: 'sure',
type: 'confirm',
message: `Create a new ${visibility} Foam in https://github.com/${owner}/${name}?`
})).sure;
if (sure) {
const spinner = ora().start();
await new Promise(resolve => {
setTimeout(() => resolve(), 1000);
});
spinner.succeed();
spinner.succeed('Foam workspace created!');
spinner.succeed('Run "code foam" to open your new workspace');
}
} else {
console.log(`Created a private Foam workspace in ./${name}`);
}
}
}

View File

@@ -2350,6 +2350,14 @@
resolved "https://registry.yarnpkg.com/@types/graphlib/-/graphlib-2.1.6.tgz#5c7b515bfadc08d737f2e84fadbd151117c73207"
integrity sha512-os2Xj+pV/iwLkLX17LWuXdPooA4Jf4xg8WSdKPUi0tCSseP95oikcA1irOgVl3K2QYnoXrjJT3qVZeQ1uskB7g==
"@types/inquirer@^6.5.0":
version "6.5.0"
resolved "https://registry.yarnpkg.com/@types/inquirer/-/inquirer-6.5.0.tgz#b83b0bf30b88b8be7246d40e51d32fe9d10e09be"
integrity sha512-rjaYQ9b9y/VFGOpqBEXRavc3jh0a+e6evAbI31tMda8VlPaSy0AZJfXsvmIe3wklc7W6C3zCSfleuMXR7NOyXw==
dependencies:
"@types/through" "*"
rxjs "^6.4.0"
"@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0", "@types/istanbul-lib-coverage@^2.0.1":
version "2.0.3"
resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.3.tgz#4ba8ddb720221f432e443bd5f9117fd22cfd4762"
@@ -2444,6 +2452,13 @@
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e"
integrity sha512-l42BggppR6zLmpfU6fq9HEa2oGPEI8yrSPL3GITjfRInppYFahObbIQOQK3UGxEnyQpltZLaPe75046NOZQikw==
"@types/through@*":
version "0.0.30"
resolved "https://registry.yarnpkg.com/@types/through/-/through-0.0.30.tgz#e0e42ce77e897bd6aead6f6ea62aeb135b8a3895"
integrity sha512-FvnCJljyxhPM3gkRgWmxmDZyAQSiBQQWLI0A0VFL0K7W1oRUrPJSqNO0NvTnLkBcotdlp3lKvaT0JrnyRDkzOg==
dependencies:
"@types/node" "*"
"@types/unist@^2.0.0", "@types/unist@^2.0.2":
version "2.0.3"
resolved "https://registry.yarnpkg.com/@types/unist/-/unist-2.0.3.tgz#9c088679876f374eb5983f150d4787aa6fb32d7e"
@@ -5937,7 +5952,7 @@ inquirer@^6.2.0, inquirer@^6.2.2:
strip-ansi "^5.1.0"
through "^2.3.6"
inquirer@^7.0.0, inquirer@^7.0.4:
inquirer@^7.0.0, inquirer@^7.0.4, inquirer@^7.3.2:
version "7.3.2"
resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-7.3.2.tgz#25245d2e32dc9f33dbe26eeaada231daa66e9c7c"
integrity sha512-DF4osh1FM6l0RJc5YWYhSDB6TawiBRlbV9Cox8MWlidU218Tb7fm3lQTULyUJDfJ0tjbzl0W4q651mrCCEM55w==