Skip to content
Permalink
Browse files

Allow CI setup without a local site

  • Loading branch information...
bcomnes committed Dec 5, 2018
1 parent 5a09c79 commit a01455f1c904bfa48ab1498f6b04fcd5000bb627
Showing with 83 additions and 34 deletions.
  1. +2 −2 src/commands/init.js
  2. +65 −22 src/commands/sites/create.js
  3. +16 −10 src/utils/init/config-manual.js
@@ -93,7 +93,7 @@ git remote add origin https://github.com/YourUserName/RepoName.git
// create site or search for one
if (noGitRemoteChoice === NEW_SITE_NO_GIT) {
// run site:create command
siteData = await SitesCreateCommand.run(['--no-manual'])
siteData = await SitesCreateCommand.run([])

console.log(`"${siteData.name}" site was created`)
console.log()
@@ -161,7 +161,7 @@ git remote add origin https://github.com/YourUserName/RepoName.git
type: 'new site'
})
// run site:create command
siteData = await SitesCreateCommand.run(['--no-manual'])
siteData = await SitesCreateCommand.run([])
} else if (initChoice === EXISTING_SITE) {
// run link command
siteData = await LinkCommand.run([], false)
@@ -5,27 +5,37 @@ const chalk = require('chalk')
const Command = require('../../base')
const renderShortDesc = require('../../utils/renderShortDescription')
const { track } = require('../../utils/telemetry')
const configManual = require("../../utils/init/config-manual");
const configManual = require('../../utils/init/config-manual')
const parseGitRemote = require('parse-github-url')
const configGithub = require('../../utils/init/config-github')

class SitesCreateCommand extends Command {
async run() {
const { flags } = this.parse(SitesCreateCommand)
const { api } = this.netlify

await this.authenticate()
let accountSlug = flags['account-slug']
let name = flags.name

const accounts = await api.listAccountsForUser()
const personal = accounts.find(account => account.type === 'PERSONAL')
if (!name || !accountSlug) {

let name = flags.name
if (!name) {
console.log('Choose a site name or leave blank for a random name. You can update later.')
const results = await inquirer.prompt([
{
type: 'input',
name: 'name',
message: 'Site name (optional):',
filter: val => (val === '' ? undefined : val)
},
}
])
name = results.name
}

let accountSlug = flags['account-slug']
if (!accountSlug) {
const results = await inquirer.prompt([
{
type: 'list',
name: 'accountSlug',
@@ -38,7 +48,6 @@ class SitesCreateCommand extends Command {
}
])
accountSlug = results.accountSlug
name = results.name
}

let site
@@ -70,25 +79,57 @@ class SitesCreateCommand extends Command {
})
)

this.log()

track('sites_created', {
siteId: site.id,
adminUrl: site.admin_url,
siteUrl: url
})

if (flags.manual) {
const { manualConfig } = await inquirer.prompt([
{
type: 'confirm',
name: 'manualConfig',
message: 'Would you like to configure this site\'s git repository manually?',
default: true
}
]);
if (flags['with-ci']) {
this.log('Configuring CI')
const { url } = await inquirer.prompt([
{
type: 'input',
name: 'url',
message: 'Git SSH remote URL to enable CI with:',
validate: input => (parseGitRemote(input) ? true : `Could not parse Git remote ${input}`)
}
])
console.log(url)
const repoData = parseGitRemote(url)
const repo = {
repoData,
repo_path: url
}

if (manualConfig) await configManual(this, site, {});
switch (true) {
case flags.manual: {
await configManual(this, site, repo)
break
}
case repoData.host === 'github.com': {
try {
await configGithub(this, site, repo)
} catch (e) {
this.warn(`Github error: ${e.status}`)
if (e.code === 404) {
this.error(
`Does the repository ${
repo.repo_path
} exist and do you have the correct permissions to set up deploy keys?`
)
} else {
throw e
}
}
break
}
default: {
this.log('No configurator found for the provided git remote. Configuring manually...')
await configManual(this, site, repo)
break
}
}
}

return site
@@ -109,11 +150,13 @@ SitesCreateCommand.flags = {
char: 'a',
description: 'account slug to create the site under'
}),
'manual': flags.boolean({
'with-ci': flags.boolean({
char: 'c',
description: 'initialize CI hooks during site creation'
}),
manual: flags.boolean({
char: 'm',
default: true,
description: 'enable the option to configure git manually',
allowNo: true
description: 'Force manual CI setup. Used --with-ci flag'
})
}

@@ -24,7 +24,7 @@ async function configManual(ctx, site, repo) {
repo.deploy_key_id = key.id

// TODO: Look these up and default to the lookup order
const { buildCmd, buildDir, repoPath } = await inquirer.prompt([
const { buildCmd, buildDir } = await inquirer.prompt([
{
type: 'input',
name: 'buildCmd',
@@ -36,17 +36,23 @@ async function configManual(ctx, site, repo) {
name: 'buildDir',
message: 'Directory to deploy (blank for current dir):',
default: '.'
},
{
type: 'input',
name: 'repoPath',
message: 'The SSH URL of the remote git repo:',
default: repo.repo_path,
validate: url => !!url.match(/(ssh:\/\/|[a-zA-Z]*@|[a-zA-Z.].*:(?!\/\/))/) || "The URL provided does not use the SSH protocol"
}
}
])
repo.dir = buildDir
repo.repo_path = repoPath

if (!repo.repo_path) {
const { repoPath } = await inquirer.prompt([
{
type: 'input',
name: 'repoPath',
message: 'The SSH URL of the remote git repo:',
default: repo.repo_path,
validate: url =>
!!url.match(/(ssh:\/\/|[a-zA-Z]*@|[a-zA-Z.].*:(?!\/\/))/) || 'The URL provided does not use the SSH protocol'
}
])
repo.repo_path = repoPath
}

if (buildCmd) {
repo.cmd = buildCmd

0 comments on commit a01455f

Please sign in to comment.
You can’t perform that action at this time.