Skip to content

Commit

Permalink
#61, start an use-cases "stage" for demonstrations.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajvincent committed Mar 22, 2024
1 parent cc2c501 commit ce71212
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/build.use-cases.yml
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ const BPSet = new BuildPromiseSet;
}
// #endregion stage 3

// use cases
{
const target = BPSet.get("use-cases");
target.addTask(async (): Promise<void> => {
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")) {
Expand All @@ -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();
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
64 changes: 64 additions & 0 deletions use-cases/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -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 `<root>@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 <root>/tsconfig.json by default

"project": "_*/tsconfig.json"
}
}
}
}
7 changes: 7 additions & 0 deletions use-cases/README.md
Original file line number Diff line number Diff line change
@@ -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).
5 changes: 5 additions & 0 deletions use-cases/build/StringStringMap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default function buildStringStringMap(): Promise<void>
{
console.log("Hello World!");
return Promise.resolve();
}
42 changes: 42 additions & 0 deletions use-cases/buildStage.ts
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit ce71212

Please sign in to comment.