Skip to content

Commit

Permalink
Merge dda8b0d into ba7bb3b
Browse files Browse the repository at this point in the history
  • Loading branch information
julienben committed Oct 19, 2019
2 parents ba7bb3b + dda8b0d commit 2a1841c
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 175 deletions.
11 changes: 5 additions & 6 deletions internals/scripts/analyze.js
Expand Up @@ -17,11 +17,10 @@ shelljs.exec(
function callback() {
clearInterval(progress);
process.stdout.write(
'\n\nOpen ' +
chalk.magenta('http://webpack.github.io/analyse/') +
' in your browser and upload the stats.json file!' +
chalk.blue(
'\n(Tip: ' + chalk.italic('CMD + double-click') + ' the link!)\n\n',
),
`\n\nOpen ${chalk.magenta(
'http://webpack.github.io/analyse/',
)} in your browser and upload the stats.json file!${chalk.blue(
`\n(Tip: ${chalk.italic('CMD + double-click')} the link!)\n\n`,
)}`,
);
}
25 changes: 25 additions & 0 deletions internals/scripts/check-npm-version.js
@@ -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);
}
});
11 changes: 4 additions & 7 deletions internals/scripts/extract-intl.js
Expand Up @@ -48,18 +48,15 @@ const task = message => {
// Wrap async functions below into a promise
const glob = pattern =>
new Promise((resolve, reject) => {
nodeGlob(
pattern,
(error, value) => (error ? reject(error) : resolve(value)),
nodeGlob(pattern, (error, value) =>
error ? reject(error) : resolve(value),
);
});

const readFile = fileName =>
new Promise((resolve, reject) => {
fs.readFile(
fileName,
'utf8',
(error, value) => (error ? reject(error) : resolve(value)),
fs.readFile(fileName, 'utf8', (error, value) =>
error ? reject(error) : resolve(value),
);
});

Expand Down
6 changes: 3 additions & 3 deletions internals/scripts/generate-templates-for-linting.js
Expand Up @@ -14,7 +14,7 @@ const rimraf = require('rimraf');
const shell = require('shelljs');

const addCheckmark = require('./helpers/checkmark');
const xmark = require('./helpers/xmark');
const addXmark = require('./helpers/xmark');

/**
* Every generated component/container is preceded by this
Expand Down Expand Up @@ -91,7 +91,7 @@ function reportSuccess(message) {
*/
function reportErrors(reason) {
// TODO Replace with our own helpers/log that is guaranteed to be blocking?
xmark(() => console.error(chalk.red(` ${reason}`)));
addXmark(() => console.error(chalk.red(` ${reason}`)));
process.exit(1);
}

Expand Down Expand Up @@ -373,7 +373,7 @@ async function generateLanguage(language) {
/**
* Run
*/
(async function () {
(async function() {
await generateComponents([
{ kind: 'component', name: 'Component', memo: false },
{ kind: 'component', name: 'MemoizedComponent', memo: true },
Expand Down
3 changes: 0 additions & 3 deletions internals/scripts/helpers/get-npm-config.js

This file was deleted.

8 changes: 8 additions & 0 deletions internals/scripts/helpers/get-required-node-npm-versions.js
@@ -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],
};
116 changes: 116 additions & 0 deletions internals/scripts/helpers/git-utils.js
@@ -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,
};
8 changes: 0 additions & 8 deletions internals/scripts/npmcheckversion.js

This file was deleted.

0 comments on commit 2a1841c

Please sign in to comment.