Skip to content

Commit 2479c7f

Browse files
TheZokeredgarmueller
authored andcommitted
Update folder structure on scaffolding (#35)
Fixes #33 & #34
1 parent c141437 commit 2479c7f

File tree

2 files changed

+50
-46
lines changed

2 files changed

+50
-46
lines changed

generator-jsonforms/README.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,32 @@ This Yeoman Generator brings you all the functions of the tooling to your termin
1818

1919
If you want to avoid the interface, you can use the following parameters:
2020

21-
### Path
21+
### Name
2222

23-
Enter the path where you want to install the project. (Default: current working directory)
23+
This name will be used inside the `package.json`. (Default: `jsonforms-react-seed`)
24+
*Note!* Only a url like schema is allowed here (e.g. no uppercase characters, no whitespaces etc.)
2425

2526
Command:
2627
```shell
27-
yo jsonforms --path "~/Documents/Project/Seed"
28+
yo jsonforms --name "my-project"
2829
```
2930

30-
### Schema Path
31+
### Path
3132

32-
Enter the path where the JSON schema is located. If not provided, a default schema will be used.
33+
Enter the path where you want to install the project. (Default: current working directory + the name of the project)
3334

3435
Command:
3536
```shell
36-
yo jsonforms --schemaPath "~/MyProject/schema.json"
37+
yo jsonforms --path "~/Documents/Project/Seed"
3738
```
3839

39-
### Name
40+
### Schema Path
4041

41-
This name will be used inside the `package.json`. (Default: `jsonforms-react-seed`)
42-
*Note!* Only a url like schema is allowed here (e.g. no uppercase characters, no whitespaces etc.)
42+
Enter the path where the JSON schema is located. If not provided, a default schema will be used.
4343

4444
Command:
4545
```shell
46-
yo jsonforms --name "my-project"
46+
yo jsonforms --schemaPath "~/MyProject/schema.json"
4747
```
4848

4949
### All together

generator-jsonforms/src/generators/app/index.ts

+40-36
Original file line numberDiff line numberDiff line change
@@ -45,35 +45,63 @@ export class JsonformsGenerator extends Generator {
4545
}
4646

4747
async prompting() {
48+
4849
if (!this.skipPrompting) {
4950
clear();
5051
this.log(
51-
chalk.blue(
52-
textSync('JSONForms Tooling', { horizontalLayout: 'full' }),
53-
),
52+
textSync('JSONForms Tooling', { horizontalLayout: 'full' }),
5453
);
5554
this.answers = await this.prompt([
5655
{
57-
name: 'path',
56+
name: 'name',
5857
type: 'input',
59-
message: 'Enter the path where the project will be installed (default: current folder):',
60-
validate: async value => {
58+
message: 'Enter a name for your seed project:',
59+
default: 'jsonforms-react-seed',
60+
validate: (value: any) => {
6161
if (value !== '') {
62-
try {
63-
await statWithPromise(value);
64-
} catch (err) {
65-
return 'Folder does not exists';
66-
}
62+
const valid = validate(value);
63+
return valid.validForNewPackages || 'Sorry, the name can only contain URL-friendly ' +
64+
'characters and cannot contain capital letters.';
6765
}
6866
return true;
6967
},
68+
when: () => {
69+
if (this.name === undefined) {
70+
return true;
71+
}
72+
if (!validate(this.name).validForNewPackages) {
73+
this.log(chalk.red('Sorry, the name can only contain URL-friendly ' +
74+
'characters and cannot contain capital letters.'));
75+
return true;
76+
}
77+
return false;
78+
}
79+
},
80+
{
81+
name: 'path',
82+
type: 'input',
83+
message: `Enter the path where the project will be installed:`,
84+
default: ( answers: any) => {
85+
if (this.name !== undefined) {
86+
return join(process.cwd(), this.name);
87+
}
88+
return join(process.cwd(), answers.name);
89+
},
90+
validate: async (value: any) => {
91+
try {
92+
await statWithPromise(value);
93+
} catch (err) {
94+
return true;
95+
}
96+
return 'Folder does already exists. Please enter a different path.';
97+
},
7098
when: (this.path == null)
7199
},
72100
{
73101
name: 'schemaPath',
74102
type: 'input',
75103
message: 'Enter the path of schema from which the ui schema will be generated (leave empty for default schema):',
76-
validate: async value => {
104+
validate: async (value: any) => {
77105
if (value !== '') {
78106
try {
79107
await statWithPromise(value);
@@ -85,30 +113,6 @@ export class JsonformsGenerator extends Generator {
85113
},
86114
when: (this.schemaPath == null)
87115
},
88-
{
89-
name: 'name',
90-
type: 'input',
91-
message: `Enter a name for your seed project (default: jsonforms-react-seed):`,
92-
validate: value => {
93-
if (value !== '') {
94-
const valid = validate(value);
95-
return valid.validForNewPackages || 'Sorry, name can only contain URL-friendly ' +
96-
'characters and name can no longer contain capital letters.';
97-
}
98-
return true;
99-
},
100-
when: () => {
101-
if (this.name === undefined) {
102-
return true;
103-
}
104-
if (!validate(this.name).validForNewPackages) {
105-
this.log(chalk.red('Sorry, name can only contain URL-friendly ' +
106-
'characters and name can no longer contain capital letters.'));
107-
return true;
108-
}
109-
return false;
110-
}
111-
}
112116
]);
113117
if (this.answers && this.answers.path === '' || this.path === '') {
114118
this.path = process.cwd();

0 commit comments

Comments
 (0)