Skip to content

Commit

Permalink
Successfully receive entities in TS runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
sodic committed Sep 30, 2024
1 parent 40dbc78 commit 934e8ae
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Wasp.Cli.Command.CreateNewProject.Common (defaultWaspVersionBounds)
import Wasp.Cli.Command.CreateNewProject.ProjectDescription (NewProjectAppName, NewProjectName)
import Wasp.NodePackageFFI (InstallablePackage (WaspConfigPackage), getPackageInstallationPath)
import Wasp.Project.Analyze (WaspFile (..), findWaspFile)
import Wasp.Project.Analyze (WaspFile (..), findPackageJsonFile, findWaspFile)
import Wasp.Project.Common (WaspProjectDir)
import Wasp.Project.ExternalConfig.PackageJson (findPackageJsonFile)
import qualified Wasp.Util.IO as IOUtil
Expand Down
58 changes: 47 additions & 11 deletions waspc/packages/wasp-config/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,60 @@ import { writeFileSync } from 'fs'
import { App, Spec } from './lib.js'

async function main() {
if (process.argv.length < 4) {
console.error(
const {
mainWaspJs: mainWaspTs,
outputFile,
entityNames,
} = parseProcessArguments(process.argv)

const app: App = (await import(mainWaspTs)).default
const spec = analyzeApp(app, entityNames)

writeFileSync(outputFile, serialize(spec))
console.log(`Wasp spec written to ${outputFile}`)
}

function analyzeApp(app: App, entityNames: string[]): Spec {
return app.getSpec()
}

function parseProcessArguments(args: string[]): {
mainWaspJs: string
outputFile: string
entityNames: string[]
} {
if (process.argv.length < 5) {
throw new Error(
'Usage: node run.js <path to main.wasp.js> <path to output file>'
)
process.exit(1)
}

const [_node, _runjs, mainWaspTs, outputFile] = process.argv
if (typeof mainWaspTs !== 'string' || typeof outputFile !== 'string') {
console.error(
'Usage: node run.js <path to main.wasp.js> <path to output file>'
const [_node, _runjs, mainWaspJs, outputFile, entityNamesJson] = process.argv
if (
typeof mainWaspJs !== 'string' ||
typeof outputFile !== 'string' ||
typeof entityNamesJson !== 'string'
) {
throw new Error(
'Usage: node run.js <path to main.wasp.js> <path to output file> <entity names json>'
)
process.exit(1)
}

const app: App = (await import(mainWaspTs)).default
writeFileSync(outputFile, serialize(app.getSpec()))
console.log(`Wasp spec written to ${outputFile}`)
const entityNames = parseEntityNamesJson(entityNamesJson)

return {
mainWaspJs,
outputFile,
entityNames,
}
}

function parseEntityNamesJson(entitiesJson: string): string[] {
const entities = JSON.parse(entitiesJson)
if (!Array.isArray(entities)) {
throw new Error('The entities JSON must be an array of entity names.')
}
return entities
}

function serialize(appConfig: Spec): string {
Expand Down

0 comments on commit 934e8ae

Please sign in to comment.