Skip to content

Commit

Permalink
fix(cli): remove '\r' in macos.
Browse files Browse the repository at this point in the history
  • Loading branch information
wangyi7099 committed Jul 29, 2019
1 parent 7a5120a commit 20a0ddf
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 30 deletions.
8 changes: 2 additions & 6 deletions packages/antdsite/lib/gatsby/createSchemaCustomization.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,8 @@ module.exports = ({ actions }) => {
fields: MdxFields
}
type SitePage implements Node @infer {
context: SitePageContext
}
type SitePageContext @dontInfer {
webConfig: Json
type SitePage implements Node @dontInfer {
path: String
}
`;
createTypes(typeDefs);
Expand Down
40 changes: 21 additions & 19 deletions packages/cli/create-antd-site.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const spawn = require('cross-spawn');
let projectName;

const allDeps = {
antdsite: '^0.0.4',
antdsite: 'latest',
gatsby: '^2.13.39',
react: '^16.8.0',
'react-dom': '^16.8.0'
Expand All @@ -29,7 +29,7 @@ const program = new commander.Command(packageJson.name)
.version(packageJson.version)
.arguments('[project-directory]')
.usage(`${chalk.green('[project-directory]')}`)
.action(name => {
.action((name) => {
projectName = name;
})
.option('--use-npm')
Expand All @@ -39,7 +39,7 @@ createApp(projectName, program.useNpm);

function printValidationResults(results) {
if (typeof results !== 'undefined') {
results.forEach(error => {
results.forEach((error) => {
console.error(chalk.red(` * ${error}`));
});
}
Expand Down Expand Up @@ -69,7 +69,7 @@ function checkAppName(appName) {
`Due to the way npm works, the following names are not allowed:\n\n`
) +
chalk.hex('#29CDFF')(
dependencies.map(depName => ` ${depName}`).join('\n')
dependencies.map((depName) => ` ${depName}`).join('\n')
) +
chalk.red('\n\nPlease choose a different project name.')
);
Expand All @@ -87,14 +87,14 @@ function shouldUseYarn() {
}

function executeNodeScript({ cwd, initScriptPath }, data, source) {
return new Promise(resolve => {
return new Promise((resolve) => {
const child = spawn(
process.execPath,
['-e', source, '--', JSON.stringify(data), initScriptPath],
{ cwd, stdio: 'inherit' }
);

child.on('close', code => {
child.on('close', (code) => {
if (code !== 0) {
return;
}
Expand All @@ -121,12 +121,13 @@ function isSafeToCreateProjectIn(root, name) {

const conflicts = fs
.readdirSync(root)
.filter(file => !validFiles.includes(file))
.filter((file) => !validFiles.includes(file))
// IntelliJ IDEA creates module files before CRA is launched
.filter(file => !/\.iml$/.test(file))
.filter((file) => !/\.iml$/.test(file))
// Don't treat log files from previous installation as conflicts
.filter(
file => !errorLogFilePatterns.some(pattern => file.indexOf(pattern) === 0)
(file) =>
!errorLogFilePatterns.some((pattern) => file.indexOf(pattern) === 0)
);

if (conflicts.length > 0) {
Expand All @@ -147,8 +148,8 @@ function isSafeToCreateProjectIn(root, name) {

// Remove any remnant files from a previous installation
const currentFiles = fs.readdirSync(path.join(root));
currentFiles.forEach(file => {
errorLogFilePatterns.forEach(errorLogFilePattern => {
currentFiles.forEach((file) => {
errorLogFilePatterns.forEach((errorLogFilePattern) => {
// This will catch `(npm-debug|yarn-error|yarn-debug).log*` files
if (file.indexOf(errorLogFilePattern) === 0) {
fs.removeSync(path.join(root, file));
Expand All @@ -158,13 +159,14 @@ function isSafeToCreateProjectIn(root, name) {
return true;
}

function createApp(name, useNpm) {
const root = path.resolve(name || './');
function createApp(name = './', useNpm) {
const root = path.resolve(name);
const appName = path.basename(root);
const originalDirectory = process.cwd();

checkAppName(appName);
fs.ensureDirSync(name);
if (!isSafeToCreateProjectIn(root, name)) {
if (!isSafeToCreateProjectIn(root, appName)) {
process.exit(1);
}

Expand Down Expand Up @@ -228,21 +230,20 @@ function createApp(name, useNpm) {
return pre.concat(cur + '@' + allDeps[cur]);
}, []);

run(root, dependencies, useYarn, appName);
run(root, dependencies, useYarn, appName, originalDirectory);
}

function run(root, dependencies, useYarn, appName) {
function run(root, dependencies, useYarn, appName, originalDirectory) {
console.log(`Installing ${chalk.hex('#29CDFF')(dependencies.join(' '))} ...`);
install(root, useYarn, dependencies).then(() => {
const initScriptPath = path.resolve(__dirname, 'init.js');
console.log(initScriptPath);

executeNodeScript(
{
cwd: process.cwd(),
initScriptPath
},
[root, appName, useYarn],
[root, appName, useYarn, originalDirectory],
`
var init = require(process.argv[2]);
init.apply(null, JSON.parse(process.argv[1]));
Expand All @@ -253,6 +254,7 @@ function run(root, dependencies, useYarn, appName) {

function install(root, useYarn, dependencies) {
return new Promise((resolve, reject) => {
return resolve();
let command;
let args;
if (useYarn) {
Expand Down Expand Up @@ -280,7 +282,7 @@ function install(root, useYarn, dependencies) {
}

const child = spawn(command, args, { stdio: 'inherit' });
child.on('close', code => {
child.on('close', (code) => {
if (code !== 0) {
reject({
command: `${command} ${args.join(' ')}`
Expand Down
14 changes: 10 additions & 4 deletions packages/cli/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,14 @@ function writeTemplate(appPath) {
}
}

function showSuccessTips(appPath, appName, useYarn) {
function showSuccessTips(appPath, appName, useYarn, originalDirectory) {
const displayedCommand = useYarn ? 'yarn' : 'npm';
let cdpath;
if (originalDirectory && path.join(originalDirectory, appName) === appPath) {
cdpath = appName;
} else {
cdpath = appPath;
}

console.log();

Expand All @@ -77,14 +83,14 @@ function showSuccessTips(appPath, appName, useYarn) {
console.log('We suggest that you begin by typing:');
console.log();

console.log(chalk.hex('#29CDFF')(' cd'), appName);
console.log(chalk.hex('#29CDFF')(' cd'), cdpath);
console.log(` ${chalk.hex('#29CDFF')(`${displayedCommand} start`)}`);
}

module.exports = function(appPath, appName, useYarn) {
module.exports = function(appPath, appName, useYarn, originalDirectory) {
writeTemplate(appPath);

tryGitInit(appPath);

showSuccessTips(appPath, appName, useYarn);
showSuccessTips(appPath, appName, useYarn, originalDirectory);
};
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "antdsite-cli",
"version": "0.0.7",
"version": "0.0.8",
"description": "Create a website based on Ant Design and GatsbyJs",
"keywords": [
"antdsite"
Expand Down

0 comments on commit 20a0ddf

Please sign in to comment.