Add roadmap path generation

pull/1331/head
Kamran Ahmed 3 years ago
parent 1fbdf68573
commit 1afe684699
  1. 132
      content/roadmaps/100-frontend/content-paths.json
  2. 44
      scripts/content-skeleton.ts

@ -0,0 +1,132 @@
{
"home": "/100-frontend/content/readme.md",
"internet": "/100-frontend/content/100-internet/readme.md",
"internet:how-does-the-internet-work": "/100-frontend/content/100-internet/100-how-does-the-internet-work.md",
"internet:what-is-http": "/100-frontend/content/100-internet/101-what-is-http.md",
"internet:browsers-and-how-they-work": "/100-frontend/content/100-internet/102-browsers-and-how-they-work.md",
"internet:dns-and-how-it-works": "/100-frontend/content/100-internet/103-dns-and-how-it-works.md",
"internet:what-is-domain-name": "/100-frontend/content/100-internet/104-what-is-domain-name.md",
"internet:what-is-hosting": "/100-frontend/content/100-internet/105-what-is-hosting.md",
"html": "/100-frontend/content/101-html/readme.md",
"html:learn-the-basics": "/100-frontend/content/101-html/100-learn-the-basics.md",
"html:writing-semantic-html": "/100-frontend/content/101-html/101-writing-semantic-html.md",
"html:forms-and-validations": "/100-frontend/content/101-html/102-forms-and-validations.md",
"html:conventions-and-best-practices": "/100-frontend/content/101-html/103-conventions-and-best-practices.md",
"html:accessibility": "/100-frontend/content/101-html/104-accessibility.md",
"html:seo-basics": "/100-frontend/content/101-html/105-seo-basics.md",
"css": "/100-frontend/content/102-css/readme.md",
"css:learn-the-basics": "/100-frontend/content/102-css/100-learn-the-basics.md",
"css:making-layouts": "/100-frontend/content/102-css/101-making-layouts.md",
"css:responsive-design-and-media-queries": "/100-frontend/content/102-css/102-responsive-design-and-media-queries.md",
"javascript": "/100-frontend/content/103-javascript/readme.md",
"javascript:syntax-and-basic-constructs": "/100-frontend/content/103-javascript/100-syntax-and-basic-constructs.md",
"javascript:learn-dom-manipulation": "/100-frontend/content/103-javascript/101-learn-dom-manipulation.md",
"javascript:learn-fetch-api-ajax-xhr": "/100-frontend/content/103-javascript/102-learn-fetch-api-ajax-xhr.md",
"javascript:es6-and-modular-javascript": "/100-frontend/content/103-javascript/103-es6-and-modular-javascript.md",
"javascript:concepts": "/100-frontend/content/103-javascript/104-concepts.md",
"version-control-systems": "/100-frontend/content/104-version-control-systems/readme.md",
"version-control-systems:basic-usage-of-git": "/100-frontend/content/104-version-control-systems/100-basic-usage-of-git.md",
"repo-hosting-services": "/100-frontend/content/105-repo-hosting-services/readme.md",
"repo-hosting-services:github": "/100-frontend/content/105-repo-hosting-services/100-github.md",
"repo-hosting-services:gitlab": "/100-frontend/content/105-repo-hosting-services/101-gitlab.md",
"repo-hosting-services:bitbucket": "/100-frontend/content/105-repo-hosting-services/102-bitbucket.md",
"web-security-knowledge": "/100-frontend/content/106-web-security-knowledge/readme.md",
"web-security-knowledge:cors": "/100-frontend/content/106-web-security-knowledge/102-cors.md",
"web-security-knowledge:https": "/100-frontend/content/106-web-security-knowledge/100-https.md",
"web-security-knowledge:content-security-policy": "/100-frontend/content/106-web-security-knowledge/101-content-security-policy.md",
"web-security-knowledge:owasp-security-risks": "/100-frontend/content/106-web-security-knowledge/103-owasp-security-risks.md",
"package-managers": "/100-frontend/content/107-package-managers/readme.md",
"package-managers:npm": "/100-frontend/content/107-package-managers/100-npm.md",
"package-managers:yarn": "/100-frontend/content/107-package-managers/101-yarn.md",
"css-architecture": "/100-frontend/content/108-css-architecture/readme.md",
"css-architecture:bem": "/100-frontend/content/108-css-architecture/100-bem.md",
"css-architecture:oocss": "/100-frontend/content/108-css-architecture/101-oocss.md",
"css-architecture:smacss": "/100-frontend/content/108-css-architecture/102-smacss.md",
"css-preprocessors": "/100-frontend/content/109-css-preprocessors/readme.md",
"css-preprocessors:sass": "/100-frontend/content/109-css-preprocessors/100-sass.md",
"css-preprocessors:postcss": "/100-frontend/content/109-css-preprocessors/101-postcss.md",
"css-preprocessors:less": "/100-frontend/content/109-css-preprocessors/102-less.md",
"build-tools": "/100-frontend/content/110-build-tools/readme.md",
"build-tools:task-runners": "/100-frontend/content/110-build-tools/100-task-runners/readme.md",
"build-tools:100-task-runners/npm-scripts": "/100-frontend/content/110-build-tools/100-task-runners/npm-scripts.md",
"build-tools:linters-formatters": "/100-frontend/content/110-build-tools/102-linters-formatters/readme.md",
"build-tools:102-linters-formatters/prettier": "/100-frontend/content/110-build-tools/102-linters-formatters/prettier.md",
"build-tools:102-linters-formatters/eslint": "/100-frontend/content/110-build-tools/102-linters-formatters/eslint.md",
"build-tools:102-linters-formatters/standardjs": "/100-frontend/content/110-build-tools/102-linters-formatters/standardjs.md",
"build-tools:module-bundlers": "/100-frontend/content/110-build-tools/101-module-bundlers/readme.md",
"build-tools:101-module-bundlers/webpack": "/100-frontend/content/110-build-tools/101-module-bundlers/webpack.md",
"build-tools:101-module-bundlers/esbuild": "/100-frontend/content/110-build-tools/101-module-bundlers/esbuild.md",
"build-tools:101-module-bundlers/rollup": "/100-frontend/content/110-build-tools/101-module-bundlers/rollup.md",
"build-tools:101-module-bundlers/parcel": "/100-frontend/content/110-build-tools/101-module-bundlers/parcel.md",
"build-tools:101-module-bundlers/vite": "/100-frontend/content/110-build-tools/101-module-bundlers/vite.md",
"pick-a-framework": "/100-frontend/content/111-pick-a-framework/readme.md",
"pick-a-framework:react-js": "/100-frontend/content/111-pick-a-framework/100-react-js/readme.md",
"pick-a-framework:100-react-js/recoil": "/100-frontend/content/111-pick-a-framework/100-react-js/recoil.md",
"pick-a-framework:100-react-js/redux": "/100-frontend/content/111-pick-a-framework/100-react-js/redux.md",
"pick-a-framework:100-react-js/mobx": "/100-frontend/content/111-pick-a-framework/100-react-js/mobx.md",
"pick-a-framework:angular": "/100-frontend/content/111-pick-a-framework/101-angular/readme.md",
"pick-a-framework:101-angular/rxjs": "/100-frontend/content/111-pick-a-framework/101-angular/rxjs.md",
"pick-a-framework:101-angular/ngrx": "/100-frontend/content/111-pick-a-framework/101-angular/ngrx.md",
"pick-a-framework:vue-js": "/100-frontend/content/111-pick-a-framework/102-vue-js/readme.md",
"pick-a-framework:102-vue-js/vuex": "/100-frontend/content/111-pick-a-framework/102-vue-js/vuex.md",
"modern-css": "/100-frontend/content/112-modern-css/readme.md",
"modern-css:styled-components": "/100-frontend/content/112-modern-css/100-styled-components.md",
"modern-css:css-modules": "/100-frontend/content/112-modern-css/101-css-modules.md",
"modern-css:styled-jsx": "/100-frontend/content/112-modern-css/102-styled-jsx.md",
"modern-css:emotion": "/100-frontend/content/112-modern-css/103-emotion.md",
"web-components": "/100-frontend/content/113-web-components/readme.md",
"web-components:html-templates": "/100-frontend/content/113-web-components/100-html-templates.md",
"web-components:custom-elements": "/100-frontend/content/113-web-components/101-custom-elements.md",
"web-components:shadow-dom": "/100-frontend/content/113-web-components/102-shadow-dom.md",
"css-frameworks": "/100-frontend/content/114-css-frameworks/readme.md",
"css-frameworks:js-first": "/100-frontend/content/114-css-frameworks/114-js-first/readme.md",
"css-frameworks:114-js-first/chakra-ui": "/100-frontend/content/114-css-frameworks/114-js-first/chakra-ui.md",
"css-frameworks:114-js-first/material-ui": "/100-frontend/content/114-css-frameworks/114-js-first/material-ui.md",
"css-frameworks:114-js-first/radix-ui": "/100-frontend/content/114-css-frameworks/114-js-first/radix-ui.md",
"css-frameworks:114-js-first/tailwind-css": "/100-frontend/content/114-css-frameworks/114-js-first/tailwind-css.md",
"css-frameworks:css-first": "/100-frontend/content/114-css-frameworks/114-css-first/readme.md",
"css-frameworks:114-css-first/bootstrap": "/100-frontend/content/114-css-frameworks/114-css-first/bootstrap.md",
"css-frameworks:114-css-first/bulma": "/100-frontend/content/114-css-frameworks/114-css-first/bulma.md",
"testing-your-apps": "/100-frontend/content/115-testing-your-apps/readme.md",
"testing-your-apps:jest": "/100-frontend/content/115-testing-your-apps/100-jest.md",
"testing-your-apps:react-testing-library": "/100-frontend/content/115-testing-your-apps/101-react-testing-library.md",
"testing-your-apps:cypress": "/100-frontend/content/115-testing-your-apps/102-cypress.md",
"testing-your-apps:enzyme": "/100-frontend/content/115-testing-your-apps/103-enzyme.md",
"testing-your-apps:other-options": "/100-frontend/content/115-testing-your-apps/104-other-options.md",
"type-checkers": "/100-frontend/content/116-type-checkers/readme.md",
"type-checkers:typescript": "/100-frontend/content/116-type-checkers/100-typescript.md",
"type-checkers:flow": "/100-frontend/content/116-type-checkers/101-flow.md",
"progressive-web-apps": "/100-frontend/content/117-progressive-web-apps/readme.md",
"progressive-web-apps:performance": "/100-frontend/content/117-progressive-web-apps/101-performance.md",
"progressive-web-apps:apis": "/100-frontend/content/117-progressive-web-apps/100-apis.md",
"server-side-rendering": "/100-frontend/content/118-server-side-rendering/readme.md",
"server-side-rendering:react-js": "/100-frontend/content/118-server-side-rendering/100-react-js/readme.md",
"server-side-rendering:100-react-js/next-js": "/100-frontend/content/118-server-side-rendering/100-react-js/next-js.md",
"server-side-rendering:100-react-js/after-js": "/100-frontend/content/118-server-side-rendering/100-react-js/after-js.md",
"server-side-rendering:angular": "/100-frontend/content/118-server-side-rendering/101-angular/readme.md",
"server-side-rendering:101-angular/universal": "/100-frontend/content/118-server-side-rendering/101-angular/universal.md",
"server-side-rendering:vue-js": "/100-frontend/content/118-server-side-rendering/102-vue-js/readme.md",
"server-side-rendering:102-vue-js/nuxt-js": "/100-frontend/content/118-server-side-rendering/102-vue-js/nuxt-js.md",
"graphql": "/100-frontend/content/119-graphql/readme.md",
"graphql:apollo": "/100-frontend/content/119-graphql/100-apollo.md",
"graphql:relay-modern": "/100-frontend/content/119-graphql/101-relay-modern.md",
"static-site-generators": "/100-frontend/content/120-static-site-generators/readme.md",
"static-site-generators:next-js": "/100-frontend/content/120-static-site-generators/100-next-js.md",
"static-site-generators:gatsbyjs": "/100-frontend/content/120-static-site-generators/101-gatsbyjs.md",
"static-site-generators:nuxt-js": "/100-frontend/content/120-static-site-generators/102-nuxt-js.md",
"static-site-generators:vuepress": "/100-frontend/content/120-static-site-generators/103-vuepress.md",
"static-site-generators:jekyll": "/100-frontend/content/120-static-site-generators/104-jekyll.md",
"static-site-generators:hugo": "/100-frontend/content/120-static-site-generators/105-hugo.md",
"static-site-generators:gridsome": "/100-frontend/content/120-static-site-generators/106-gridsome.md",
"static-site-generators:eleventy": "/100-frontend/content/120-static-site-generators/107-eleventy.md",
"mobile-applications": "/100-frontend/content/121-mobile-applications/readme.md",
"mobile-applications:react-native": "/100-frontend/content/121-mobile-applications/100-react-native.md",
"mobile-applications:nativescript": "/100-frontend/content/121-mobile-applications/101-nativescript.md",
"mobile-applications:flutter": "/100-frontend/content/121-mobile-applications/102-flutter.md",
"mobile-applications:ionic": "/100-frontend/content/121-mobile-applications/103-ionic.md",
"desktop-applications": "/100-frontend/content/122-desktop-applications/readme.md",
"desktop-applications:electron": "/100-frontend/content/122-desktop-applications/100-electron.md",
"desktop-applications:carlo": "/100-frontend/content/122-desktop-applications/101-carlo.md",
"desktop-applications:proton-native": "/100-frontend/content/122-desktop-applications/102-proton-native.md",
"web-assembly": "/100-frontend/content/123-web-assembly.md"
}

