Skip to content

Commit

Permalink
update post install script for non ssh git users
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidWells committed Jun 2, 2017
1 parent 654702c commit 2d354e6
Showing 1 changed file with 72 additions and 46 deletions.
118 changes: 72 additions & 46 deletions scripts/build/postinstall.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Post install to build components
const cwd = process.cwd()
const path = require('path')
const exec = require('child_process').exec
const child_process = require('child_process')
const exec = child_process.exec
const execSync = child_process.execSync
const fs = require('fs')
const rimraf = require('rimraf')
const docsConfig = require('../docs/config')
Expand All @@ -10,6 +12,22 @@ const docsRepoPath = docsConfig.serverlessRepoPath
const blogRepoPath = blogConfig.blogRepoPath
const seperator = '--------------------------'


function execute(command, callback) {
try {
exec(command, function(error, stdout, stderr){
if (error.message.match(/successfully authenticated/)) {
return callback(true)
}
return callback(false)
})
} catch (err) {
return callback(false)
}
}

// Check if user used ssh with github

console.log('cwd', cwd)
if (process.env.IS_NETLIFY_ENV) {
console.log('in NETLIFY CI context, don\'t clone stuff just download it')
Expand All @@ -23,52 +41,60 @@ if (process.env.IS_NETLIFY_ENV) {
// Handle blog folder
const blogExists = fileOrDirExists(blogRepoPath)
const isBlogGitRepo = fileOrDirExists(path.join(blogRepoPath, '.git'))
if (!blogExists) {
// check for git path.join(blogRepoPath, '.git')
console.log('No serverless blog repo found. Clone it from github')
cloneRepo('[email protected]:serverless/blog.git', blogConfig.repoBranch, 'serverless-blog')
}
if (blogExists && !isBlogGitRepo) {
console.log('Blog folder exists but isnt github repo')
rimraf(blogRepoPath, () => {
console.log('Empty ./serverless-blog directory and clone repo')
cloneRepo('[email protected]:serverless/blog.git', blogConfig.repoBranch, 'serverless-blog')
})
} else {
// console.log(`Local Blog Repo found`)
// updateRepo(blogRepoPath)
// console.log(seperator)
}
if (isBlogGitRepo) {
console.log('Local Blog Repo found')
updateRepo(blogRepoPath)
}

// Handle docs folder
const docsExists = fileOrDirExists(docsRepoPath)
const docsIsGitRepo = fileOrDirExists(path.join(docsRepoPath, '.git'))
if (!docsExists) {
// check for git path.join(blogRepoPath, '.git')
console.log('No serverless docs repo found. Clone it from github')
console.log(seperator)
console.log('NOTE: serverless docs repo is big. Might take a minute to download')
cloneRepo('[email protected]:serverless/serverless.git', docsConfig.repoBranch, 'serverless')
}
if (docsExists && !docsIsGitRepo) {
console.log('Docs folder exists but isn\'t github repo')
rimraf(docsRepoPath, () => {
console.log('Empty ./serverless directory and clone repo')
cloneRepo('[email protected]:serverless/serverless.git', docsConfig.repoBranch, 'serverless')
})
} else {
// console.log(`Local Docs Repo found`)
// updateRepo(docsRepoPath)
// console.log(seperator)
}
if (docsIsGitRepo) {
console.log('Local Docs Repo found')
updateRepo(docsRepoPath)
}
// Check if user used ssh with github for cloning
execute('ssh -T [email protected]', function(hasGithubSSH) {

const blogGithubURL = (hasGithubSSH) ? '[email protected]:serverless/blog.git': 'https://github.com/serverless/blog.git'
const docsGithubURL = (hasGithubSSH) ? '[email protected]:serverless/serverless.git': 'https://github.com/serverless/serverless.git'
// console.log('hasGithubSSH', hasGithubSSH)
if (!blogExists) {
// check for git path.join(blogRepoPath, '.git')
console.log('No serverless blog repo found. Clone it from github')
cloneRepo(blogGithubURL, blogConfig.repoBranch, 'serverless-blog')
}
if (blogExists && !isBlogGitRepo) {
console.log('Blog folder exists but isnt github repo')
rimraf(blogRepoPath, () => {
console.log('Empty ./serverless-blog directory and clone repo')
cloneRepo(blogGithubURL, blogConfig.repoBranch, 'serverless-blog')
})
} else {
// console.log(`Local Blog Repo found`)
// updateRepo(blogRepoPath)
// console.log(seperator)
}
if (isBlogGitRepo) {
console.log('Local Blog Repo found')
updateRepo(blogRepoPath)
}

// Handle docs folder
const docsExists = fileOrDirExists(docsRepoPath)
const docsIsGitRepo = fileOrDirExists(path.join(docsRepoPath, '.git'))
if (!docsExists) {
// check for git path.join(blogRepoPath, '.git')
console.log('No serverless docs repo found. Clone it from github')
console.log(seperator)
console.log('NOTE: serverless docs repo is big. Might take a minute to download')
cloneRepo(docsGithubURL, docsConfig.repoBranch, 'serverless')
}
if (docsExists && !docsIsGitRepo) {
console.log('Docs folder exists but isn\'t github repo')
rimraf(docsRepoPath, () => {
console.log('Empty ./serverless directory and clone repo')
cloneRepo(docsGithubURL, docsConfig.repoBranch, 'serverless')
})
} else {
// console.log(`Local Docs Repo found`)
// updateRepo(docsRepoPath)
// console.log(seperator)
}
if (docsIsGitRepo) {
console.log('Local Docs Repo found')
updateRepo(docsRepoPath)
}
})
}
// TODO: replace clone with https://github.com/tunnckoCore/gitclone
function cloneRepo(repo, branch, path) {
Expand Down

0 comments on commit 2d354e6

Please sign in to comment.