Skip to content

Commit

Permalink
fix: reset lib on command load + add a way to ignore mterm templates
Browse files Browse the repository at this point in the history
  • Loading branch information
daretodave committed Apr 29, 2024
1 parent f3d1516 commit 328852c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/main/bootstrap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export async function boostrap(context: BootstrapContext): Promise<void> {
}
})

await workspace.commands.load()
await workspace.commands.load(workspace.settings)
} catch (e) {
console.error(e)

Expand Down
11 changes: 8 additions & 3 deletions src/main/framework/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { runInNewContext } from 'node:vm'
import * as tryRequire from 'try-require'
import { compile } from '../vendor/webpack'
import { ExecuteContext } from './runtime'
import { Settings } from './settings'

export class Commands {
public lib: object = {}
Expand Down Expand Up @@ -65,18 +66,20 @@ export class Commands {
return exec
}

async load(): Promise<void> {
async load(settings: Settings): Promise<void> {
const filesToCreate = [
{ templateFile: 'package.json', outputFile: 'package.json' },
{ templateFile: 'commands.ts', outputFile: 'commands.ts' },
{ templateFile: 'node_types.ts', outputFile: 'types.d.ts' }
]

const ignoreTemplates = settings.get<string[]>('ignoreTemplate', [])

for (const { templateFile, outputFile } of filesToCreate) {
const outputFilePath = join(this.workingDirectory, outputFile)
const isExist = await pathExists(outputFilePath)

if (!isExist) {
if (!isExist && !ignoreTemplates.includes(outputFile)) {
const templateFilePath = join(this.templateDirectory, templateFile)
const templateContent: Buffer = await readFile(templateFilePath)
await writeFile(outputFilePath, templateContent, 'utf-8')
Expand All @@ -85,7 +88,7 @@ export class Commands {

const tsConfigTarget = join(this.workingDirectory, 'tsconfig.json')
const isTSConfigExists = await pathExists(tsConfigTarget)
if (!isTSConfigExists) {
if (!isTSConfigExists && !ignoreTemplates.includes('tsconfig.json')) {
const tsConfig = await readJson(join(this.templateDirectory, 'tsconfig.json'))

tsConfig['compilerOptions'].types = tsConfig['compilerOptions'].types || []
Expand All @@ -105,6 +108,8 @@ export class Commands {

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

this.lib = {}

runInNewContext(`${jsFile}`, this)
}
}
6 changes: 3 additions & 3 deletions src/main/framework/system-commands/reload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { ExecuteContext } from '../runtime'
import { RunnerWindow } from '../../window/windows/runner'

async function reload(context: ExecuteContext): Promise<void> {
await context.workspace.commands.load()
context.out('- commands reloaded \n')

await context.workspace.load()
context.out('- settings reloaded \n')

await context.workspace.commands.load(context.workspace.settings)
context.out('- commands reloaded \n')

await context.workspace.reload(RunnerWindow)
context.out('- window reloaded \n')
}
Expand Down

0 comments on commit 328852c

Please sign in to comment.