Skip to content

Commit 5735a8d

Browse files
authored
Merge pull request #19 from bci-oss/feature/optizmize-options-list-for-selecting-config-files
Optimize prompt that only wizard configs are shown
2 parents c1bcfd4 + a419336 commit 5735a8d

File tree

8 files changed

+41
-18
lines changed

8 files changed

+41
-18
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jest-stare/
1414
node_modules/
1515
npm-debug.log*
1616
yarn-error.log*
17-
wizard-config.json
17+
*wizard.config.json
1818

1919
# Mac OSX Finder files.
2020
**/.DS_Store

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ If you want to use a pre-existing config file, without going through the generat
558558
.json config using the 'configFile' flag by running the command like this:
559559
560560
```bash
561-
ng generate @esmf/semantic-ui-schematics:table --configFile=wizard-configs/<config-file-name>.json
561+
ng generate @esmf/semantic-ui-schematics:table --configFile=<config-file-name>-wizard.configs.json
562562
```
563563
564564
Example of configuration file:
@@ -567,7 +567,7 @@ Example of configuration file:
567567
{
568568
"aspectModelTFiles": ["FOLDER\\Movement.ttl"],
569569
"excludedProperties": [],
570-
"configFile": "wizard-config.json",
570+
"configFile": "wizard.config.json",
571571
"complexProps": [
572572
{
573573
"prop": "position",
42.4 KB
Loading
11.7 KB
Loading

documentation/js-sdk-guide/modules/tooling-guide/pages/table-generation.adoc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,19 @@ auto-generated. The first prompt allows you to load a config file or start from
4646

4747
image::config-file-loading.png[width=100%]
4848

49-
Loading pre-existing config file will result into this:
49+
When you decide to create a new configuration file, you will be prompted to specify a name for your config file. This provided name will be integrated into the default naming structure for the config file.
50+
51+
The naming structure is <config-file-name>-wizard.config.json. Here, <config-file-name> is the name that you provide when prompted.
52+
53+
For example, if you enter myConfig when prompted for the config file name, your new config file will be named myConfig-wizard.config.json.
54+
55+
image::schema.enter-name-for-config-file.png[width=100%]
56+
57+
When you decide to load a pre-existing config file, the system will display the result as follows:
5058

5159
image::schema.load-config-file.yes.png[width=100%]
5260

53-
This will give access to the folder structure and by using a FUZZY search mechanism can provide the possibility to input the pre-existing config file. By default, the config file is called _wizard-config.json_ and can be found in the root folder of the project.
61+
This will give access to the folder structure and by using a FUZZY search mechanism can provide the possibility to input the pre-existing config file. The config file will now be named based on your input _<config-file-name>_-wizard.config.json, and can be found in the root folder of the project.
5462

5563
=== _Aspect Model selection_
5664
If no pre-existing config file is loaded, then there is an option to choose for one or multiple Aspect Model files from the folder structure, using the same FUZZY search mechanism.

src/ng-generate/table-prompter/index.ts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import {
2929
import * as fs from 'fs';
3030
import inquirer, {Answers, Question, QuestionAnswer} from 'inquirer';
3131
import {Observable, Subject, Subscriber} from 'rxjs';
32-
import {WIZARD_CONFIG_FILE} from '../../utils/file';
3332
import {TemplateHelper} from '../../utils/template-helper';
3433
import {Schema} from '../table/schema';
3534
import * as locale from 'locale-codes';
@@ -38,6 +37,8 @@ inquirer.registerPrompt('fuzzypath', require('inquirer-fuzzy-path'));
3837
inquirer.registerPrompt('suggest', require('inquirer-prompt-suggest'));
3938
inquirer.registerPrompt('search-list', require('inquirer-search-list'));
4039

40+
export let WIZARD_CONFIG_FILE = 'wizard.config.json';
41+
4142
const loader = new AspectModelLoader();
4243

4344
let aspect: Aspect;
@@ -144,14 +145,23 @@ function getTtlPaths(promptSubj: Subject<any>, allAnswers: Schema, subscriber: S
144145
default: false,
145146
};
146147

148+
const configFileName = {
149+
type: 'input',
150+
name: 'configFileName',
151+
message: 'Please enter a name for your config file. It will be automatically appended to (<config-file-name>-wizard.config.json):',
152+
validate: function (input: string) {
153+
return input.length === 0 ? 'The config file name cannot be empty. Please provide a valid name.' : true;
154+
}
155+
};
156+
147157
const importConfigFile = {
148158
type: 'fuzzypath',
149159
name: 'importConfigFile',
150-
excludeFilter: (nodePath: any) => !nodePath.endsWith('.json'),
160+
excludeFilter: (nodePath: any) => !nodePath.endsWith('wizard.config.json'),
151161
excludePath: (nodePath: any) => nodePath.startsWith('node_modules'),
152162
itemType: 'file',
153-
message: 'Choose the path to an existing wizard config file(.json). Start writing file name for suggestions:',
154-
default: './',
163+
message: 'Choose the path to an existing wizard config file which ends with "wizard.config.json". Start writing file name for suggestions:',
164+
rootPath: './',
155165
suggestOnly: false,
156166
depthLimit: 5,
157167
};
@@ -163,7 +173,7 @@ function getTtlPaths(promptSubj: Subject<any>, allAnswers: Schema, subscriber: S
163173
excludePath: (nodePath: any) => nodePath.startsWith('node_modules'),
164174
itemType: 'file',
165175
message: 'Choose the path to a .ttl file. Start writing file name for suggestions:',
166-
default: './',
176+
rootPath: './',
167177
suggestOnly: false,
168178
depthLimit: 5,
169179
};
@@ -181,20 +191,27 @@ function getTtlPaths(promptSubj: Subject<any>, allAnswers: Schema, subscriber: S
181191
switch (true) {
182192
case singleAnswer.name === createOrImport.name: {
183193
if (singleAnswer.answer) {
184-
promptSubj.next(pathDecision);
194+
promptSubj.next(configFileName);
185195
} else {
186196
promptSubj.next(importConfigFile);
187197
}
188198
break;
189199
}
200+
case singleAnswer.name === configFileName.name: {
201+
if (singleAnswer.answer !== WIZARD_CONFIG_FILE) {
202+
WIZARD_CONFIG_FILE = `${singleAnswer.answer}-${WIZARD_CONFIG_FILE}`;
203+
}
204+
promptSubj.next(pathDecision);
205+
break;
206+
}
190207
case singleAnswer.name === importConfigFile.name: {
191-
const configFileName = singleAnswer.answer;
192-
if (!configFileName) {
208+
const fileName = singleAnswer.answer;
209+
if (!fileName) {
193210
console.log('Error loading config file. Try again with a different file ! ');
194211
promptSubj.complete();
195212
}
196213
try {
197-
const data = fs.readFileSync(configFileName, 'utf8');
214+
const data = fs.readFileSync(fileName, 'utf8');
198215
fromImport = true;
199216
promptSubj.complete();
200217
writeConfigAndExit(subscriber, tree, JSON.parse(data), true);
@@ -212,7 +229,6 @@ function getTtlPaths(promptSubj: Subject<any>, allAnswers: Schema, subscriber: S
212229
promptSubj.next(pathDecision);
213230
}
214231
break;
215-
216232
case singleAnswer.name === pathDecision.name: {
217233
const ttlFileName = singleAnswer.answer;
218234
if (!ttlFileName) {

src/ng-generate/table/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
wrapBuildComponentExecution,
2525
} from '../../utils/angular';
2626
import {generateTranslationFiles, generateTranslationModule, loadAspectModel, loadRDF} from '../../utils/aspect-model';
27-
import {createOrOverwrite, formatGeneratedFiles, loadAndApplyConfigFile, WIZARD_CONFIG_FILE} from '../../utils/file';
27+
import {createOrOverwrite, formatGeneratedFiles, loadAndApplyConfigFile} from '../../utils/file';
2828
import {addPackageJsonDependencies, DEFAULT_DEPENDENCIES} from '../../utils/package-json';
2929
import {TemplateHelper} from '../../utils/template-helper';
3030
import {HtmlGenerator} from './generators/html.generator';
@@ -35,6 +35,7 @@ import {Schema} from './schema';
3535
import {TsComponentGenerator} from './generators/ts-component.generator';
3636
import {addModuleImportToModule} from '@angular/cdk/schematics';
3737
import ora from 'ora';
38+
import {WIZARD_CONFIG_FILE} from "../table-prompter/index";
3839

3940
export default function (options: Schema): Rule {
4041
return (tree: Tree, context: SchematicContext): void => {

src/utils/file.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ const prettier = require('prettier');
2121
// this resolves the config provided by the schematics lib
2222
const defaultPrettierConfigPath = require.resolve('../../.prettierrc');
2323

24-
export const WIZARD_CONFIG_FILE = 'wizard-config.json';
25-
2624
export function loadAndApplyConfigFile(configFile: string, options: any): void {
2725
try {
2826
if (options.configFile && options.configFile !== '') {

0 commit comments

Comments
 (0)