From ce71212bd7ef6c898207dd54535e4d455c382bca Mon Sep 17 00:00:00 2001 From: "Alexander J. Vincent" Date: Thu, 21 Mar 2024 20:19:24 -0700 Subject: [PATCH] #61, start an use-cases "stage" for demonstrations. --- .github/workflows/build.use-cases.yml | 20 +++++++++ build.ts | 13 ++++++ package.json | 2 + use-cases/.eslintrc.json | 64 +++++++++++++++++++++++++++ use-cases/README.md | 7 +++ use-cases/build/StringStringMap.ts | 5 +++ use-cases/buildStage.ts | 42 ++++++++++++++++++ 7 files changed, 153 insertions(+) create mode 100644 .github/workflows/build.use-cases.yml create mode 100644 use-cases/.eslintrc.json create mode 100644 use-cases/README.md create mode 100644 use-cases/build/StringStringMap.ts create mode 100644 use-cases/buildStage.ts diff --git a/.github/workflows/build.use-cases.yml b/.github/workflows/build.use-cases.yml new file mode 100644 index 0000000..e0d290a --- /dev/null +++ b/.github/workflows/build.use-cases.yml @@ -0,0 +1,20 @@ +name: build-stage-two +on: + push: + paths: + - '*' + - '.github/workflows/**' + - 'stage_2_snapshot/snapshot/source/**' + - 'use-cases/**' +jobs: + build-stage-two: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: '20.x' + - run: npm ci + - run: npm run use-cases + timeout-minutes: 5 + - run: npm run is-repo-clean diff --git a/build.ts b/build.ts index 2173031..45ace4c 100644 --- a/build.ts +++ b/build.ts @@ -109,6 +109,16 @@ const BPSet = new BuildPromiseSet; } // #endregion stage 3 +// use cases +{ + const target = BPSet.get("use-cases"); + target.addTask(async (): Promise => { + console.log("starting use cases"); + await recursiveBuild("use-cases", "buildStage.ts"); + console.log("completed use cases"); + }); +} + BPSet.markReady(); { if ((env.TSMS_STAGE === undefined) || (env.TSMS_STAGE === "one")) { @@ -122,5 +132,8 @@ BPSet.markReady(); if ((env.TSMS_STAGE === undefined) || (env.TSMS_STAGE === "three")) { BPSet.main.addSubtarget("stage 3"); } + if ((env.TSMS_STAGE === undefined) || (env.TSMS_STAGE === "use-cases")) { + BPSet.main.addSubtarget("use-cases"); + } } await BPSet.main.run(); diff --git a/package.json b/package.json index 03cc1ff..ef812c7 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,8 @@ "debug-stage-three-generation-test": "TSMS_STAGE='three' TSMS_DEBUG='stage_three_generation_test' node --import ./register-hooks.js ./build.ts", "debug-stage-three-integration": "TSMS_STAGE='three' TSMS_DEBUG='stage_3_integration' node --import ./register-hooks.js ./build.ts", "debug-stage-three-test": "TSMS_STAGE='three' TSMS_DEBUG='stage_three_test' node --import ./register-hooks.js ./build.ts", + "use-cases": "TSMS_STAGE='use-cases' node --import ./register-hooks.js ./build.ts", + "debug-use-cases": "TSMS_STAGE='use-cases' TSMS_DEBUG='use-cases' --import ./register-hooks.js ./build.ts", "tsc-tasks": "tsc --project ./utilities/source/tasks/tsconfig.json", "postinstall": "patch-package", "is-repo-clean": "node --import ./register-hooks.js ./utilities/source/assertRepoIsClean.ts" diff --git a/use-cases/.eslintrc.json b/use-cases/.eslintrc.json new file mode 100644 index 0000000..3b5e9f2 --- /dev/null +++ b/use-cases/.eslintrc.json @@ -0,0 +1,64 @@ +{ + "env": { + "es2021": true, + "jasmine": true, + "node": true + }, + "extends": [ + "eslint:recommended", + "plugin:import/recommended", + "plugin:import/typescript", + "plugin:@typescript-eslint/eslint-recommended", + "plugin:@typescript-eslint/recommended", + "plugin:@typescript-eslint/recommended-type-checked", + "plugin:@typescript-eslint/stylistic-type-checked" + ], + + "overrides": [ + { + "files": [ + "**/*.ts" + ] + } + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": 2022, + "sourceType": "module", + "tsconfigRootDir": ".", + "project": true + }, + "plugins": [ + "@typescript-eslint", + "eslint-plugin-tsdoc", + "import" + ], + "root": true, + "rules": { + "@typescript-eslint/ban-types": [ + "error", + { + "types": { + "Function": false + } + } + ], + "@typescript-eslint/consistent-type-definitions": "off", + "@typescript-eslint/explicit-function-return-type": ["error"], + "tsdoc/syntax": "warn" + }, + "settings": { + "import/parsers": { + "@typescript-eslint/parser": [".ts"] + }, + "import/resolver": { + "typescript": { + "alwaysTryTypes": true, // always try to resolve types under `@types` directory even it doesn't contain any source code, like `@types/unist` + + // Choose from one of the "project" configs below or omit to use /tsconfig.json by default + + "project": "_*/tsconfig.json" + } + } + } +} diff --git a/use-cases/README.md b/use-cases/README.md new file mode 100644 index 0000000..05636f6 --- /dev/null +++ b/use-cases/README.md @@ -0,0 +1,7 @@ +# Use cases + +The files in this directory are demonstrations of `ts-morph-structures` and `ts-morph` in action. These are not test cases. The formal testing is over at this point. + +Instead, I'm going to focus on how to use these libraries to generate TypeScript code. + +As a result, you'll see a lot of console logging when you run this "stage". You'll also see greater numbers of code comments than usual (or at least, I hope so). diff --git a/use-cases/build/StringStringMap.ts b/use-cases/build/StringStringMap.ts new file mode 100644 index 0000000..6fb99b6 --- /dev/null +++ b/use-cases/build/StringStringMap.ts @@ -0,0 +1,5 @@ +export default function buildStringStringMap(): Promise +{ + console.log("Hello World!"); + return Promise.resolve(); +} diff --git a/use-cases/buildStage.ts b/use-cases/buildStage.ts new file mode 100644 index 0000000..bed6563 --- /dev/null +++ b/use-cases/buildStage.ts @@ -0,0 +1,42 @@ +import { BuildPromiseSet } from "#utilities/source/BuildPromise.js"; +import { runModule } from "#utilities/source/runModule.js"; + +import buildStringStringMap from "./build/StringStringMap.js"; + +const BPSet = new BuildPromiseSet; + +{ // eslint + const target = BPSet.get("eslint"); + + const args = [ + "-c", "./.eslintrc.json", + "--max-warnings=0", + ]; + + args.push("buildStage.ts"); + args.push("build/**/*.ts"); + + target.addTask(async () => { + console.log("starting use cases:eslint"); + await runModule("../node_modules/eslint/bin/eslint.js", args); + }); +} + +{ // use cases + const target = BPSet.get("use cases"); + target.addTask(async () => { + /* Do not use Promise.all() here or PromiseAllParallel, PromiseAllSequence. + The intent of these modules is demonstration of ts-morph-structures, not efficiency or speed. + */ + await buildStringStringMap(); + }); +} + +BPSet.markReady(); +{ + BPSet.main.addSubtarget("use cases"); + BPSet.main.addSubtarget("eslint"); +} +await BPSet.main.run(); + +export default Promise.resolve();