-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Deploy to root on master branch * Add default branch value of master * Bump version to v1.0.0-beta.1
- Loading branch information
1 parent
4b37048
commit c4dabcf
Showing
7 changed files
with
82 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,39 @@ | ||
const shell = require('shelljs'); | ||
const path = require('path'); | ||
|
||
const DEPLOY_BRANCH_DIRECTORY = 'branch'; | ||
const BRANCH_DIRECTORY_NAME = 'branch'; | ||
|
||
shell.set('-e'); | ||
|
||
module.exports = { prepareDeployDirectory }; | ||
|
||
function prepareDeployDirectory(directory, options) { | ||
checkoutPagesBranchToDeployDirectory(directory); | ||
moveDirectoryContentToDeployDirectory(directory, options); | ||
} | ||
|
||
function checkoutPagesBranchToDeployDirectory(directory) { | ||
createDeployDirectoryIfDoesNotExist(directory); | ||
function prepareDeployDirectory(deployDirectory, { directory: sourceDirectory, branch }) { | ||
createBranchDirectoryIfNeeded(deployDirectory, branch); | ||
|
||
try { | ||
pullGithubPagesBranchToDirectory(directory); | ||
} catch (err) { | ||
console.error(err); | ||
console.log('gh-pages branch does not exist yet, it will be created automatically...'); | ||
} | ||
copyContentWithReplacement(sourceDirectory, getTargetDirectory(deployDirectory, branch)); | ||
} | ||
|
||
function createDeployDirectoryIfDoesNotExist(directory) { | ||
shell.mkdir('-p', directory); | ||
function createBranchDirectoryIfNeeded(deployDirectory, branch) { | ||
if (!isMaster(branch)) { | ||
shell.mkdir('-p', getBranchDirectory(deployDirectory)); | ||
} | ||
} | ||
|
||
function pullGithubPagesBranchToDirectory(directory) { | ||
shell.exec(`git --work-tree=./${directory} checkout gh-pages -- .`, { silent: true }); | ||
function isMaster(branch) { | ||
return branch === 'master'; | ||
} | ||
|
||
function moveDirectoryContentToDeployDirectory(directory, options) { | ||
createBranchDirectoryIfDoesNotExist(directory); | ||
|
||
const source = options.directory; | ||
const target = path.join(directory, DEPLOY_BRANCH_DIRECTORY, options.branch); | ||
|
||
moveContent(source, target); | ||
function getBranchDirectory(deployDirectory) { | ||
return path.join(deployDirectory, BRANCH_DIRECTORY_NAME); | ||
} | ||
|
||
function createBranchDirectoryIfDoesNotExist(directory) { | ||
shell.mkdir('-p', path.join(directory, DEPLOY_BRANCH_DIRECTORY)); | ||
function getTargetDirectory(deployDirectory, branch) { | ||
return isMaster(branch) | ||
? deployDirectory | ||
: path.join(getBranchDirectory(deployDirectory), branch); | ||
} | ||
|
||
function moveContent(source, target) { | ||
function copyContentWithReplacement(source, target) { | ||
shell.rm('-rf', target); | ||
shell.cp('-r', source, target); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters