Skip to content

Commit

Permalink
resolves #13
Browse files Browse the repository at this point in the history
  • Loading branch information
daretodave committed Apr 24, 2024
1 parent 6d97383 commit 78cfedb
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
3 changes: 3 additions & 0 deletions src/main/bootstrap/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ export async function boostrap(context: BootstrapContext): Promise<void> {
await workspace.load()

await createWindows(context)

await workspace.commands.load()

await createTray(context)

createShortcut(context)
Expand Down
5 changes: 3 additions & 2 deletions src/main/framework/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ export class Commands {
}

const packageJson = await readJson(join(this.workingDirectory, 'package.json'))

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

const tsConfig = await readJson(join(this.templateDirectory, 'tsconfig.json'))
const tsConfig = await readJson(join(this.workingDirectory, 'tsconfig.json'))

tsConfig['compilerOptions'].typeRoots = [join(__dirname, '..', '..', 'node_modules', '@types')]

Expand All @@ -53,7 +54,7 @@ export class Commands {
await writeJson(join(temp, 'tsconfig.json'), tsConfig, 'utf-8')
await writeJson(join(temp, 'package.json'), packageJson, 'utf-8')

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

const jsFile: Buffer = await readFile(join(temp, 'commands.js'))
runInNewContext(`${jsFile}`, this)
Expand Down
1 change: 0 additions & 1 deletion src/main/framework/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export class Workspace {
}

await this.settings.load()
await this.commands.load()

/**
* Load an initial index
Expand Down
18 changes: 14 additions & 4 deletions src/main/vendor/webpack.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import webpack from 'webpack'

export async function compile(scriptFile: string, scriptFileCompiled: string): Promise<void> {
export async function compile(
scriptFile: string,
folderTarget: string,
...resolveModule: string[]
): Promise<void> {
return new Promise((resolve, reject) => {
webpack(
{
Expand All @@ -17,11 +21,12 @@ export async function compile(scriptFile: string, scriptFileCompiled: string): P
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js']
extensions: ['.tsx', '.ts', '.js'],
modules: resolveModule
},
output: {
filename: 'commands.js',
path: scriptFileCompiled,
path: folderTarget,
library: {
name: 'lib',
type: 'assign-properties'
Expand All @@ -32,7 +37,12 @@ export async function compile(scriptFile: string, scriptFileCompiled: string): P
if (err) {
reject(err)
} else if (stats?.hasErrors()) {
reject(stats.toJson().errors)
reject(
stats
.toJson()
.errors?.map((o) => o.details)
.reduce((errorText, errorEntry) => `${errorText}\n${errorEntry}`, '')
)
} else {
resolve()
}
Expand Down
4 changes: 1 addition & 3 deletions src/renderer/src/error-runtime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ export default function ErrorRuntimePage(): ReactElement {
<button onClick={exit}>Exit</button>
<button onClick={workspace}>Workspace</button>
<hr />
<pre>
<code>{errorMessage}</code>
</pre>
<pre>{errorMessage}</pre>
</div>
)
}

0 comments on commit 78cfedb

Please sign in to comment.