mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-10 12:53:03 -05:00
feat(generator): add the management of new badge
This commit is contained in:
@@ -3,6 +3,7 @@ title: <%= difficulty %> <%= title %>
|
|||||||
description: Challenge <%= challengeNumber %> is about ...
|
description: Challenge <%= challengeNumber %> is about ...
|
||||||
sidebar:
|
sidebar:
|
||||||
order: <%= order %>
|
order: <%= order %>
|
||||||
|
badge: New
|
||||||
---
|
---
|
||||||
|
|
||||||
:::note
|
:::note
|
||||||
|
|||||||
@@ -16,6 +16,30 @@ import { join } from 'path';
|
|||||||
import { getProjectDir } from '../../utils/normalize';
|
import { getProjectDir } from '../../utils/normalize';
|
||||||
import { Schema } from './schema';
|
import { Schema } from './schema';
|
||||||
|
|
||||||
|
function findPreviousChallengeFilePath(tree, path, number) {
|
||||||
|
if (tree.isFile(path) && path.startsWith(`${number}-`)) {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
const matchingChild = tree
|
||||||
|
.children(path)
|
||||||
|
.find((child) => child.startsWith(`${number}-`));
|
||||||
|
|
||||||
|
if (matchingChild) {
|
||||||
|
const fullPath = path + '/' + matchingChild;
|
||||||
|
return fullPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const child of tree.children(path)) {
|
||||||
|
const childPath = path + '/' + child;
|
||||||
|
const result = findPreviousChallengeFilePath(tree, childPath, number);
|
||||||
|
if (result) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
export async function challengeGenerator(tree: Tree, options: Schema) {
|
export async function challengeGenerator(tree: Tree, options: Schema) {
|
||||||
const { appDirectory } = getProjectDir(options.name, options.directory);
|
const { appDirectory } = getProjectDir(options.name, options.directory);
|
||||||
|
|
||||||
@@ -51,7 +75,7 @@ export async function challengeGenerator(tree: Tree, options: Schema) {
|
|||||||
tmpl: '',
|
tmpl: '',
|
||||||
projectName: names(options.name).name,
|
projectName: names(options.name).name,
|
||||||
title: options.title,
|
title: options.title,
|
||||||
challengeNumber: challengeNumber + 1,
|
challengeNumber,
|
||||||
docRepository: options.docRepository,
|
docRepository: options.docRepository,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -92,6 +116,20 @@ export async function challengeGenerator(tree: Tree, options: Schema) {
|
|||||||
|
|
||||||
tree.write('./docs/src/content/docs/index.mdx', replaced);
|
tree.write('./docs/src/content/docs/index.mdx', replaced);
|
||||||
|
|
||||||
|
const previousChallengeFilePath = findPreviousChallengeFilePath(
|
||||||
|
tree,
|
||||||
|
`./docs/src/content/docs/challenges`,
|
||||||
|
String(challengeNumber - 1)
|
||||||
|
);
|
||||||
|
console.log(`restul`, previousChallengeFilePath);
|
||||||
|
|
||||||
|
const previousChallenge = tree.read(previousChallengeFilePath).toString();
|
||||||
|
|
||||||
|
tree.write(
|
||||||
|
previousChallengeFilePath,
|
||||||
|
previousChallenge.replace(`badge: New`, ``)
|
||||||
|
);
|
||||||
|
|
||||||
updateJson(tree, challengeNumberPath, (json) => {
|
updateJson(tree, challengeNumberPath, (json) => {
|
||||||
json.total += 1;
|
json.total += 1;
|
||||||
json[difficulty] += 1;
|
json[difficulty] += 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user