Skip to content

Commit

Permalink
update no-repo flow
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidWells committed Sep 10, 2018
1 parent ca5cafb commit 9d20d77
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 26 deletions.
41 changes: 32 additions & 9 deletions src/commands/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const Command = require('../base')
const renderShortDesc = require('../utils/renderShortDescription')
const openBrowser = require('../utils/open-browser')
const path = require('path')
const chalk = require('chalk')
const { flags } = require('@oclif/command')
const get = require('lodash.get')
const fs = require('fs')
Expand Down Expand Up @@ -47,9 +48,20 @@ class DeployCommand extends Command {
get(await api.getSite({ siteId }), 'build_settings.functions_dir')

if (!deployFolder) {
this.error(
`Can't determine a deploy folder. Please define one in your site settings, netlify.toml or pass one as a flag.`
)

this.log(`Can't determine a deploy folder.`)
this.log()
this.log('Please define one in your site settings, netlify.toml or pass one as a flag')
this.log()
this.log(`Example using CLI flag:
# deploy to preview URL
${chalk.cyanBright.bold('netlify deploy --dir your-build-directory')}
# deploy to live URL with the --prod flag
${chalk.cyanBright.bold('netlify deploy --dir your-build-directory --prod')}
`)
this.exit()
}

// TODO go through the above resolution, and make sure the resolve algorithm makes sense
Expand All @@ -68,9 +80,9 @@ class DeployCommand extends Command {
let results
try {
if (deployToProduction) {
this.log('Deploying to live site...')
this.log('Deploying to live site url...')
} else {
this.log('Deploying to draft site...')
this.log('Deploying to draft url...')
}

results = await api.deploy(siteId, resolvedDeployPath, resolvedFunctionsPath, site.configPath, {
Expand All @@ -86,15 +98,26 @@ class DeployCommand extends Command {
const deployUrl = get(results, 'deploy.deploy_ssl_url') || get(results, 'deploy.deploy_url')

const msgData = {
URL: results.deploy.ssl_url || results.deploy.url,
Logs: `${get(results, 'deploy.admin_url')}/deploys/${get(results, 'deploy.id')}`,
'Deploy URL': deployUrl
'Unique Deploy URL': deployUrl
}
if (!deployToProduction) {
delete msgData.URL

if (deployToProduction) {
msgData['Live Url'] = siteUrl
} else {
delete msgData['Unique Deploy URL']
msgData['Live Draft Url'] = deployUrl
}
this.log()
this.log(prettyjson.render(msgData))

if (!deployToProduction) {
console.log()
console.log('If everything looks good on your draft URL. Take it live with the --prod flag')
console.log(`${chalk.cyanBright.bold('netlify deploy --prod')}`)
console.log()
}

if (flags['open']) {
const urlToOpen = (flags['prod']) ? siteUrl : deployUrl
await openBrowser(urlToOpen)
Expand Down
101 changes: 87 additions & 14 deletions src/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class InitCommand extends Command {
await this.authenticate()

const siteId = site.get('siteId')

// const hasFlags = !isEmpty(flags)
let siteData
try {
Expand All @@ -31,30 +32,38 @@ class InitCommand extends Command {

if (siteId && siteData) {
const repoUrl = get(siteData, 'build_settings.repo_url')
this.log()
this.log(`${chalk.yellow('Warning:')} It looks like this site has already been initialized.`)
this.log()
this.log(`Site Name: ${chalk.cyan(siteData.name)}`)
this.log(`Site Url: ${chalk.cyan(siteData.ssl_url || siteData.url)}`)
if (repoUrl) {
this.log()
this.log(`${chalk.yellow('Warning:')} It looks like this site has already been initialized.`)
this.log()
this.log(`Site Name: ${chalk.cyan(siteData.name)}`)
this.log(`Site Url: ${chalk.cyan(siteData.ssl_url || siteData.url)}`)
this.log(`Site Repo: ${chalk.cyan(repoUrl)}`)
this.log(`Site Id: ${chalk.cyan(siteData.id)}`)
this.log(`Admin URL: ${chalk.cyan(siteData.admin_url)}`)
this.log()

this.log(`To create a new site, Please run ${chalk.cyanBright.bold('netlify unlink')}`)
// TODO remove this.log(`Or delete the siteId from ${this.siteData.path}`)
this.exit()
}
this.log(`Site Id: ${chalk.cyan(siteData.id)}`)
this.log(`Admin URL: ${chalk.cyan(siteData.admin_url)}`)
this.log()

this.log(`To disconnect this directory and create a new site (or link to another siteId)`)
this.log(`1. Run ${chalk.cyanBright.bold('netlify unlink')}`)
this.log(`2. Then run ${chalk.cyanBright.bold('netlify init')} again`)
// TODO remove this.log(`Or delete the siteId from ${this.siteData.path}`)
this.exit()
}

// Look for local repo
const repo = await getRepoData()

if (repo.error) {
console.log()
console.log(`${chalk.redBright('Git Repo Error (╯°□°)╯︵ ┻━┻')}`)
console.log()
console.log(`${chalk.redBright('No git remote found. (╯°□°)╯︵ ┻━┻')}`)
console.log(`
It is recommended that you initialize a site that has a remote repository in Github.
This will allow for Netlify Continuous deployment to build branch & PR previews.
For more details on Netlify CI checkout the docs: http://bit.ly/2N0Jhy5
`)
let message
switch (repo.error) {
case 'Couldn\'t find origin url': {
Expand All @@ -68,6 +77,70 @@ git remote add origin https://github.com/YourUserName/RepoName.git
if (message) {
console.log(message)
}

const NEW_SITE_NO_GIT = 'Yes, create manually deploy site'
const NO_ABORT = 'No, I will connect this with directory with github first'

const { noGitRemoteChoice } = await inquirer.prompt([
{
type: 'list',
name: 'noGitRemoteChoice',
message: 'Do you want to create a netlify site without a git repository?',
choices: [
NEW_SITE_NO_GIT,
NO_ABORT
]
}
])

// create site or search for one
if (noGitRemoteChoice === NEW_SITE_NO_GIT) {
// run site:create command
siteData = await SitesCreateCommand.run([])

console.log(`"${siteData.name}" site was created`)
console.log()
this.log(`To deploy to this site. Run your site build and then ${chalk.cyanBright.bold('netlify deploy')}`)

// Save to .netlify/state.json file
state.set('siteId', siteData.id)

// no github remote
this.exit()

} else if (noGitRemoteChoice === NO_ABORT) {
console.log()
console.log(`${chalk.bold('To initialize a new git repo follow the steps below.')}
1. Initialize a new repo:
${chalk.cyanBright.bold('git init')}
2. Commit your files
${chalk.cyanBright.bold('git add .')}
3. Commit your files
${chalk.cyanBright.bold('git commit -m \'initial commit\'')}
4. Create a new repo in github ${chalk.cyanBright.bold('https://github.com/new')}
5. Link the remote repo with this local directory
${chalk.cyanBright.bold('git remote add origin git@github.com:YourGithubName/your-repo-slug.git')}
6. Push up your files
${chalk.cyanBright.bold('git push -u origin master')}
7. Initialize your Netlify Site
${chalk.cyanBright.bold('netlify init')}
`)
this.exit()
}

// Throw github remote error
this.error(repo.error)
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class LinkCommand extends Command {
this.log(`Linked to ${siteData.name} in ${path.relative(path.join(process.cwd(), '..'), state.path)}`)

await track('sites_linked', {
siteId: siteData.id,
siteId: siteData && siteData.id || siteId,
linkType: 'manual',
kind: 'byName'
})
Expand Down
4 changes: 2 additions & 2 deletions src/commands/unlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class UnlinkCommand extends Command {
return this.exit()
}

let siteData
let siteData = {}
try {
siteData = await this.netlify.api.getSite({ siteId })
} catch (e) {
Expand All @@ -22,7 +22,7 @@ class UnlinkCommand extends Command {
state.delete('siteId')

await track('sites_unlinked', {
siteId: siteData.id,
siteId: siteData.id || siteId,
})

this.log(`Unlinked ${site.configPath} from ${siteData ? siteData.name : siteId}`)
Expand Down

0 comments on commit 9d20d77

Please sign in to comment.