Skip to content

Commit

Permalink
Updates build mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Bachmann committed Oct 16, 2024
1 parent d4627a1 commit 51e037d
Show file tree
Hide file tree
Showing 13 changed files with 857 additions and 17,634 deletions.
1 change: 1 addition & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
build/**/*.js.map
ext-src/**
public/**
node_modules
scripts/**
src/**
.editorconfig
Expand Down
21 changes: 21 additions & 0 deletions build-ext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const esbuild = require('esbuild')
const esbuildPluginTsc = require('esbuild-plugin-tsc')

/** import("esbuild").BuildOptions */
const settings = {
entryPoints: ['ext-src/extension.ts'],
outfile: 'build/ext-src/extension.js',
platform: 'node',
bundle: true,
external: [
'vscode'
],
plugins: [
esbuildPluginTsc({
force: true,
tsconfigPath: 'tsconfig.extension.json'
})
]
}

esbuild.build(settings)
25 changes: 25 additions & 0 deletions build-view.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const esbuild = require('esbuild')
const esbuildPluginTsc = require('esbuild-plugin-tsc')

/** import("esbuild").BuildOptions */
const settings = {
entryPoints: ['src/index.tsx'],
outdir: 'build/static/',
platform: 'browser',
bundle: true,
loader: {
'.html': 'file',
'.ttf': 'file',
'.ttf?*': 'file',
'.woff': 'file',
'.woff2': 'file'
},
plugins: [
esbuildPluginTsc({
force: true,
tsconfigPath: 'tsconfig.json'
})
]
}

