Skip to content

Commit

Permalink
#61, printing the Map interfaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajvincent committed Mar 22, 2024
1 parent bef3d12 commit 4288674
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 197 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"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",
"debug-use-cases": "TSMS_STAGE='use-cases' TSMS_DEBUG='use-cases' node --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
135 changes: 0 additions & 135 deletions stage_3_snapshot/spec-snapshot/use-cases/StringStringMap.ts

This file was deleted.

19 changes: 17 additions & 2 deletions use-cases/build/StringStringMap.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import path from "path";

import {
type InterfaceDeclaration,
type SourceFile,
} from "ts-morph";

import {
distDir,
project,
removeDistFile,
//getExistingSourceFile,
} from "./sharedProject.js";
import { SourceFile } from "ts-morph";
} from "./utilities/sharedProject.js";

import getTypeScriptNodes from "./utilities/typescript-builtins.js";

export default async function buildStringStringMap(): Promise<void>
{
Expand Down Expand Up @@ -40,6 +47,14 @@ export default class StringStringMap<V> {
`.trim()
);

/* What are we dealing with? */
const MapInterfaceNodes = getTypeScriptNodes<InterfaceDeclaration>(
sourceFile => sourceFile.getInterfaces().filter(ifc => ifc.getName() === "Map")
).map(entry => entry[1]);
for (const node of MapInterfaceNodes) {
console.log(node.print());
}

await moduleFile.save();
return Promise.resolve();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import url from "url";
import {
ModuleKind,
ModuleResolutionKind,
type Node,
Project,
type ProjectOptions,
ScriptTarget,
type Structures,
SourceFile,
} from "ts-morph";

Expand All @@ -24,8 +26,13 @@ const TSC_CONFIG: ProjectOptions = {
skipFileDependencyResolution: true,
};

export const stageDir = path.normalize(path.join(url.fileURLToPath(import.meta.url), "../../"));
export interface NodeWithStructures extends Node {
getStructure(): Structures;
}

export const stageDir = path.normalize(path.join(url.fileURLToPath(import.meta.url), "../../../"));
export const distDir = path.join(stageDir, "dist");
export const projectDir = path.dirname(stageDir);

export const project = new Project(TSC_CONFIG);

Expand All @@ -46,3 +53,4 @@ export function getExistingSourceFile(
{
return project.getSourceFile(absolutePathToFile) ?? project.addSourceFileAtPath(absolutePathToFile);
}

41 changes: 41 additions & 0 deletions use-cases/build/utilities/typescript-builtins.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import fs from "fs/promises";
import path from "path";

import {
type SourceFile
} from "ts-morph";

import {
NodeWithStructures,
project,
projectDir,
} from "./sharedProject.js";

const TYPESCRIPT_LIBS = path.join(projectDir, "node_modules/typescript/lib");
const fileNames = (await fs.readdir(TYPESCRIPT_LIBS)).filter(f => /^lib\..*\.d.ts$/.test(f)).map(f => path.join(TYPESCRIPT_LIBS, f));
const sourceFiles: readonly SourceFile[] = project.addSourceFilesAtPaths(fileNames);

export default function getTypeScriptNodes<
NodeKind extends NodeWithStructures
>
(
callback: (sourceFile: SourceFile) => NodeKind[]
): [string, NodeKind][]
{
return sourceFiles.map(
sourceFile => processSourceFile(sourceFile, callback)
).flat();
}

function processSourceFile<
NodeKind extends NodeWithStructures
>
(
sourceFile: SourceFile,
callback: (sourceFile: SourceFile) => NodeKind[]
): [string, NodeKind][]
{
const nodes = callback(sourceFile);
const pathToSourceFile = sourceFile.getFilePath();
return nodes.map(node => [pathToSourceFile, node]);
}
58 changes: 0 additions & 58 deletions utilities/source/typescript-builtins.ts

This file was deleted.

0 comments on commit 4288674

Please sign in to comment.