Skip to content

Commit

Permalink
feat(generator): add challenge number automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas committed Sep 22, 2023
1 parent 40d7a8d commit e6c6e4d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
3 changes: 3 additions & 0 deletions challenge-number.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"total": 35
}
21 changes: 18 additions & 3 deletions libs/cli/src/generators/app/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ import {
E2eTestRunner,
UnitTestRunner,
} from '@nx/angular/generators';
import { formatFiles, generateFiles, names, Tree } from '@nx/devkit';
import {
formatFiles,
generateFiles,
names,
readJsonFile,
Tree,
updateJson,
} from '@nx/devkit';
import { Linter } from '@nx/linter';
import { join } from 'path';
import { getProjectDir } from '../../utils/normalize';
Expand All @@ -12,6 +19,9 @@ import { Schema } from './schema';
export async function appGenerator(tree: Tree, options: Schema) {
const { appDirectory } = getProjectDir(options.name, options.directory);

const challengeNumberPath = 'challenge-number.json';
const challengeNumber = readJsonFile(challengeNumberPath).total;

await applicationGenerator(tree, {
...options,
style: 'scss',
Expand All @@ -36,7 +46,7 @@ export async function appGenerator(tree: Tree, options: Schema) {
tmpl: '',
projectName: names(options.name).name,
title: options.title,
challengeNumber: options.challengeNumber,
challengeNumber,
docRepository: options.docRepository,
});

Expand All @@ -48,7 +58,7 @@ export async function appGenerator(tree: Tree, options: Schema) {
tmpl: '',
projectName: names(options.name).name,
title: options.title,
challengeNumber: options.challengeNumber,
challengeNumber,
difficulty: options.challengeDifficulty,
}
);
Expand All @@ -59,6 +69,11 @@ export async function appGenerator(tree: Tree, options: Schema) {
});
}

updateJson(tree, challengeNumberPath, (json) => {
json.total = json.total + 1;
return json;
});

await formatFiles(tree);
}

Expand Down
1 change: 0 additions & 1 deletion libs/cli/src/generators/app/schema.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export interface Schema {
title: string;
challengeNumber: number;
challengeDifficulty: string;
docRepository: string;
name: string;
Expand Down
9 changes: 0 additions & 9 deletions libs/cli/src/generators/app/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@
},
"x-priority": "important"
},
"challengeNumber": {
"description": "The number of your challenge.",
"type": "number",
"$default": {
"$source": "argv",
"index": 2
},
"x-priority": "important"
},
"challengeDifficulty": {
"description": "The difficulty of the challenge.",
"type": "string",
Expand Down

0 comments on commit e6c6e4d

Please sign in to comment.