Skip to content

Commit 20a0ddf

Browse files
committed
fix(cli): remove '\r' in macos.
1 parent 7a5120a commit 20a0ddf

4 files changed

Lines changed: 34 additions & 30 deletions

File tree

packages/antdsite/lib/gatsby/createSchemaCustomization.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,8 @@ module.exports = ({ actions }) => {
3737
fields: MdxFields
3838
}
3939
40-
type SitePage implements Node @infer {
41-
context: SitePageContext
42-
}
43-
44-
type SitePageContext @dontInfer {
45-
webConfig: Json
40+
type SitePage implements Node @dontInfer {
41+
path: String
4642
}
4743
`;
4844
createTypes(typeDefs);

packages/cli/create-antd-site.js

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const spawn = require('cross-spawn');
1111
let projectName;
1212

1313
const allDeps = {
14-
antdsite: '^0.0.4',
14+
antdsite: 'latest',
1515
gatsby: '^2.13.39',
1616
react: '^16.8.0',
1717
'react-dom': '^16.8.0'
@@ -29,7 +29,7 @@ const program = new commander.Command(packageJson.name)
2929
.version(packageJson.version)
3030
.arguments('[project-directory]')
3131
.usage(`${chalk.green('[project-directory]')}`)
32-
.action(name => {
32+
.action((name) => {
3333
projectName = name;
3434
})
3535
.option('--use-npm')
@@ -39,7 +39,7 @@ createApp(projectName, program.useNpm);
3939

4040
function printValidationResults(results) {
4141
if (typeof results !== 'undefined') {
42-
results.forEach(error => {
42+
results.forEach((error) => {
4343
console.error(chalk.red(` * ${error}`));
4444
});
4545
}
@@ -69,7 +69,7 @@ function checkAppName(appName) {
6969
`Due to the way npm works, the following names are not allowed:\n\n`
7070
) +
7171
chalk.hex('#29CDFF')(
72-
dependencies.map(depName => ` ${depName}`).join('\n')
72+
dependencies.map((depName) => ` ${depName}`).join('\n')
7373
) +
7474
chalk.red('\n\nPlease choose a different project name.')
7575
);
@@ -87,14 +87,14 @@ function shouldUseYarn() {
8787
}
8888

8989
function executeNodeScript({ cwd, initScriptPath }, data, source) {
90-
return new Promise(resolve => {
90+
return new Promise((resolve) => {
9191
const child = spawn(
9292
process.execPath,
9393
['-e', source, '--', JSON.stringify(data), initScriptPath],
9494
{ cwd, stdio: 'inherit' }
9595
);
9696

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

122122
const conflicts = fs
123123
.readdirSync(root)
124-
.filter(file => !validFiles.includes(file))
124+
.filter((file) => !validFiles.includes(file))
125125
// IntelliJ IDEA creates module files before CRA is launched
126-
.filter(file => !/\.iml$/.test(file))
126+
.filter((file) => !/\.iml$/.test(file))
127127
// Don't treat log files from previous installation as conflicts
128128
.filter(
129-
file => !errorLogFilePatterns.some(pattern => file.indexOf(pattern) === 0)
129+
(file) =>
130+
!errorLogFilePatterns.some((pattern) => file.indexOf(pattern) === 0)
130131
);
131132

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

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

161-
function createApp(name, useNpm) {
162-
const root = path.resolve(name || './');
162+
function createApp(name = './', useNpm) {
163+
const root = path.resolve(name);
163164
const appName = path.basename(root);
165+
const originalDirectory = process.cwd();
164166

165167
checkAppName(appName);
166168
fs.ensureDirSync(name);
167-
if (!isSafeToCreateProjectIn(root, name)) {
169+
if (!isSafeToCreateProjectIn(root, appName)) {
168170
process.exit(1);
169171
}
170172

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

231-
run(root, dependencies, useYarn, appName);
233+
run(root, dependencies, useYarn, appName, originalDirectory);
232234
}
233235

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

240241
executeNodeScript(
241242
{
242243
cwd: process.cwd(),
243244
initScriptPath
244245
},
245-
[root, appName, useYarn],
246+
[root, appName, useYarn, originalDirectory],
246247
`
247248
var init = require(process.argv[2]);
248249
init.apply(null, JSON.parse(process.argv[1]));
@@ -253,6 +254,7 @@ function run(root, dependencies, useYarn, appName) {
253254

254255
function install(root, useYarn, dependencies) {
255256
return new Promise((resolve, reject) => {
257+
return resolve();
256258
let command;
257259
let args;
258260
if (useYarn) {
@@ -280,7 +282,7 @@ function install(root, useYarn, dependencies) {
280282
}
281283

282284
const child = spawn(command, args, { stdio: 'inherit' });
283-
child.on('close', code => {
285+
child.on('close', (code) => {
284286
if (code !== 0) {
285287
reject({
286288
command: `${command} ${args.join(' ')}`

packages/cli/init.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,14 @@ function writeTemplate(appPath) {
5050
}
5151
}
5252

53-
function showSuccessTips(appPath, appName, useYarn) {
53+
function showSuccessTips(appPath, appName, useYarn, originalDirectory) {
5454
const displayedCommand = useYarn ? 'yarn' : 'npm';
55+
let cdpath;
56+
if (originalDirectory && path.join(originalDirectory, appName) === appPath) {
57+
cdpath = appName;
58+
} else {
59+
cdpath = appPath;
60+
}
5561

5662
console.log();
5763

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

80-
console.log(chalk.hex('#29CDFF')(' cd'), appName);
86+
console.log(chalk.hex('#29CDFF')(' cd'), cdpath);
8187
console.log(` ${chalk.hex('#29CDFF')(`${displayedCommand} start`)}`);
8288
}
8389

84-
module.exports = function(appPath, appName, useYarn) {
90+
module.exports = function(appPath, appName, useYarn, originalDirectory) {
8591
writeTemplate(appPath);
8692

8793
tryGitInit(appPath);
8894

89-
showSuccessTips(appPath, appName, useYarn);
95+
showSuccessTips(appPath, appName, useYarn, originalDirectory);
9096
};

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "antdsite-cli",
3-
"version": "0.0.7",
3+
"version": "0.0.8",
44
"description": "Create a website based on Ant Design and GatsbyJs",
55
"keywords": [
66
"antdsite"

0 commit comments

Comments
 (0)