esbuild.build(settings)
13 changes: 3 additions & 10 deletions ext-src/KanbnBoardPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ export default class KanbnBoardPanel {
// Restrict the webview to only loading content from allowed paths
localResourceRoots: [
vscode.Uri.file(path.join(this._extensionPath, 'build')),
vscode.Uri.file(path.join(this._kanbnFolderName, '.kanbn')),
vscode.Uri.file(path.join(this._extensionPath, 'node_modules', 'vscode-codicons', 'dist'))
vscode.Uri.file(path.join(this._kanbnFolderName, '.kanbn'))
]
});
(this._panel as any).iconPath = {
Expand Down Expand Up @@ -283,10 +282,8 @@ export default class KanbnBoardPanel {
}

private _getHtmlForWebview (): string {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const manifest = require(path.join(this._extensionPath, 'build', 'asset-manifest.json'))
const mainScript = manifest.files['main.js']
const mainStyle = manifest.files['main.css']
const mainScript = path.join('static', 'index.js')
const mainStyle = path.join('static', 'index.css')
if (this._panel === null) {
throw new Error('panel is undefined')
}
Expand All @@ -296,9 +293,6 @@ export default class KanbnBoardPanel {
const customStyleUri = webview.asWebviewUri(vscode.Uri.file(
path.join(this._kanbnFolderName, '.kanbn', 'board.css')
))
const codiconsUri = webview.asWebviewUri(vscode.Uri.file(
path.join(this._extensionPath, 'node_modules', 'vscode-codicons', 'dist', 'codicon.css')
))

// Use a nonce to whitelist which scripts can be run
const nonce = getNonce()
Expand All @@ -312,7 +306,6 @@ export default class KanbnBoardPanel {
<title>Kanbn Board</title>
<link rel="stylesheet" type="text/css" href="${styleUri.toString()}">
<link rel="stylesheet" type="text/css" href="${customStyleUri.toString()}">
<link rel="stylesheet" type="text/css" href="${codiconsUri.toString()}">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src vscode-webview-resource: https:; script-src 'nonce-${nonce}'; font-src vscode-webview-resource:; style-src vscode-webview-resource: 'unsafe-inline' http: https: data:;">
<base href="${webview.asWebviewUri(vscode.Uri.file(path.join(this._extensionPath, 'build'))).toString()})}/">
</head>
Expand Down
13 changes: 3 additions & 10 deletions ext-src/KanbnBurndownPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ export default class KanbnBurndownPanel {
// Restrict the webview to only loading content from allowed paths
localResourceRoots: [
vscode.Uri.file(path.join(this._extensionPath, 'build')),
vscode.Uri.file(path.join(this._kanbnFolderName, '.kanbn')),
vscode.Uri.file(path.join(this._extensionPath, 'node_modules', 'vscode-codicons', 'dist'))
vscode.Uri.file(path.join(this._kanbnFolderName, '.kanbn'))
]
});
(this._panel as any).iconPath = {
Expand Down Expand Up @@ -148,10 +147,8 @@ export default class KanbnBurndownPanel {
}

private _getHtmlForWebview (): string {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const manifest = require(path.join(this._extensionPath, 'build', 'asset-manifest.json'))
const mainScript = manifest.files['main.js']
const mainStyle = manifest.files['main.css']
const mainScript = path.join('static', 'index.js')
const mainStyle = path.join('static', 'index.css')
if (this._panel === null) {
throw new Error('panel is undefined')
}
Expand All @@ -163,9 +160,6 @@ export default class KanbnBurndownPanel {
const customStyleUri = webview.asWebviewUri(vscode.Uri.file(
path.join(this._kanbnFolderName, '.kanbn', 'board.css')
))
const codiconsUri = webview.asWebviewUri(vscode.Uri.file(
path.join(this._extensionPath, 'node_modules', 'vscode-codicons', 'dist', 'codicon.css')
))

// Use a nonce to whitelist which scripts can be run
const nonce = getNonce()
Expand All @@ -179,7 +173,6 @@ export default class KanbnBurndownPanel {
<title>Kanbn Board</title>
<link rel="stylesheet" type="text/css" href="${styleUri.toString()}">
<link rel="stylesheet" type="text/css" href="${customStyleUri.toString()}">
<link rel="stylesheet" type="text/css" href="${codiconsUri.toString()}">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src vscode-webview-resource: https:; script-src 'nonce-${nonce}'; font-src vscode-webview-resource:; style-src vscode-webview-resource: 'unsafe-inline' http: https: data:;">
<base href="${webview.asWebviewUri(vscode.Uri.file(path.join(this._extensionPath, 'build'))).toString()}/">
</head>
Expand Down
35 changes: 13 additions & 22 deletions ext-src/KanbnTaskPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default class KanbnTaskPanel {
this._kanbnFolderName = kanbnFolderName
this._taskId = taskId
this._defaultColumn = defaultColumn

// Create and show a new webview panel
this._panel = this.createWebviewPanel(column)
this.updateFileWatcher()
Expand Down Expand Up @@ -224,16 +224,15 @@ export default class KanbnTaskPanel {
)
}

private createWebviewPanel(column: vscode.ViewColumn): vscode.WebviewPanel {
private createWebviewPanel (column: vscode.ViewColumn): vscode.WebviewPanel {
return vscode.window.createWebviewPanel(KanbnTaskPanel.viewType, 'New task', column, {
// Enable javascript in the webview
enableScripts: true,

// Restrict the webview to only loading content from allowed paths
localResourceRoots: [
vscode.Uri.file(path.join(this._extensionPath, 'build')),
vscode.Uri.file(path.join(this._kanbnFolderName, '.kanbn')),
vscode.Uri.file(path.join(this._extensionPath, 'node_modules', 'vscode-codicons', 'dist'))
vscode.Uri.file(path.join(this._kanbnFolderName, '.kanbn'))
]
})
}
Expand All @@ -248,9 +247,8 @@ export default class KanbnTaskPanel {
}
}


private getTaskFilename (): string | undefined {
if (typeof this._taskId !== 'string') return
if (typeof this._taskId !== 'string') return

const folderPath = path.join(this._kanbnFolderName, '.kanbn')
const taskFilename = this._taskId.replace(/(?<!\.md)$/, '.md')
Expand All @@ -259,12 +257,12 @@ export default class KanbnTaskPanel {
return taskPath
}

private updateFileWatcher() {
private updateFileWatcher (): void {
this.fileWatcher?.dispose()
if (!this._panel) return
if (this._panel === undefined) return

const taskPath = this.getTaskFilename()
if (!taskPath) return;
if (taskPath === undefined) return

this.fileWatcher = vscode.workspace.createFileSystemWatcher(taskPath)
this._panel.onDidDispose(() => this.fileWatcher?.dispose())
Expand All @@ -277,7 +275,7 @@ export default class KanbnTaskPanel {
public async showTaskFilePanel (): Promise<void> {
const taskPath = this.getTaskFilename()

if (!taskPath) return
if (taskPath === undefined) return

const taskfileEditor = vscode.workspace.getConfiguration('kanbn').get<boolean>('taskfileEditor')
try {
Expand Down Expand Up @@ -349,15 +347,14 @@ export default class KanbnTaskPanel {
}
}

private async loadOtherTaskData(task?: any) {
if (typeof task?.id !== "string") return;
private async loadOtherTaskData (task?: any): void {
if (typeof task?.id !== 'string') return

try {
const finishedPomodoros: number | undefined = await vscode.commands.executeCommand('pomodoro.getFinishedTasksCount', task.id)

if (typeof finishedPomodoros === "number") {
if (typeof finishedPomodoros === 'number') {
task.finishedPomodoros = finishedPomodoros
} else {
}
} catch (e) {
}
Expand All @@ -369,10 +366,8 @@ export default class KanbnTaskPanel {
}

private _getHtmlForWebview (): string {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const manifest = require(path.join(this._extensionPath, 'build', 'asset-manifest.json'))
const mainScript = manifest.files['main.js']
const mainStyle = manifest.files['main.css']
const mainScript = path.join('static', 'index.js')
const mainStyle = path.join('static', 'index.css')
if (this._panel === null) {
throw new Error('Panel is not defined')
}
Expand All @@ -384,9 +379,6 @@ export default class KanbnTaskPanel {
const customStyleUri = webview.asWebviewUri(vscode.Uri.file(
path.join(this._kanbnFolderName, '.kanbn', 'board.css')
))
const codiconsUri = webview.asWebviewUri(vscode.Uri.file(
path.join(this._extensionPath, 'node_modules', 'vscode-codicons', 'dist', 'codicon.css')
))

// Use a nonce to whitelist which scripts can be run
const nonce = getNonce()
Expand All @@ -400,7 +392,6 @@ export default class KanbnTaskPanel {
<title>Kanbn Board</title>
<link rel="stylesheet" type="text/css" href="${styleUri.toString()}">
<link rel="stylesheet" type="text/css" href="${customStyleUri.toString()}">
<link rel="stylesheet" type="text/css" href="${codiconsUri.toString()}">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src vscode-webview-resource: https:; script-src 'nonce-${nonce}'; font-src vscode-webview-resource:; style-src vscode-webview-resource: 'unsafe-inline' http: https: data:;">
<base href="${webview.asWebviewUri(vscode.Uri.file(path.join(this._extensionPath, 'build'))).toString()}/">
</head>
Expand Down
Loading

0 comments on commit 51e037d

Please sign in to comment.