Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support umi@3 app #109

Merged
merged 2 commits into from
May 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ if (!semver.satisfies(process.version, '>= 8.0.0')) {
const name = args._[0] || '';
const { type } = args;
delete args.type;
run({
name,
type,
args,
});

(async () => {
await run({
name,
type,
args,
});
process.exit(0);
})();
37 changes: 27 additions & 10 deletions lib/generators/ant-design-pro/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,28 @@ class AntDesignProGenerator extends BasicGenerator {
};
} else {
const prompts = [
{
name: 'nextPro',
type: 'confirm',
message: '🧙 Be the first to experience the new umi@3 ?',
default: false,
when: () => {
// 为了测试,没有任何用处
process.send && process.send({ type: 'prompt' });
process.emit('message', { type: 'prompt' });
return true;
},
},
{
name: 'language',
type: 'list',
message: '🤓 Which language do you want to use?',
choices: ['TypeScript', 'JavaScript'],
default: 'TypeScript',
filter: value => {
// 为了测试,没有任何用处
when: ({ nextPro }) => {
process.send && process.send({ type: 'prompt' });
process.emit('message', { type: 'prompt' });
return value;
return !nextPro;
},
},
{
Expand All @@ -59,18 +70,20 @@ class AntDesignProGenerator extends BasicGenerator {
message: '🚀 Do you need all the blocks or a simple scaffold?',
choices: ['simple', 'complete'],
default: 'simple',
filter: value => {
// 为了测试,没有任何用处
when: ({ nextPro }) => {
process.send && process.send({ type: 'prompt' });
process.emit('message', { type: 'prompt' });
return value;
return !nextPro;
},
},
{
name: 'nextAntd',
type: 'confirm',
when: ({ allBlocks }) => {
return allBlocks === 'simple';
when: ({ allBlocks, nextPro }) => {
process.send && process.send({ type: 'prompt' });
process.emit('message', { type: 'prompt' });
console.log(nextPro);
return allBlocks === 'simple' && !nextPro;
},
message: '🦄 Time to use better, faster and latest antd@4!',
default: true,
Expand All @@ -83,7 +96,7 @@ class AntDesignProGenerator extends BasicGenerator {
}

async writing() {
const { language, allBlocks, nextAntd } = this.prompts;
const { language = 'TypeScript', allBlocks, nextPro, nextAntd } = this.prompts;

const isTypeScript = language === 'TypeScript';
const projectName = this.opts.name || this.opts.env.cwd;
Expand All @@ -101,14 +114,18 @@ class AntDesignProGenerator extends BasicGenerator {
gitArgs.push('--branch', 'antd@3');
}

if (nextPro) {
gitArgs.push('--branch', 'v5');
}

// all-blocks 分支上包含了所有的区块
if (allBlocks === 'complete') {
log(`🙈 complete mode can only use the version of antd@4`);
gitArgs.push('--branch', 'all-blocks');
}

// Set branch if provided
if (this.opts.args.branch) {
if (this.opts.args.branch && !nextPro) {
gitArgs.push('--branch', this.opts.args.branch);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const run = async config => {

try {
return runGenerator(`./generators/${type}`, config);
} catch(e) {
} catch (e) {
console.error(chalk.red(`> Generate failed`), e);
process.exit(1);
}
Expand Down
6 changes: 6 additions & 0 deletions test/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ exports[`test umi-create test generate antd pro project from gitee.org 1`] = `
block - Create a umi block.
library - Create a library with umi.
plugin - Create a umi plugin. ? Select the boilerplate type ant-design-pro
? 🧙 Be the first to experience the new umi@3 ? (y/N) ? 🧙 Be the first to experience the new umi@3 ? No

? 🤓 Which language do you want to use? (Use arrow keys)
❯ TypeScript
JavaScript ? 🤓 Which language do you want to use? TypeScript
? 🚀 Do you need all the blocks or a simple scaffold? (Use arrow keys)
❯ simple
complete ? 🚀 Do you need all the blocks or a simple scaffold? simple
false
? 🦄 Time to use better, faster and latest antd@4! (Y/n) ? 🦄 Time to use better, faster and latest antd@4! Yes
❯ 🚚 clone success
❯ Clean up...
Expand All @@ -31,6 +34,8 @@ exports[`test umi-create test generate antd pro project from github 1`] = `
block - Create a umi block.
library - Create a library with umi.
plugin - Create a umi plugin. ? Select the boilerplate type ant-design-pro
? 🧙 Be the first to experience the new umi@3 ? (y/N) ? 🧙 Be the first to experience the new umi@3 ? No

? 🤓 Which language do you want to use? (Use arrow keys)
❯ TypeScript
JavaScript ? 🤓 Which language do you want to use?
Expand All @@ -39,6 +44,7 @@ exports[`test umi-create test generate antd pro project from github 1`] = `
? 🚀 Do you need all the blocks or a simple scaffold? (Use arrow keys)
❯ simple
complete ? 🚀 Do you need all the blocks or a simple scaffold? simple
false
? 🦄 Time to use better, faster and latest antd@4! (Y/n) ? 🦄 Time to use better, faster and latest antd@4! Yes
❯ 🚚 clone success
❯ [Sylvanas] Prepare js environment...
Expand Down
20 changes: 16 additions & 4 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ describe('test umi-create', () => {
.beforeScript(path.join(fixtures, 'mock_github.js'))
.waitForPrompt()
.write('\n')
.write('\n')
.write('\n')
.writeKey('DOWN', 'ENTER')
.write('\n')
.write('\n')
Expand Down Expand Up @@ -51,6 +53,8 @@ describe('test umi-create', () => {
.write('\n')
.write('\n')
.write('\n')
.write('\n')
.write('\n')
.end();

expect(winEOL(response.stdout).replace(/>/g, '❯')).toMatchSnapshot();
Expand Down Expand Up @@ -78,6 +82,9 @@ describe('typescript', () => {
.write('\n')
.write('\n')
.write('\n')
.write('\n')
.write('\n')
.write('\n')
.end();

expect(response.code).toBe(0);
Expand All @@ -102,13 +109,14 @@ describe('typescript', () => {
.beforeScript(path.join(fixtures, 'mock_github.js'))
.waitForPrompt()
.write('\n')
.write('\n')
.write('\n')
// ts
.write('\n')
// all-blocks
.writeKey('DOWN', 'ENTER')
.write('\n')
.end();

expect(response.code).toBe(0);
expect(fs.existsSync(path.join(temp, '/src/pages/exception/403/index.tsx'))).toBeTruthy();
});
Expand All @@ -127,14 +135,18 @@ describe('typescript', () => {
})
.beforeScript(path.join(fixtures, 'mock_github.js'))
.waitForPrompt()
.write('\n')
.writeKey('ENTER')
.writeKey('ENTER')
.writeKey('ENTER')
// js
.writeKey('DOWN', 'ENTER')
// all blocks
.writeKey('DOWN', 'ENTER')
.write('\n')
.writeKey('ENTER')
.writeKey('ENTER')
.end();

console.log(response);
console.log(temp);
expect(response.code).toBe(0);
expect(fs.existsSync(path.join(temp, 'tsconfig.json'))).toBeFalsy();
expect(fs.existsSync(path.join(temp, '/src/pages/exception/403/index.jsx'))).toBeTruthy();
Expand Down