Skip to content

Commit dc6e582

Browse files
authored
Add prompt to request generation destination
Add Prompt for generation destination folder
2 parents 8de1cd8 + 38924fb commit dc6e582

File tree

17 files changed

+48
-42
lines changed

17 files changed

+48
-42
lines changed

libs/schematic/generators/ng-generate/components/shared/generators/components/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@
1313

1414
export * from './chip-list/index';
1515
export * from './command-bar/index';
16-
export * from '../../../table/generators/components/export-dialog/index';

libs/schematic/generators/ng-generate/components/shared/generators/constants/semantic-explanation/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {Values} from '../../../schema';
1717
import {getTableColumValues} from '../../../utils';
1818

1919
export function generateSemanticExplanation(options: Values): Rule {
20-
return (tree: Tree, _context: SchematicContext) => {
20+
return (_tree: Tree, _context: SchematicContext) => {
2121
return mergeWith(
2222
apply(url('../shared/generators/constants/semantic-explanation/files'), [
2323
applyTemplates({
@@ -29,7 +29,7 @@ export function generateSemanticExplanation(options: Values): Rule {
2929
},
3030
name: options.name,
3131
}),
32-
move('src/app/shared/constants'),
32+
move(options.path),
3333
]),
3434
options.overwrite ? MergeStrategy.Overwrite : MergeStrategy.Error
3535
);

libs/schematic/generators/ng-generate/components/shared/index.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,6 @@ export function prepareOptions(schema: Schema, componentType: ComponentType): Sc
118118
options.jsonAccessPath = `${options.jsonAccessPath}.`;
119119
}
120120

121-
options.path = options.path || 'src/app/shared/components';
122-
123-
console.log(options);
124-
// throw new Error('Stop execution to check prepared options.');
125-
126121
return options;
127122
}
128123

@@ -243,7 +238,7 @@ export function generateGeneralFilesRules(): Array<Rule> {
243238
return [
244239
generateFilterService(options),
245240
generateGeneralStyle(options),
246-
generateTranslationFiles(options),
241+
generateTranslationFiles(options, false),
247242
wrapBuildComponentExecution(options),
248243
generateGeneralService(options),
249244
generateCustomService(options),

libs/schematic/generators/ng-generate/components/table/generators/services/storage/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function generateStorageService(options: any): Rule {
2424
options: options,
2525
name: 'storage',
2626
}),
27-
move('src/app/shared/services'),
27+
move(options.path),
2828
]),
2929
options.overwrite ? MergeStrategy.Overwrite : MergeStrategy.Error
3030
);

libs/schematic/generators/ng-generate/components/table/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {generateConfigMenu} from './generators/components/config-menu/index';
3434
import {generateTableComponent} from './generators/components/table/index';
3535
import {generateDataSource} from './generators/data-source/index';
3636
import {TableSchema} from './schema';
37+
import {LOG_COLOR} from '../../../utils/constants';
3738

