Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
179 additions
and
175 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const chalk = require('chalk'); | ||
const { exec } = require('child_process'); | ||
const { compare } = require('compare-versions'); | ||
|
||
const addXMark = require('./helpers/xmark'); | ||
const { | ||
requiredNpmVersion, | ||
} = require('./helpers/get-required-node-npm-versions'); | ||
|
||
exec('npm -v', (err, stdout) => { | ||
if (err) throw err; | ||
|
||
const currentNpmVersion = stdout.trim(); | ||
|
||
if (compare(currentNpmVersion, requiredNpmVersion, '<')) { | ||
addXMark(() => | ||
process.stderr.write( | ||
chalk.red( | ||
` You need npm version v${requiredNpmVersion} or above but you are using v${currentNpmVersion}.\n\n`, | ||
), | ||
), | ||
); | ||
process.exit(1); | ||
} | ||
}); |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const { | ||
engines: { node, npm }, | ||
} = require('../../../package.json'); | ||
|
||
module.exports = { | ||
requiredNodeVersion: node.match(/([0-9.]+)/g)[0], | ||
requiredNpmVersion: npm.match(/([0-9.]+)/g)[0], | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,116 @@ | ||
const { exec } = require('child_process'); | ||
const shell = require('shelljs'); | ||
|
||
/** | ||
* Initialize a new Git repository | ||
* @returns {Promise<any>} | ||
*/ | ||
function initGitRepository() { | ||
return new Promise((resolve, reject) => { | ||
exec('git init', (err, stdout) => { | ||
if (err) { | ||
reject(new Error(err)); | ||
} else { | ||
resolve(stdout); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* Add all files to the new repository | ||
* @returns {Promise<any>} | ||
*/ | ||
function addToGitRepository() { | ||
return new Promise((resolve, reject) => { | ||
exec('git add .', (err, stdout) => { | ||
if (err) { | ||
reject(new Error(err)); | ||
} else { | ||
resolve(stdout); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* Initial Git commit | ||
* @returns {Promise<any>} | ||
*/ | ||
function commitToGitRepository() { | ||
return new Promise((resolve, reject) => { | ||
exec('git commit -m "Initial commit"', (err, stdout) => { | ||
if (err) { | ||
reject(new Error(err)); | ||
} else { | ||
resolve(stdout); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* Checks if we are under Git version control | ||
* @returns {Promise<boolean>} | ||
*/ | ||
function hasGitRepository() { | ||
return new Promise((resolve, reject) => { | ||
exec('git status', (err, stdout) => { | ||
if (err) { | ||
reject(new Error(err)); | ||
} | ||
|
||
const regex = new RegExp(/fatal:\s+Not\s+a\s+git\s+repository/, 'i'); | ||
|
||
/* eslint-disable-next-line no-unused-expressions */ | ||
regex.test(stdout) ? resolve(false) : resolve(true); | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* Checks if this is a clone from our repo | ||
* @returns {Promise<any>} | ||
*/ | ||
function checkIfRepositoryIsAClone() { | ||
return new Promise((resolve, reject) => { | ||
exec('git remote -v', (err, stdout) => { | ||
if (err) { | ||
reject(new Error(err)); | ||
} | ||
|
||
const isClonedRepo = stdout | ||
.split(/\r?\n/) | ||
.map(line => line.trim()) | ||
.filter(line => line.startsWith('origin')) | ||
.filter(line => /react-boilerplate\/react-boilerplate\.git/.test(line)) | ||
.length; | ||
|
||
resolve(!!isClonedRepo); | ||
}); | ||
}); | ||
} | ||
|
||
/** | ||
* Remove the current Git repository | ||
* @returns {Promise<any>} | ||
*/ | ||
function removeGitRepository() { | ||
return new Promise((resolve, reject) => { | ||
try { | ||
shell.rm('-rf', '.git/'); | ||
resolve(); | ||
} catch (err) { | ||
reject(err); | ||
} | ||
}); | ||
} | ||
|
||
module.exports = { | ||
initGitRepository, | ||
addToGitRepository, | ||
commitToGitRepository, | ||
hasGitRepository, | ||
checkIfRepositoryIsAClone, | ||
removeGitRepository, | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.