Skip to content

Commit

Permalink
refactor(tools-forecast-codegen): Redesigned Forecast plugin architec…
Browse files Browse the repository at this point in the history
…ture
  • Loading branch information
sullivanpj committed Sep 29, 2023
1 parent b4c89d3 commit d994538
Show file tree
Hide file tree
Showing 81 changed files with 3,986 additions and 618 deletions.
4 changes: 2 additions & 2 deletions libs/contact/typescript/server/attachment/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@
}
},
"generate": {
"executor": "@stormstack/tools-executors-typescript:storm-generate",
"executor": "@stormstack/tools-nx-forecast:generate",
"options": {
"outputPath": "libs/contact/typescript/server/attachment/src/__generated__",
"schema": "schema.storm",
"schema": "schema.4cast",
"packageManager": "pnpm",
"dependencyCheck": true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,9 @@ generator js {
output = "../../../../../../node_modules/@prisma/client/contact-attachment"
}

plugin prisma {
provider = "@core/prisma"
}

plugin meta {
provider = "@core/model-meta"
output = "src/__generated__/model-meta"
compile = false
}

plugin access {
provider = "@core/access-policy"
output = "src/__generated__/access-policy"
compile = false
}

plugin zod {
provider = "@plugins/zod"
output = "src/__generated__/zod"
compile = false
}

plugin drizzle {
provider = "@plugins/drizzle"
output = "src/__generated__/drizzle"
compile = false
}

plugin graphql {
provider = "@plugins/graphql"
output = "src/__generated__/graphql"
plugin crud {
provider = "@stormstack/tools-forecast-plugins-crud"
output = "src/__generated__/crud"
compile = false
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { MissingContextError } from "@stormstack/core-shared-utilities";
import { AsyncLocalStorage } from "node:async_hooks";

const asyncLocalStorage = new AsyncLocalStorage<AsyncScope>();

export class AsyncScope {
static get() {
const scope = asyncLocalStorage.getStore();
if (!scope) {
throw new MissingContextError("GlobalContextStore");
}

return scope;
}

constructor(callback: () => void) {
const parentScope = asyncLocalStorage.getStore();
if (parentScope) {
Object.setPrototypeOf(this, parentScope);
}

asyncLocalStorage.run(this, callback);
}
}
2 changes: 1 addition & 1 deletion libs/core/typescript/server/utilities/src/exists.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { existsSync } from "fs";
import { existsSync } from "node:fs";

export const exists = (filePath: string): boolean => {
return existsSync(filePath);
Expand Down
18 changes: 13 additions & 5 deletions libs/core/typescript/server/utilities/src/file-path-fns.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Path from "path";
import Path, { dirname, isAbsolute, join } from "path";

export const findFileName = (filePath: string): string => {
export function findFileName(filePath: string): string {
return (
filePath
?.split(
Expand All @@ -12,8 +12,16 @@ export const findFileName = (filePath: string): string => {
)
?.pop() ?? ""
);
};
}

export const findFilePath = (filePath: string): string => {
export function findFilePath(filePath: string): string {
return filePath.replace(findFileName(filePath), "");
};
}

export function resolvePath(filePath: string, basePath?: string) {
if (isAbsolute(filePath)) {
return filePath;
} else {
return join(dirname(basePath), filePath);
}
}
4 changes: 2 additions & 2 deletions libs/core/typescript/shared/logging/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "@stormstack/core-shared-logging",
"version": "0.0.1",
"type": "module",
"dependencies": {
"chalk": "4.1.0",
"ora": "^7.0.1"
"chalk": "4.1.0"
},
"devDependencies": {
"@types/jest": "29.5.3"
Expand Down
3 changes: 2 additions & 1 deletion libs/core/typescript/shared/logging/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"bundle": true,
"metafile": true,
"minify": true,
"format": ["esm", "cjs"]
"format": ["esm", "cjs"],
"thirdParty": true
}
},
"lint": {
Expand Down
35 changes: 0 additions & 35 deletions libs/core/typescript/shared/logging/src/console/console-logger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-empty-function */
import { Provider } from "@stormstack/core-shared-injection/decorators";
import ora from "ora";
import { formatLog } from "../format";
import { Logger } from "../logger";
import {
Expand All @@ -13,7 +12,6 @@ import {
printWarning,
startGroup
} from "./print";
import { ConsoleSpinner } from "./types";

@Provider(Logger)
export class ConsoleLogger extends Logger {
Expand Down Expand Up @@ -109,39 +107,6 @@ export class ConsoleLogger extends Logger {
endGroup();
}

/**
* The function returns a ConsoleSpinner object, which is created using the ora library and takes an
* optional text parameter.
* @param {string} [text] - The `text` parameter is an optional string that represents the text to be
* displayed alongside the spinner.
* @returns an instance of the `ConsoleSpinner` class.
*/
static spinner(text?: string): ConsoleSpinner {
return ora(text);
}

/**
* The function `spinnerStart` returns a ConsoleSpinner object that starts a spinner animation with an
* optional text.
* @param {string} [text] - The `text` parameter is an optional string that represents the text to be
* displayed alongside the spinner. It is used to provide additional context or information to the user
* while the spinner is running. If no `text` is provided, the spinner will be displayed without any
* accompanying text.
* @returns a ConsoleSpinner object.
*/
static spinnerStart(text?: string): ConsoleSpinner {
return ConsoleLogger.spinner(text).start();
}

/**
* The function stops a console spinner and returns the stopped spinner.
* @param {ConsoleSpinner} spinner - The parameter "spinner" is of type "ConsoleSpinner".
* @returns the stopped spinner object.
*/
static spinnerStop(spinner: ConsoleSpinner): ConsoleSpinner {
return spinner.stop();
}

public constructor(_name = "root") {
super(_name);
}
Expand Down
3 changes: 2 additions & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"tools/devops/*",
"tools/executors/*",
"tools/generators/*",
"tools/storm/*",
"tools/nx/*",
"tools/forecast/*",
"design-system/*",
"libs/core/*",
"libs/common/*",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "stormstack",
"name": "@stormstack/root",
"namespace": "@stormstack",
"version": "0.0.0",
"private": true,
Expand Down
39 changes: 37 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "stormstack",
"name": "@stormstack/root",
"$schema": "node_modules/nx/schemas/project-schema.json",
"targets": {
"local-registry": {
Expand Down
3 changes: 3 additions & 0 deletions tools/forecast/codegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"@prisma/client": "^5.2.0",
"@vscode/vsce": "^2.20.1",
"chalk": "4.1.0",
"cosmiconfig": "^8.3.6",
"glob": "^10.3.3",
"handlebars": "^4.7.8",
"langium": "1.2.1",
"langium-cli": "1.2.1",
"path": "^0.12.7",
Expand Down
32 changes: 2 additions & 30 deletions tools/forecast/codegen/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/tools/forecast/codegen",
"main": "tools/forecast/codegen/src/cli/index.ts",
"main": "tools/forecast/codegen/src/index.ts",
"additionalEntryPoints": [
"tools/forecast/codegen/src/index.ts",
"tools/forecast/codegen/src/plugins/access-policy/index.ts",
"tools/forecast/codegen/src/plugins/model-meta/index.ts",
"tools/forecast/codegen/src/plugins/prisma/index.ts"
"tools/forecast/codegen/src/cli/index.ts"
],
"project": "tools/forecast/codegen/package.json",
"tsConfig": "tools/forecast/codegen/tsconfig.json",
Expand Down Expand Up @@ -46,31 +43,6 @@
"input": "tools/forecast/codegen/build",
"glob": "*.*",
"output": "build"
},
{
"input": "tools/forecast/codegen/src/res",
"glob": "*.*",
"output": "res"
},
{
"input": "tools/forecast/codegen/assets",
"glob": "*.*",
"output": "assets"
},
{
"input": "tools/forecast/codegen/syntaxes",
"glob": "*.*",
"output": "syntaxes"
},
{
"input": "tools/forecast/codegen",
"glob": "language-configuration.json",
"output": "."
},
{
"input": "tools/forecast/codegen/bin",
"glob": ".",
"output": "bin"
}
]
}
Expand Down
Loading

0 comments on commit d994538

Please sign in to comment.