Skip to content

Commit

Permalink
fix: apply compile on user dir for commands.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
daretodave committed Apr 29, 2024
1 parent 2cf2222 commit fb7ae4b
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions src/main/framework/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class Commands {
const filesToCreate = [
{ templateFile: 'package.json', outputFile: 'package.json' },
{ templateFile: 'commands.ts', outputFile: 'commands.ts' },
{ templateFile: 'tsconfig.json', outputFile: 'tsconfig.json' }
{ templateFile: 'node_types.ts', outputFile: 'types.d.ts' }
]

for (const { templateFile, outputFile } of filesToCreate) {
Expand All @@ -83,31 +83,25 @@ export class Commands {
}
}

const nodeTypesFileLocation = join(this.templateDirectory, 'node_types.ts')
const types: Buffer = await readFile(nodeTypesFileLocation)
const tsConfigTarget = join(this.workingDirectory, 'tsconfig.json')
const isTSConfigExists = await pathExists(tsConfigTarget)
if (!isTSConfigExists) {
const tsConfig = await readJson(join(this.templateDirectory, 'tsconfig.json'))

const packageJson = await readJson(join(this.workingDirectory, 'package.json'))
tsConfig['compilerOptions'].types = tsConfig['compilerOptions'].types || []
tsConfig['compilerOptions'].types.push(join(this.workingDirectory, 'types.d.ts'))

const commandFileLocation = join(this.workingDirectory, packageJson.main)
const commands: Buffer = await readFile(commandFileLocation)
await writeJson(tsConfigTarget, tsConfig)
}

const tsConfig = await readJson(join(this.workingDirectory, 'tsconfig.json'))
const packageJson = await readJson(join(this.workingDirectory, 'package.json'))
const commandFileLocation = join(this.workingDirectory, packageJson.main)

const id = short.generate()
const temp = join(tmpdir(), `mterm-${id}`)
await mkdirs(temp)

tsConfig['compilerOptions'].types = tsConfig['compilerOptions'].types || []
tsConfig['compilerOptions'].types.push(join(temp, 'node.d.ts'))

const scriptFile = join(temp, packageJson.main)
await writeFile(scriptFile, commands, 'utf-8')
await writeJson(join(temp, 'tsconfig.json'), tsConfig, 'utf-8')
await writeJson(join(temp, 'package.json'), packageJson, 'utf-8')

await writeFile(join(temp, 'node.d.ts'), types, 'utf-8')

await compile(scriptFile, temp, join(this.workingDirectory, 'node_modules'))
await compile(commandFileLocation, temp, join(this.workingDirectory, 'node_modules'))

const jsFile: Buffer = await readFile(join(temp, 'commands.js'))

Expand Down

0 comments on commit fb7ae4b

Please sign in to comment.