3839
export default function (tableSchema: TableSchema): Rule {
3940
return (tree: Tree, context: SchematicContext) => {
@@ -42,6 +43,8 @@ export default function (tableSchema: TableSchema): Rule {
4243
}
4344

4445
export function generateTable(tableSchema: TableSchema): Rule {
46+
console.log(LOG_COLOR, 'Start generating Table component...');
47+
4548
prepareOptions(tableSchema, ComponentType.TABLE);
4649

4750
return chain([

libs/schematic/generators/ng-generate/prompter/index.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,20 @@ import {ComponentType, Schema} from '../components/shared/schema';
2121

2222
import {loader, reorderAspectModelUrnToLoad, writeConfigAndExit} from './utils';
2323
import {virtualFs} from '@angular-devkit/core';
24-
import {anotherFile, configFileName, createOrImport, importConfigFile} from './prompts-questions/shared/prompt-simple-questions';
24+
import {
25+
anotherFile,
26+
configFileName,
27+
createOrImport,
28+
importConfigFile,
29+
requestPath,
30+
} from './prompts-questions/shared/prompt-simple-questions';
2531
import {tablePrompterQuestions} from './prompts-questions/table/prompt-questions';
2632
import {pathDecision, requestAspectModelWithAspect} from './prompts-questions/shared/prompt-complex-questions';
2733
import {formPrompterQuestions} from './prompts-questions/form/prompt-questions';
2834
import {cardPrompterQuestions} from './prompts-questions/card/prompt-questions';
2935
import {typesPrompterQuestions} from './prompts-questions/types/prompt-questions';
3036
import {loadInquirer} from '../../utils/angular';
37+
import {LOG_COLOR} from '../../utils/constants';
3138

3239
// Function to dynamically load inquirer-fuzzy-path and register the prompt
3340
async function registerFuzzyPathPrompt(): Promise<any> {
@@ -69,13 +76,16 @@ export let aspect: Aspect;
6976
* @throws {Error} - Will throw an error if an error occurs during execution.
7077
*/
7178
export async function generate(subscriber: Subscriber<Tree>, tree: Tree, options: Schema, type: string) {
72-
console.log('\x1b[33m%s\x1b[0m', 'Welcome to the TTL schematic UI generator, answer some questions to get you started:');
79+
console.log(LOG_COLOR, 'Welcome to the TTL schematic UI generator, answer some questions to get you started:');
7380

7481
inquirer = await registerFuzzyPathPrompt();
7582
generationType = type as ComponentType;
7683
initAnswers();
7784

7885
runPrompts(subscriber, tree, new TemplateHelper(), options).finally(() => {
86+
// "path" is the default options property for schematics to determine where to generate files
87+
allAnswers.path = allAnswers.pathToSource;
88+
7989
cleanUpOptionsObject(allAnswers);
8090
Object.assign(options, allAnswers);
8191

@@ -180,7 +190,7 @@ async function runPrompts(subscriber: Subscriber<Tree>, tree: Tree, templateHelp
180190
* @returns {Promise<Object>} A promise that resolves to the answers from the user.
181191
*/
182192
async function getConfigurationFileConfig(subscriber: Subscriber<Tree>, tree: Tree) {
183-
const answerGeneralConfig = await inquirer.prompt([createOrImport, configFileName, importConfigFile, pathDecision(WIZARD_CONFIG_FILE)]);
193+
const answerGeneralConfig = await inquirer.prompt([createOrImport, requestPath, configFileName, importConfigFile, pathDecision(WIZARD_CONFIG_FILE)]);
184194

185195
if (answerGeneralConfig.importConfigFile) {
186196
importFileConfig(answerGeneralConfig.importConfigFile, subscriber, tree);
@@ -323,7 +333,8 @@ function cleanUpOptionsObject(allAnswers: any) {
323333
objectKey.startsWith('paths') ||
324334
objectKey.startsWith('anotherFile') ||
325335
objectKey.startsWith('createOrImport') ||
326-
objectKey.startsWith('importConfigFile')
336+
objectKey.startsWith('importConfigFile') ||
337+
objectKey.startsWith('pathToSource')
327338
) {
328339
delete allAnswers[objectKey];
329340
}

libs/schematic/generators/ng-generate/prompter/prompts-questions/shared/prompt-complex-questions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ export const requestAspectModelWithAspect = (allAnswers: any) => ({
204204
default: '',
205205
});
206206

207-
export const pathDecision: any = (configFile: string, anotherFile: boolean = false) => ({
207+
export const pathDecision: any = (configFile: string, anotherFile = false) => ({
208208
type: 'fuzzypath',
209209
name: 'paths',
210210
excludeFilter: (nodePath: string) => !nodePath.endsWith('.ttl'),

libs/schematic/generators/ng-generate/prompter/prompts-questions/shared/prompt-simple-questions.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,13 @@ export const requestSetViewEncapsulation = {
103103
choices: [ViewEncapsulation.None, ViewEncapsulation.Emulated, ViewEncapsulation.ShadowDom],
104104
default: ViewEncapsulation.None,
105105
};
106+
107+
export const requestPath = {
108+
type: 'input',
109+
name: 'pathToSource',
110+
message: `Input the path to the source files where the component files should be generated (e.g., src/app/components):`,
111+
filter: (input: string) => input.trim(),
112+
default: 'src/app/shared',
113+
when: answer => answer['createOrImport'],
114+
};
115+

libs/schematic/generators/ng-generate/prompter/prompts-questions/table/prompt-questions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export async function tablePrompterQuestions(
6464
combineAnswers: (...answers: any[]) => any,
6565
allAnswers: any
6666
): Promise<void> {
67-
const defaultConfiguration: ConfigurationDefaultsSchema = new TableDefaultsSchema();
67+
const defaultConfiguration: ConfigurationDefaultsSchema = {};
6868

6969
combineAnswers(
7070
answerConfigurationFileConfig,

libs/schematic/generators/ng-generate/prompter/utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {Subscriber} from 'rxjs';
1717
import * as fs from 'fs';
1818
import * as util from 'util';
1919
import {WIZARD_CONFIG_FILE} from './index';
20+
import {LOG_COLOR} from '../../utils/constants';
2021

2122
interface PropertyDetail {
2223
name: string;
@@ -81,12 +82,13 @@ export function handleComplexPropList(property: Property, complexPropList: Array
8182
* @param {any} config - The configuration to write to the file.
8283
* @param {boolean} [fromImport=false] - A flag to indicate if the operation is from an import.
8384
*/
85+
// TODO add config file name as parameter
8486
export async function writeConfigAndExit(subscriber: Subscriber<Tree>, tree: Tree, config: any, fromImport = false) {
8587
const writeFileAsync = util.promisify(fs.writeFile);
8688
await writeFileAsync(WIZARD_CONFIG_FILE, JSON.stringify(config), 'utf8');
8789

8890
console.log(
89-
'\x1b[33m%s\x1b[0m',
91+
LOG_COLOR,
9092
fromImport
9193
? `The import was successful, the config used for your generation can be found here: ${WIZARD_CONFIG_FILE}`
9294
: `New config file was generated based on your choices, it can be found here: ${WIZARD_CONFIG_FILE}`

0 commit comments

Comments
 (0)