mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-04-24 05:05:53 +08:00
Create git repository with initial commit (#1288)
* Create git repo with initial commit * Fixe commit message * Added the git repo to the docs * Bail if we are in a mercurial repository * Removed Chore from commit mesage * Create repo after installing react and react-dom * Removed docs * Commit changes when ejecting * Update after review * git add -A instead of git add . after code review
This commit is contained in:
committed by
Dan Abramov
parent
d67a9e7932
commit
247e5c90a0
43
packages/react-scripts/scripts/init.js
vendored
43
packages/react-scripts/scripts/init.js
vendored
@@ -17,10 +17,49 @@ process.on('unhandledRejection', err => {
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const chalk = require('chalk');
|
||||
const execSync = require('child_process').execSync;
|
||||
const spawn = require('react-dev-utils/crossSpawn');
|
||||
const { defaultBrowsers } = require('react-dev-utils/browsersHelper');
|
||||
const os = require('os');
|
||||
|
||||
function insideGitRepository() {
|
||||
try {
|
||||
execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore' });
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function insideMercurialRepository() {
|
||||
try {
|
||||
execSync('hg --cwd . root', { stdio: 'ignore' });
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function gitInit() {
|
||||
try {
|
||||
execSync('git --version', { stdio: 'ignore' });
|
||||
|
||||
if (insideGitRepository() || insideMercurialRepository()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
execSync('git init', { stdio: 'ignore' });
|
||||
execSync('git add -A', { stdio: 'ignore' });
|
||||
execSync('git commit -m "Initial commit from Create React App"', {
|
||||
stdio: 'ignore',
|
||||
});
|
||||
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = function(
|
||||
appPath,
|
||||
appName,
|
||||
@@ -134,6 +173,10 @@ module.exports = function(
|
||||
}
|
||||
}
|
||||
|
||||
if (gitInit()) {
|
||||
console.log('Initialized git repository');
|
||||
}
|
||||
|
||||
// Display the most elegant way to cd.
|
||||
// This needs to handle an undefined originalDirectory for
|
||||
// backward compatibility with old global-cli's.
|
||||
|
||||
Reference in New Issue
Block a user