-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tools-executors-typescript): Added the
storm
schema code gener…
…ation executor
- Loading branch information
1 parent
b9789cb
commit e4c570d
Showing
8 changed files
with
134 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { ExecutorContext, workspaceRoot } from "@nx/devkit"; | ||
import { executeAsync } from "@open-system/core-server-utilities"; | ||
import { ConsoleLogger } from "@open-system/core-shared-utilities"; | ||
import { generateAction } from "@open-system/tools-storm-schema"; | ||
import { existsSync } from "fs"; | ||
import Path from "path"; | ||
import { StormGenerateExecutorSchema } from "./schema"; | ||
|
||
export default async function ( | ||
options: StormGenerateExecutorSchema, | ||
context: ExecutorContext | ||
) { | ||
let result!: unknown; | ||
try { | ||
ConsoleLogger.info("Executing Storm (Code Generation) executor..."); | ||
|
||
const buildTarget = | ||
context.workspace.projects[context.projectName].targets.build; | ||
|
||
const schemaPath = Path.join(workspaceRoot, options.schema); | ||
if (!existsSync(schemaPath)) { | ||
ConsoleLogger.error( | ||
`No Storm schema file could be found at: "${schemaPath}" ` | ||
); | ||
return { success: false }; | ||
} | ||
|
||
const outputPath = Path.join(workspaceRoot, buildTarget.options.outputPath); | ||
if (existsSync(outputPath)) { | ||
result = await executeAsync(`rmdir /S /Q "${outputPath}" `); | ||
if (result) { | ||
ConsoleLogger.error(result); | ||
return { success: false }; | ||
} | ||
} | ||
|
||
await generateAction({ | ||
schema: schemaPath, | ||
packageManager: options.packageManager, | ||
dependencyCheck: options.dependencyCheck, | ||
outDir: outputPath, | ||
}); | ||
|
||
ConsoleLogger.success( | ||
`Storm (Code Generation) executor successfully ran for ${context.projectName}.` | ||
); | ||
|
||
return { success: !result }; | ||
} catch (e) { | ||
ConsoleLogger.error( | ||
`An error occurred syncing client API for ${context.projectName}` | ||
); | ||
ConsoleLogger.error(e); | ||
|
||
return { success: false }; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export type PackageManagers = "npm" | "yarn" | "pnpm"; | ||
|
||
export interface StormGenerateExecutorSchema { | ||
schema: string; | ||
outputPath: string; | ||
packageManager: PackageManagers; | ||
dependencyCheck: boolean; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"$schema": "http://json-schema.org/schema", | ||
"cli": "nx", | ||
"id": "storm-generate", | ||
"title": "Open System - Storm Generate", | ||
"description": "Generate code based on a provided Storm model", | ||
"type": "object", | ||
"properties": { | ||
"schema": { | ||
"type": "string", | ||
"description": "The `.storm` file name and path of the Storm model to use", | ||
"default": "./schema.storm" | ||
}, | ||
"outputPath": { | ||
"type": "string", | ||
"description": "Path to the directory where the files will be generated", | ||
"default": "src/__generated__" | ||
}, | ||
"packageManager": { | ||
"type": "string", | ||
"description": "Name of the package manager used by this repository", | ||
"options": [ | ||
"npm", "yarn", "pnpm" | ||
], | ||
"default": "npm" | ||
}, | ||
"dependencyCheck": { | ||
"type": "boolean", | ||
"description": "Should the currently installed Prisma version be checked", | ||
"default": true | ||
} | ||
}, | ||
"required": ["stormFile", "outputPath", "packageManager", "dependencyCheck"] | ||
} |