From ce11b2e6de18c056ff4ef3201e689336cc0b1683 Mon Sep 17 00:00:00 2001 From: Thomas Mair Date: Tue, 24 Oct 2023 17:01:37 +0200 Subject: [PATCH] docs: use a processor to transform the operator decision tree data --- .../operator-decision-tree.yml} | 0 apps/rxjs.dev/package.json | 5 +-- .../decision-tree-generator/jest.config.js | 8 ---- .../tools/decision-tree-generator/main.ts | 28 ------------ .../decision-tree-generator/package.json | 28 ------------ .../decision-tree-generator/tsconfig.json | 6 --- .../transforms/angular.io-package/index.js | 7 ++- apps/rxjs.dev/tools/transforms/config.js | 2 + .../rxjs-decision-tree-generator}/README.md | 0 .../rxjs-decision-tree-generator/index.ts | 37 ++++++++++++++++ .../src/lib/addUniqueId.spec.ts | 29 ++++++------ .../src/lib/addUniqueId.ts | 0 .../src/lib/build.spec.ts | 4 +- .../src/lib/build.ts | 6 +-- .../src/lib/decisionTreeReducer.spec.ts | 44 +++++++------------ .../src/lib/decisionTreeReducer.ts | 32 +++++--------- .../src/lib/extractInitialSequence.spec.ts | 6 +-- .../src/lib/extractInitialSequence.ts | 0 .../src/lib/fixtures.ts | 0 .../src/lib/flattenApiList.spec.ts | 2 +- .../src/lib/flattenApiList.ts | 0 .../src/lib/generateUniqueId.spec.ts | 0 .../src/lib/generateUniqueId.ts | 0 .../src/lib/helpers.spec.ts | 0 .../src/lib/helpers.ts | 2 +- .../src/lib/index.ts | 0 .../src/lib/interfaces.ts | 0 apps/rxjs.dev/tools/transforms/test.js | 2 +- yarn.lock | 17 ++++--- 29 files changed, 111 insertions(+), 154 deletions(-) rename apps/rxjs.dev/{tools/decision-tree-generator/src/tree.yml => content/operator-decision-tree.yml} (100%) delete mode 100644 apps/rxjs.dev/tools/decision-tree-generator/jest.config.js delete mode 100644 apps/rxjs.dev/tools/decision-tree-generator/main.ts delete mode 100644 apps/rxjs.dev/tools/decision-tree-generator/package.json delete mode 100644 apps/rxjs.dev/tools/decision-tree-generator/tsconfig.json rename apps/rxjs.dev/tools/{decision-tree-generator => transforms/rxjs-decision-tree-generator}/README.md (100%) create mode 100644 apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/index.ts rename apps/rxjs.dev/tools/{decision-tree-generator => transforms/rxjs-decision-tree-generator}/src/lib/addUniqueId.spec.ts (59%) rename apps/rxjs.dev/tools/{decision-tree-generator => transforms/rxjs-decision-tree-generator}/src/lib/addUniqueId.ts (100%) rename apps/rxjs.dev/tools/{decision-tree-generator => transforms/rxjs-decision-tree-generator}/src/lib/build.spec.ts (75%) rename apps/rxjs.dev/tools/{decision-tree-generator => transforms/rxjs-decision-tree-generator}/src/lib/build.ts (80%) rename apps/rxjs.dev/tools/{decision-tree-generator => transforms/rxjs-decision-tree-generator}/src/lib/decisionTreeReducer.spec.ts (67%) rename apps/rxjs.dev/tools/{decision-tree-generator => transforms/rxjs-decision-tree-generator}/src/lib/decisionTreeReducer.ts (60%) rename apps/rxjs.dev/tools/{decision-tree-generator => transforms/rxjs-decision-tree-generator}/src/lib/extractInitialSequence.spec.ts (79%) rename apps/rxjs.dev/tools/{decision-tree-generator => transforms/rxjs-decision-tree-generator}/src/lib/extractInitialSequence.ts (100%) rename apps/rxjs.dev/tools/{decision-tree-generator => transforms/rxjs-decision-tree-generator}/src/lib/fixtures.ts (100%) rename apps/rxjs.dev/tools/{decision-tree-generator => transforms/rxjs-decision-tree-generator}/src/lib/flattenApiList.spec.ts (87%) rename apps/rxjs.dev/tools/{decision-tree-generator => transforms/rxjs-decision-tree-generator}/src/lib/flattenApiList.ts (100%) rename apps/rxjs.dev/tools/{decision-tree-generator => transforms/rxjs-decision-tree-generator}/src/lib/generateUniqueId.spec.ts (100%) rename apps/rxjs.dev/tools/{decision-tree-generator => transforms/rxjs-decision-tree-generator}/src/lib/generateUniqueId.ts (100%) rename apps/rxjs.dev/tools/{decision-tree-generator => transforms/rxjs-decision-tree-generator}/src/lib/helpers.spec.ts (100%) rename apps/rxjs.dev/tools/{decision-tree-generator => transforms/rxjs-decision-tree-generator}/src/lib/helpers.ts (97%) rename apps/rxjs.dev/tools/{decision-tree-generator => transforms/rxjs-decision-tree-generator}/src/lib/index.ts (100%) rename apps/rxjs.dev/tools/{decision-tree-generator => transforms/rxjs-decision-tree-generator}/src/lib/interfaces.ts (100%) diff --git a/apps/rxjs.dev/tools/decision-tree-generator/src/tree.yml b/apps/rxjs.dev/content/operator-decision-tree.yml similarity index 100% rename from apps/rxjs.dev/tools/decision-tree-generator/src/tree.yml rename to apps/rxjs.dev/content/operator-decision-tree.yml diff --git a/apps/rxjs.dev/package.json b/apps/rxjs.dev/package.json index 2cb7e1c337..69e1b32e18 100644 --- a/apps/rxjs.dev/package.json +++ b/apps/rxjs.dev/package.json @@ -23,11 +23,10 @@ "test-pwa-score": "node scripts/test-pwa-score", "deploy-production": "scripts/deploy-to-firebase.sh", "payload-size": "scripts/payload.sh", - "docs": "npx ts-node -P tsconfig.docs.json ../../node_modules/dgeni/lib/gen-docs.js ./tools/transforms/angular.io-package && yarn docs-decision-tree", + "docs": "npx ts-node -P tsconfig.docs.json ../../node_modules/dgeni/lib/gen-docs.js ./tools/transforms/angular.io-package", "docs-watch": "npx ts-node -P tsconfig.docs.json tools/transforms/authors-package/watchr.js", "docs-lint": "eslint --ignore-path=\"tools/transforms/.eslintignore\" tools/transforms", "docs-test": "npx ts-node -P tsconfig.docs.json tools/transforms/test.js", - "docs-decision-tree": "ts-node -P tools/decision-tree-generator/tsconfig.json tools/decision-tree-generator/main.ts", "firebase-utils-test": "jasmine-ts tools/firebase-test-utils/*.spec.ts", "tools-lint": "tslint -c \"tools/tslint.json\" \"tools/firebase-test-utils/**/*.ts\"", "tools-test": "./scripts/deploy-to-firebase.test.sh && yarn docs-test && yarn firebase-utils-test", @@ -74,7 +73,7 @@ "@types/jasmine": "~3.6.0", "@types/jasminewd2": "^2.0.3", "@types/lunr": "^2.3.3", - "@types/node": "^12.11.1", + "@types/node": "^20.6.3", "@types/svgo": "^1.3.3", "@typescript-eslint/eslint-plugin": "^6.9.0", "@typescript-eslint/parser": "^6.9.0", diff --git a/apps/rxjs.dev/tools/decision-tree-generator/jest.config.js b/apps/rxjs.dev/tools/decision-tree-generator/jest.config.js deleted file mode 100644 index 6d7b8ae45b..0000000000 --- a/apps/rxjs.dev/tools/decision-tree-generator/jest.config.js +++ /dev/null @@ -1,8 +0,0 @@ -module.exports = { - roots: ['/src'], - transform: { - '^.+\\.tsx?$': 'ts-jest', - }, - testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$', - moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], -}; diff --git a/apps/rxjs.dev/tools/decision-tree-generator/main.ts b/apps/rxjs.dev/tools/decision-tree-generator/main.ts deleted file mode 100644 index f5721679c4..0000000000 --- a/apps/rxjs.dev/tools/decision-tree-generator/main.ts +++ /dev/null @@ -1,28 +0,0 @@ -import chalk from 'chalk'; -import { readFileSync, writeFileSync } from 'fs'; -import { resolve } from 'path'; -import { parse } from 'yamljs'; -import { ApiListNode, build, flattenApiList, TreeNodeRaw } from './src/lib'; -const generatedBase = resolve(`${__dirname}/../../src/generated/docs`); -const outFilename = `${generatedBase}/app/decision-tree-data.json`; -const yamlContent = readFileSync(`${__dirname}/src/tree.yml`, 'utf8'); -const decisionTreeJson: TreeNodeRaw[] = parse(yamlContent); -let apiList: ApiListNode[]; - -try { - apiList = JSON.parse(readFileSync(`${generatedBase}/api/api-list.json`, 'utf8')); -} catch (error) { - console.log( - chalk.red('Decision Tree Generator - error:'), - 'Generating the decision tree requires the generated API list. Please run `yarn docs` and try again.' - ); -} - -try { - const flattenedApiList = flattenApiList(apiList); - const jsonContent = build(flattenedApiList, decisionTreeJson); - writeFileSync(outFilename, JSON.stringify(jsonContent), 'utf8'); - console.log(chalk.green('Decision Tree Generator - success:'), 'Finished generating decision tree'); -} catch (error) { - console.log(chalk.red('Decision Tree Generator - error:'), error.message); -} diff --git a/apps/rxjs.dev/tools/decision-tree-generator/package.json b/apps/rxjs.dev/tools/decision-tree-generator/package.json deleted file mode 100644 index 4870eef917..0000000000 --- a/apps/rxjs.dev/tools/decision-tree-generator/package.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "name": "decision-tree-generator", - "version": "2.0.1", - "description": "Interactive widget for a decision tree to assist choosing an RxJS operator", - "contributors": [ - { - "name": "Jason Awbrey", - "email": "jason.s.awbrey@gmail.com", - "url": "https://jason-awbrey.com" - } - ], - "scripts": { - "watch": "nodemon -e ts,yml --watch './**/*' --exec 'ts-node' main.ts", - "build": "ts-node main.ts", - "test": "jest", - "test:watch": "jest --watch -o", - "test:coverage": "jest --coverage", - "test:watch:coverage": "jest --watch -o --coverage" - }, - "devDependencies": { - "@types/jest": "^26.0.13", - "jest": "^26.4.2", - "nodemon": "^2.0.4", - "ts-jest": "^26.3.0", - "ts-node": "^7.0.1", - "typescript": "^3.9.7" - } -} diff --git a/apps/rxjs.dev/tools/decision-tree-generator/tsconfig.json b/apps/rxjs.dev/tools/decision-tree-generator/tsconfig.json deleted file mode 100644 index 38ff73e14f..0000000000 --- a/apps/rxjs.dev/tools/decision-tree-generator/tsconfig.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "compilerOptions": { - "module": "commonjs", - "esModuleInterop": true - } -} \ No newline at end of file diff --git a/apps/rxjs.dev/tools/transforms/angular.io-package/index.js b/apps/rxjs.dev/tools/transforms/angular.io-package/index.js index 10538749d5..d89ea38dbf 100644 --- a/apps/rxjs.dev/tools/transforms/angular.io-package/index.js +++ b/apps/rxjs.dev/tools/transforms/angular.io-package/index.js @@ -11,7 +11,7 @@ const apiPackage = require('../angular-api-package'); const contentPackage = require('../angular-content-package'); const { extname, resolve } = require('canonical-path'); const { existsSync } = require('fs'); -const { SRC_PATH } = require('../config'); +const { SRC_PATH, DOCS_OUTPUT_PATH, DECISION_TREE_PATH } = require('../config'); // prettier-ignore module.exports = new Package('angular.io', [gitPackage, apiPackage, contentPackage]) @@ -19,6 +19,7 @@ module.exports = new Package('angular.io', [gitPackage, apiPackage, contentPacka .processor(require('./processors/processNavigationMap')) .processor(require('./processors/createOverviewDump')) .processor(require('./processors/cleanGeneratedFiles')) + .processor(require('../rxjs-decision-tree-generator')) // We don't include this in the angular-base package because the `versionInfo` stuff // accesses the file system and git, which is slow. @@ -54,4 +55,8 @@ module.exports = new Package('angular.io', [gitPackage, apiPackage, contentPacka .config(function(renderLinkInfo, postProcessHtml) { renderLinkInfo.docTypes = postProcessHtml.docTypes; + }) + .config(function(decisionTreeGenerator) { + decisionTreeGenerator.outputFolder = DOCS_OUTPUT_PATH + '/app'; + decisionTreeGenerator.decisionTreeFile = DECISION_TREE_PATH; }); diff --git a/apps/rxjs.dev/tools/transforms/config.js b/apps/rxjs.dev/tools/transforms/config.js index 0ad1a9c9cc..2f80e44ac5 100644 --- a/apps/rxjs.dev/tools/transforms/config.js +++ b/apps/rxjs.dev/tools/transforms/config.js @@ -12,6 +12,7 @@ const DOCS_OUTPUT_PATH = resolve(OUTPUT_PATH, 'docs'); const API_SOURCE_PATH = resolve(PROJECT_ROOT, 'packages/rxjs/src'); const MARBLE_IMAGES_PATH = resolve(SRC_PATH, 'assets/images/marble-diagrams'); const MARBLE_IMAGES_WEB_PATH = 'assets/images/marble-diagrams'; +const DECISION_TREE_PATH = resolve(CONTENTS_PATH, 'operator-decision-tree.yml'); function requireFolder(dirname, folderPath) { const absolutePath = resolve(dirname, folderPath); @@ -32,5 +33,6 @@ module.exports = { API_SOURCE_PATH, MARBLE_IMAGES_PATH, MARBLE_IMAGES_WEB_PATH, + DECISION_TREE_PATH, requireFolder, }; diff --git a/apps/rxjs.dev/tools/decision-tree-generator/README.md b/apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/README.md similarity index 100% rename from apps/rxjs.dev/tools/decision-tree-generator/README.md rename to apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/README.md diff --git a/apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/index.ts b/apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/index.ts new file mode 100644 index 0000000000..9ffa81b2a2 --- /dev/null +++ b/apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/index.ts @@ -0,0 +1,37 @@ +import { readFile } from 'fs/promises'; +import { parse } from 'yamljs'; + +import { TreeNodeRaw, build, flattenApiList } from './src/lib'; + +module.exports = function decisionTreeGenerator(log: { warn: (message: string) => void }) { + return { + $runBefore: ['rendering-docs'], + $runAfter: ['generateApiListDoc'], + $validate: { + decisionTreeFile: { presence: true }, + outputFolder: { presence: true }, + }, + $process: async function (this: any, docs: any[]) { + const apiListDoc = docs.find((doc) => doc.docType === 'api-list-data'); + + if (!apiListDoc) { + throw new Error('Can not find api-list-data for decision tree generation'); + } + + const yamlContent = await readFile(this.decisionTreeFile, { encoding: 'utf8' }); + const decisionTreeJson: TreeNodeRaw[] = parse(yamlContent); + + const flattenedApiList = flattenApiList(apiListDoc.data); + const jsonContent = build(flattenedApiList, decisionTreeJson, log); + + docs.push({ + docType: 'decision-tree-data', + template: 'json-doc.template.json', + path: this.outputFolder + '/decision-tree-data.json', + outputPath: this.outputFolder + '/decision-tree-data.json', + data: jsonContent, + }); + return docs; + }, + }; +}; diff --git a/apps/rxjs.dev/tools/decision-tree-generator/src/lib/addUniqueId.spec.ts b/apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/addUniqueId.spec.ts similarity index 59% rename from apps/rxjs.dev/tools/decision-tree-generator/src/lib/addUniqueId.spec.ts rename to apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/addUniqueId.spec.ts index a16af54a69..3d2cdb4c13 100644 --- a/apps/rxjs.dev/tools/decision-tree-generator/src/lib/addUniqueId.spec.ts +++ b/apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/addUniqueId.spec.ts @@ -5,33 +5,34 @@ import { mockRawTreeNodes } from './fixtures'; describe('addUniqueId', () => { describe('when called with three raw nodes', () => { let tree: TreeNode[]; - let baseProperties: jest.Expect; + const baseProperties = jasmine.objectContaining({ + id: jasmine.any(String), + label: jasmine.any(String), + depth: jasmine.any(Number), + }); beforeEach(() => { tree = addUniqueId(mockRawTreeNodes); - baseProperties = expect.objectContaining({ - id: expect.any(String), - label: expect.any(String), - depth: expect.any(Number), - }); }); describe('and one of the nodes is a child of another', () => { it('should not flatten the tree and return the same number of top level nodes', () => { - expect(tree).toHaveLength(mockRawTreeNodes.length); + expect(tree.length).toBe(mockRawTreeNodes.length); }); it('should return an array of tree nodes that have unique ids', () => { - tree.forEach(node => { + tree.forEach((node) => { expect(node).toEqual(baseProperties); if (!node.children) { - expect(node).not.toHaveProperty('options'); + expect(node.options).toBeUndefined(); } else { - expect(node).toEqual(expect.objectContaining({ - children: expect.any(Array), - options: expect.any(Array), - })); - node.children.forEach(child => { + expect(node).toEqual( + jasmine.objectContaining({ + children: jasmine.any(Array), + options: jasmine.any(Array), + }) + ); + node.children.forEach((child) => { expect(child).toEqual(baseProperties); }); } diff --git a/apps/rxjs.dev/tools/decision-tree-generator/src/lib/addUniqueId.ts b/apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/addUniqueId.ts similarity index 100% rename from apps/rxjs.dev/tools/decision-tree-generator/src/lib/addUniqueId.ts rename to apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/addUniqueId.ts diff --git a/apps/rxjs.dev/tools/decision-tree-generator/src/lib/build.spec.ts b/apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/build.spec.ts similarity index 75% rename from apps/rxjs.dev/tools/decision-tree-generator/src/lib/build.spec.ts rename to apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/build.spec.ts index 279e73e665..5a994515d3 100644 --- a/apps/rxjs.dev/tools/decision-tree-generator/src/lib/build.spec.ts +++ b/apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/build.spec.ts @@ -3,9 +3,9 @@ import { mockFlatApiList, mockRawTreeNodes } from './fixtures'; import { treeNodeCount } from './helpers'; describe('build', () => { - const tree = build(mockFlatApiList, mockRawTreeNodes); + const tree = build(mockFlatApiList, mockRawTreeNodes, {warn: () => {}}); it('should return a flat map of all nodes and one additional initial node', () => { - expect(tree).toHaveProperty('initial'); + expect(tree.initial).toBeDefined() expect(Object.keys(tree).length).toBe(treeNodeCount(mockRawTreeNodes) + 1); }); }); diff --git a/apps/rxjs.dev/tools/decision-tree-generator/src/lib/build.ts b/apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/build.ts similarity index 80% rename from apps/rxjs.dev/tools/decision-tree-generator/src/lib/build.ts rename to apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/build.ts index f1ff62d35f..9e656fb976 100644 --- a/apps/rxjs.dev/tools/decision-tree-generator/src/lib/build.ts +++ b/apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/build.ts @@ -14,12 +14,12 @@ import { decisionTreeReducer } from './decisionTreeReducer'; * @requires decisionTreeReducer * @returns {DecisionTree} */ -export function build(apiList: FlattenedApiList, tree: TreeNodeRaw[]): DecisionTree { +export function build(apiList: FlattenedApiList, tree: TreeNodeRaw[], log: { warn: (message: string) => void }): DecisionTree { const nodesWithUniqueIds = addUniqueId(tree); const initialOption = extractInitialSequence(nodesWithUniqueIds); return { - ...decisionTreeReducer(nodesWithUniqueIds, apiList), - [initialOption.id]: { ...initialOption } + ...decisionTreeReducer(nodesWithUniqueIds, apiList, log), + [initialOption.id]: { ...initialOption }, }; } diff --git a/apps/rxjs.dev/tools/decision-tree-generator/src/lib/decisionTreeReducer.spec.ts b/apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/decisionTreeReducer.spec.ts similarity index 67% rename from apps/rxjs.dev/tools/decision-tree-generator/src/lib/decisionTreeReducer.spec.ts rename to apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/decisionTreeReducer.spec.ts index e654595b0b..c312ba8b89 100644 --- a/apps/rxjs.dev/tools/decision-tree-generator/src/lib/decisionTreeReducer.spec.ts +++ b/apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/decisionTreeReducer.spec.ts @@ -4,11 +4,11 @@ import { addUniqueId } from './addUniqueId'; import { rawNodesWithMethodCount } from './helpers'; describe('decisionTreeReducer', () => { - const tree = decisionTreeReducer(addUniqueId(mockRawTreeNodes), mockFlatApiList); + const tree = decisionTreeReducer(addUniqueId(mockRawTreeNodes), mockFlatApiList, { warn: jasmine.createSpy() }); describe('all nodes', () => { - const baseProperties = expect.objectContaining({ - id: expect.any(String), - label: expect.any(String) + const baseProperties = jasmine.objectContaining({ + id: jasmine.any(String), + label: jasmine.any(String), }); it('should have base properties', () => { @@ -22,11 +22,8 @@ describe('decisionTreeReducer', () => { describe('that have options', () => { it('should have an options property that is an array of strings', () => { for (const key in tree) { - if ( - tree.hasOwnProperty(key) && - tree[key].options - ) { - tree[key].options.forEach(option => { + if (tree.hasOwnProperty(key) && tree[key].options) { + tree[key].options?.forEach((option) => { expect(typeof option).toBe('string'); }); } @@ -37,22 +34,16 @@ describe('decisionTreeReducer', () => { describe('when a node does not have options', () => { it('should not have an options property', () => { for (const key in tree) { - if ( - tree.hasOwnProperty(key) && - !tree[key].options - ) { - expect(tree[key]).not.toHaveProperty('options'); + if (tree.hasOwnProperty(key) && !tree[key].options) { + expect(tree[key].options).toBeUndefined(); } } }); it('should have a docType and a path', () => { for (const key in tree) { - if ( - tree.hasOwnProperty(key) && - !tree[key].options - ) { - expect(tree[key]).toHaveProperty('docType'); - expect(tree[key]).toHaveProperty('path'); + if (tree.hasOwnProperty(key) && !tree[key].options) { + expect(tree[key].docType).toBeDefined(); + expect(tree[key].path).toBeDefined(); } } }); @@ -61,12 +52,12 @@ describe('decisionTreeReducer', () => { const treeNodesMissingInApiList = [ ...mockRawTreeNodes, { - label: 'foo' - } + label: 'foo', + }, ]; it('should call a console.log', () => { - const spy = jest.spyOn(console, 'log'); - decisionTreeReducer(addUniqueId(treeNodesMissingInApiList), mockFlatApiList); + const spy = jasmine.createSpy('warn'); + decisionTreeReducer(addUniqueId(treeNodesMissingInApiList), mockFlatApiList, { warn: spy }); expect(spy).toHaveBeenCalled(); }); }); @@ -77,10 +68,7 @@ describe('decisionTreeReducer', () => { it('should have a method property', () => { let count = 0; for (const key in tree) { - if ( - tree.hasOwnProperty(key) && - tree[key].method - ) { + if (tree.hasOwnProperty(key) && tree[key].method) { count++; } } diff --git a/apps/rxjs.dev/tools/decision-tree-generator/src/lib/decisionTreeReducer.ts b/apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/decisionTreeReducer.ts similarity index 60% rename from apps/rxjs.dev/tools/decision-tree-generator/src/lib/decisionTreeReducer.ts rename to apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/decisionTreeReducer.ts index d6d201172d..f57ec7d2e8 100644 --- a/apps/rxjs.dev/tools/decision-tree-generator/src/lib/decisionTreeReducer.ts +++ b/apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/decisionTreeReducer.ts @@ -1,10 +1,4 @@ -import chalk from 'chalk'; -import { - DecisionTree, - FlattenedApiList, - FlattenedApiNode, - TreeNode -} from './interfaces'; +import { DecisionTree, FlattenedApiList, FlattenedApiNode, TreeNode } from './interfaces'; /** * Recursively walks the tree and pulls relevant information from the API list. @@ -15,39 +9,33 @@ import { * @param {FlattenedApiList} apiList * @returns {DecisionTree} */ -export function decisionTreeReducer( - tree: TreeNode[], - apiList: FlattenedApiList -): DecisionTree { +export function decisionTreeReducer(tree: TreeNode[], apiList: FlattenedApiList, log: { warn: (message: string) => void }): DecisionTree { return tree.reduce((acc, curr) => { let nested; let treeNode: TreeNode = { // there might not be options, grab what we know is available id: curr.id, - label: curr.label + label: curr.label, }; if (curr.options) { // we are still deciding treeNode = { ...treeNode, - options: curr.options + options: curr.options, }; } if (!curr.options) { // we found the function/operator we want to use - const apiNode: FlattenedApiNode = apiList[treeNode.label]; + const apiNode: FlattenedApiNode = apiList[treeNode.label!]; if (!apiNode) { - console.log( - chalk.yellow('Decision Tree Generator - (reducer) - warning:'), - `Label does not exist in API List: ${treeNode.label}` - ); + log.warn(`Decision Tree Generator - (reducer) - warning: Label does not exist in API List: ${treeNode.label}`); } treeNode = { ...treeNode, - ...apiNode // helps to build uri, used in Angular template + ...apiNode, // helps to build uri, used in Angular template }; } @@ -55,19 +43,19 @@ export function decisionTreeReducer( // if we need to point at a method of a class, like Observable.create, helps to build uri treeNode = { ...treeNode, - method: curr.method + method: curr.method, }; } if (curr.children) { // there are children of the current node, recursively walk the paths to continue building the decision tree data - nested = decisionTreeReducer(curr.children, apiList); + nested = decisionTreeReducer(curr.children, apiList, log); } return { ...acc, ...nested, - [treeNode.id]: treeNode + [treeNode.id]: treeNode, }; }, {}); } diff --git a/apps/rxjs.dev/tools/decision-tree-generator/src/lib/extractInitialSequence.spec.ts b/apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/extractInitialSequence.spec.ts similarity index 79% rename from apps/rxjs.dev/tools/decision-tree-generator/src/lib/extractInitialSequence.spec.ts rename to apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/extractInitialSequence.spec.ts index c35eeccdfe..29c943298a 100644 --- a/apps/rxjs.dev/tools/decision-tree-generator/src/lib/extractInitialSequence.spec.ts +++ b/apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/extractInitialSequence.spec.ts @@ -8,14 +8,14 @@ const initialSequence = extractInitialSequence(tree); describe('extractInitialSequence', () => { describe('when given a tree that has passed through addUniqueId', () => { it('will return an object that has an id of initial', () => { - expect(initialSequence).toMatchObject({ + expect(initialSequence).toEqual({ id: 'initial', - options: expect.any(Array) + options: jasmine.any(Array) }); }); it('it will return a number of options equal to the length of the original tree', () => { - expect(initialSequence.options).toHaveLength(mockRawTreeNodes.length); + expect(initialSequence.options.length).toBe(mockRawTreeNodes.length); }); }); }); diff --git a/apps/rxjs.dev/tools/decision-tree-generator/src/lib/extractInitialSequence.ts b/apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/extractInitialSequence.ts similarity index 100% rename from apps/rxjs.dev/tools/decision-tree-generator/src/lib/extractInitialSequence.ts rename to apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/extractInitialSequence.ts diff --git a/apps/rxjs.dev/tools/decision-tree-generator/src/lib/fixtures.ts b/apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/fixtures.ts similarity index 100% rename from apps/rxjs.dev/tools/decision-tree-generator/src/lib/fixtures.ts rename to apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/fixtures.ts diff --git a/apps/rxjs.dev/tools/decision-tree-generator/src/lib/flattenApiList.spec.ts b/apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/flattenApiList.spec.ts similarity index 87% rename from apps/rxjs.dev/tools/decision-tree-generator/src/lib/flattenApiList.spec.ts rename to apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/flattenApiList.spec.ts index 10065ea8c1..db7f0c8baa 100644 --- a/apps/rxjs.dev/tools/decision-tree-generator/src/lib/flattenApiList.spec.ts +++ b/apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/flattenApiList.spec.ts @@ -7,7 +7,7 @@ describe('flattenApiList', () => { const flattenedApiList = flattenApiList(mockRawApiListWithDeprecatedRefs); const validRefCount = validApiRefCount(mockRawApiListWithDeprecatedRefs); it('should return a flat list with only stable refs', () => { - expect(Object.keys(flattenedApiList)).toHaveLength(validRefCount); + expect(Object.keys(flattenedApiList).length).toBe(validRefCount); }); }); }); diff --git a/apps/rxjs.dev/tools/decision-tree-generator/src/lib/flattenApiList.ts b/apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/flattenApiList.ts similarity index 100% rename from apps/rxjs.dev/tools/decision-tree-generator/src/lib/flattenApiList.ts rename to apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/flattenApiList.ts diff --git a/apps/rxjs.dev/tools/decision-tree-generator/src/lib/generateUniqueId.spec.ts b/apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/generateUniqueId.spec.ts similarity index 100% rename from apps/rxjs.dev/tools/decision-tree-generator/src/lib/generateUniqueId.spec.ts rename to apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/generateUniqueId.spec.ts diff --git a/apps/rxjs.dev/tools/decision-tree-generator/src/lib/generateUniqueId.ts b/apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/generateUniqueId.ts similarity index 100% rename from apps/rxjs.dev/tools/decision-tree-generator/src/lib/generateUniqueId.ts rename to apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/generateUniqueId.ts diff --git a/apps/rxjs.dev/tools/decision-tree-generator/src/lib/helpers.spec.ts b/apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/helpers.spec.ts similarity index 100% rename from apps/rxjs.dev/tools/decision-tree-generator/src/lib/helpers.spec.ts rename to apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/helpers.spec.ts diff --git a/apps/rxjs.dev/tools/decision-tree-generator/src/lib/helpers.ts b/apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/helpers.ts similarity index 97% rename from apps/rxjs.dev/tools/decision-tree-generator/src/lib/helpers.ts rename to apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/helpers.ts index b79251611d..19f686ed90 100644 --- a/apps/rxjs.dev/tools/decision-tree-generator/src/lib/helpers.ts +++ b/apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/helpers.ts @@ -41,7 +41,7 @@ export function treeNodeCount(tree) { */ export function rawNodesWithMethodCount(tree) { return tree.filter(node => { - let childHadMethod: boolean; + let childHadMethod = false; if (node.method) { return node; diff --git a/apps/rxjs.dev/tools/decision-tree-generator/src/lib/index.ts b/apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/index.ts similarity index 100% rename from apps/rxjs.dev/tools/decision-tree-generator/src/lib/index.ts rename to apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/index.ts diff --git a/apps/rxjs.dev/tools/decision-tree-generator/src/lib/interfaces.ts b/apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/interfaces.ts similarity index 100% rename from apps/rxjs.dev/tools/decision-tree-generator/src/lib/interfaces.ts rename to apps/rxjs.dev/tools/transforms/rxjs-decision-tree-generator/src/lib/interfaces.ts diff --git a/apps/rxjs.dev/tools/transforms/test.js b/apps/rxjs.dev/tools/transforms/test.js index 48967ddd45..5de1cb6714 100644 --- a/apps/rxjs.dev/tools/transforms/test.js +++ b/apps/rxjs.dev/tools/transforms/test.js @@ -13,5 +13,5 @@ const Jasmine = require('jasmine'); const jasmine = new Jasmine({ projectBaseDir: __dirname }); -jasmine.loadConfig({ spec_files: ['**/*.spec.js'] }); +jasmine.loadConfig({ spec_files: ['**/*.spec.{js,ts}'] }); jasmine.execute(); diff --git a/yarn.lock b/yarn.lock index cceef373ea..d907388fcc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2645,16 +2645,18 @@ dependencies: undici-types "~5.26.4" -"@types/node@^12.11.1": - version "12.20.55" - resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.55.tgz#c329cbd434c42164f846b909bd6f85b5537f6240" - integrity sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ== - "@types/node@^14.14.6": version "14.18.63" resolved "https://registry.yarnpkg.com/@types/node/-/node-14.18.63.tgz#1788fa8da838dbb5f9ea994b834278205db6ca2b" integrity sha512-fAtCfv4jJg+ExtXhvCkCqUKZ+4ok/JQk01qDKhL5BDDoS3AxKXhV5/MAVUZyQnSEd2GT92fkgZl0pz0Q0AzcIQ== +"@types/node@^20.6.3": + version "20.8.8" + resolved "https://registry.yarnpkg.com/@types/node/-/node-20.8.8.tgz#adee050b422061ad5255fc38ff71b2bb96ea2a0e" + integrity sha512-YRsdVxq6OaLfmR9Hy816IMp33xOBjfyOgUd77ehqg96CFywxAPbDbXvAsuN2KVg2HOT8Eh6uAfU+l4WffwPVrQ== + dependencies: + undici-types "~5.25.1" + "@types/parse-json@^4.0.0": version "4.0.2" resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.2.tgz#5950e50960793055845e956c427fc2b0d70c5239" @@ -15414,6 +15416,11 @@ undefsafe@^2.0.2: resolved "https://registry.yarnpkg.com/undefsafe/-/undefsafe-2.0.5.tgz#38733b9327bdcd226db889fb723a6efd162e6e2c" integrity sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA== +undici-types@~5.25.1: + version "5.25.3" + resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.25.3.tgz#e044115914c85f0bcbb229f346ab739f064998c3" + integrity sha512-Ga1jfYwRn7+cP9v8auvEXN1rX3sWqlayd4HP7OKk4mZWylEmu3KzXDUGrQUN6Ol7qo1gPvB2e5gX6udnyEPgdA== + undici-types@~5.26.4: version "5.26.5" resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617"