@ -61,11 +61,12 @@ if (!roadmapDirName) {
process.exit(1);
}
const roadmapContentPath = path.join(CONTENT_DIR, roadmapDirName, 'content');
const roadmapDirPath = path.join(CONTENT_DIR, roadmapDirName);
const roadmapContentDirPath = path.join(CONTENT_DIR, roadmapDirName, 'content');
// If roadmap content already exists do not proceed as it would override the files
if (fs.existsSync(roadmapContentPath)) {
console.error(`Roadmap content already exists @ ${roadmapContentPath}`);
if (fs.existsSync(roadmapContentDirPath)) {
console.error(`Roadmap content already exists @ ${roadmapContentDirPath}`);
process.exit(1);
}
@ -150,12 +151,23 @@ controls.forEach((control) => {
prepareDirTree(control, dirTree, dirSortOrders);
});
function createDirTree(parentDir: string, dirTree: DirTreeType, sortOrders: DirSortOrdersType) {
/**
* @param parentDir Parent directory in which directory is to be created
* @param dirTree Nested dir tree to be created
* @param sortOrders Mapping from groupName to sort order
* @param filePaths The mapping from groupName to file path
*/
function createDirTree(
parentDir: string,
dirTree: DirTreeType,
sortOrders: DirSortOrdersType,
filePaths: Record<string, string> = {}
) {
const childrenDirNames = Object.keys(dirTree);
const hasChildren = childrenDirNames.length !== 0;
const groupName = parentDir
.replace(roadmapContentPath, '') // Remove base dir path
.replace(roadmapContentDirPath, '') // Remove base dir path
.replace(/(^\/)|(\/$)/g, '') // Remove trailing slashes
.replace(/(^\d+?-)/g, '') // Remove sorting information
.replace('/', ':'); // Replace slashes with `:`
@ -171,14 +183,21 @@ function createDirTree(parentDir: string, dirTree: DirTreeType, sortOrders: DirS
// If no children, create a file for this under the parent directory
if (!hasChildren) {
fs.writeFileSync(`${parentDir}.md`, '');
return;
let fileName = `${parentDir}.md`;
fs.writeFileSync(fileName, '');
filePaths[groupName || 'home'] = fileName.replace(CONTENT_DIR, '');
return filePaths;
}
// There *are* children, so create the parent as a directory
// and create `readme.md` as the content file for this
fs.mkdirSync(parentDir);
fs.writeFileSync(path.join(parentDir, 'readme.md'), '');
let readmeFilePath = path.join(parentDir, 'readme.md');
fs.writeFileSync(readmeFilePath, '');
filePaths[groupName || 'home'] = readmeFilePath.replace(CONTENT_DIR, '');
// For each of the directory names, create a
// directory inside the given directory
@ -186,9 +205,14 @@ function createDirTree(parentDir: string, dirTree: DirTreeType, sortOrders: DirS
createDirTree(
path.join(parentDir, dirName),
dirTree[dirName],
dirSortOrders
dirSortOrders,
filePaths
);
});
return filePaths;
}
createDirTree(roadmapContentPath, dirTree, dirSortOrders);
const filePaths = createDirTree(roadmapContentDirPath, dirTree, dirSortOrders);
fs.writeFileSync(path.join(roadmapDirPath, 'content-paths.json'), JSON.stringify(filePaths, null, 2));

Loading…
Cancel
Save