diff --git a/package.json b/package.json index 60f670c..837ec31 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "displayName": "lowcode", "description": "lowcode tool, support ChatGPT and other LLM", "author": "wjkang ", - "version": "1.7.9", + "version": "1.8.0", "icon": "asset/icon.png", "publisher": "wjkang", "repository": "https://github.com/lowcoding/lowcode-vscode", diff --git a/src/extension.ts b/src/extension.ts index 613872c..9a04301 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -10,6 +10,7 @@ import { registerQuickGenerateBlock } from './commands/quickGenerateBlock'; import { registerChatGPTViewProvider } from './webview'; import { registerChatGPTCommand } from './commands/chatGPT'; import { registerRunSnippetScript } from './commands/runSnippetScript'; +import { runActivate } from './lifecycle'; export function activate(context: vscode.ExtensionContext) { vscode.window.onDidChangeActiveTextEditor( @@ -23,6 +24,8 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions, ); + runActivate(); + init({ extensionContext: context, extensionPath: context.extensionPath }); generateCode(context); diff --git a/src/lifecycle.ts b/src/lifecycle.ts new file mode 100644 index 0000000..86d1582 --- /dev/null +++ b/src/lifecycle.ts @@ -0,0 +1,29 @@ +import * as path from 'path'; +import * as fs from 'fs-extra'; +import { window } from 'vscode'; +import { getSnippets } from './utils/materials'; +import { getEnv, rootPath } from './utils/vscodeEnv'; + +export const runActivate = () => { + const templateList = getSnippets().filter((s) => s.preview.runActivate); + templateList.forEach((template) => { + const scriptFile = path.join(template!.path, 'script/index.js'); + if (fs.existsSync(scriptFile)) { + // delete eval('require').cache[eval('require').resolve(scriptFile)]; + const script = eval('require')(scriptFile); + if (script.onActivate) { + const context = { + workspaceRootPath: rootPath, + env: getEnv(), + materialPath: template!.path, + code: '', + }; + try { + script.onActivate(context); + } catch (ex: any) { + window.showErrorMessage(`${template.name}:${ex.toString()}`); + } + } + } + }); +}; diff --git a/src/utils/materials.ts b/src/utils/materials.ts index 37b5530..0e2e336 100644 --- a/src/utils/materials.ts +++ b/src/utils/materials.ts @@ -33,6 +33,7 @@ export const getLocalMaterials = ( notShowInintellisense?: boolean; showInRunSnippetScript?: boolean; showInRunSnippetScriptOnExplorer?: boolean; + runActivate?: boolean; schema?: string; chatGPT?: { commandPrompt?: string; @@ -188,6 +189,7 @@ export function getSnippets() { notShowInintellisense?: boolean; showInRunSnippetScript?: boolean; showInRunSnippetScriptOnExplorer?: boolean; + runActivate?: boolean; schema?: string; chatGPT?: { commandPrompt?: string;