Skip to content

Commit

Permalink
Commit initial state.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jun 13, 2018
1 parent c9e1c08 commit 2e823d6
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 13 deletions.
1 change: 1 addition & 0 deletions .bin/kkt.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ program
program
.command('create <app-name>')
.description('create a new project powered by kkt')
.option('-g, --git [message]', 'Force / skip git intialization, optionally specify initial commit message')
.option('-r, --registry <url>', 'Use specified npm registry when installing dependencies (only for npm)')
.option('-f, --force', 'Overwrite target directory if it exists')
.on('--help', () => {
Expand Down
37 changes: 27 additions & 10 deletions src/Creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const execa = require('execa');
const path = require('path');
const fs = require('fs-extra');
const inquirer = require('inquirer');
const copyTemplate = require('copy-template-dir');
const { copyTemplate } = require('./util/copyTemplate');
const kktpkg = require('../package.json');
const { installDeps } = require('./util/installDeps');
const { logSpinner, stopSpinner } = require('./util/spinner');
Expand Down Expand Up @@ -49,15 +49,12 @@ module.exports = class Creator {
await this.run('git init');
}
stopSpinner();

// commit initial state
let gitCommitFailed = false;
if (tempDir) {
await copyTemplate(tempDir, targetDir, {
name,
kktVersion: KKT_VERSION,
}, async (err, createdFiles) => {
if (err) return log(` Copy Tamplate Error: ${err} !!!`.red);
log('');
createdFiles.sort().forEach((createdFile) => {
const copyTemp = await copyTemplate(tempDir, targetDir, { name, KKT_VERSION });
if (copyTemp && copyTemp.length > 0) {
copyTemp.sort().forEach((createdFile) => {
log(` ${'create'.green} ${createdFile.replace(targetDir, `${name}`)}`);
});
log('\n⚙ Installing dependencies. This might take a while...\n');
Expand All @@ -68,7 +65,27 @@ module.exports = class Creator {
`${targetDir === process.cwd() ? '' : chalk.cyan(` ${chalk.white('$')} cd ${name}\n`)}` +
` ${chalk.cyan(`${chalk.white('$')} npm run start\n\n`)}`
);
});
// 提交第一次记录
if (shouldInitGit) {
await this.run('pwd');
await this.run('git add -A');
const msg = typeof cliOptions.git === 'string' ? cliOptions.git : 'Initial commit';
try {
await this.run('git', ['commit', '-m', msg]);
} catch (e) {
gitCommitFailed = true;
}
}
} else {
return log(` Copy Tamplate Error: ${copyTemp} !!!`.red);
}
}

if (gitCommitFailed) {
log(
'Skipped git commit due to missing username and email in git config.\n'.red +
'You will need to perform the initial commit yourself.\n'.red
);
}
}

Expand Down
13 changes: 13 additions & 0 deletions src/util/copyTemplate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const copyTemplateDir = require('copy-template-dir');

exports.copyTemplate = function copyTemplate(inDir, outDir, option) {
return new Promise((resolve, reject) => {
copyTemplateDir(inDir, outDir, option, (err, createdFiles) => {
if (err) {
reject(new Error(err));
return;
}
resolve(createdFiles);
});
});
};
2 changes: 1 addition & 1 deletion templates/default/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
"react-dom": "^16.4.0"
},
"devDependencies": {
"kkt": "{{kktVersion}}"
"kkt": "{{KKT_VERSION}}"
}
}
2 changes: 1 addition & 1 deletion templates/router-redux-rematch/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"react-router-dom": "^4.2.2"
},
"devDependencies": {
"kkt": "{{kktVersion}}"
"kkt": "{{KKT_VERSION}}"
}
}
2 changes: 1 addition & 1 deletion templates/router-redux-rematch/src/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const user = {
async logout() {
await localStorage.removeItem('token');
await localStorage.removeItem('username');
await this.addUserData({ username: null, token: null });
await this.updateState({ username: null, token: null });
},
},
};

0 comments on commit 2e823d6

Please sign in to comment.