Skip to content

Commit 9ff0f82

Browse files
authored
Merge pull request #23 from lowcoding/feat/v1.8.0
✨ feat: lifecycle runActivate
2 parents 460d4d9 + a05d2ca commit 9ff0f82

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "lowcode",
44
"description": "lowcode tool, support ChatGPT and other LLM",
55
"author": "wjkang <[email protected]>",
6-
"version": "1.7.9",
6+
"version": "1.8.0",
77
"icon": "asset/icon.png",
88
"publisher": "wjkang",
99
"repository": "https://github.com/lowcoding/lowcode-vscode",

src/extension.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { registerQuickGenerateBlock } from './commands/quickGenerateBlock';
1010
import { registerChatGPTViewProvider } from './webview';
1111
import { registerChatGPTCommand } from './commands/chatGPT';
1212
import { registerRunSnippetScript } from './commands/runSnippetScript';
13+
import { runActivate } from './lifecycle';
1314

1415
export function activate(context: vscode.ExtensionContext) {
1516
vscode.window.onDidChangeActiveTextEditor(
@@ -23,6 +24,8 @@ export function activate(context: vscode.ExtensionContext) {
2324
context.subscriptions,
2425
);
2526

27+
runActivate();
28+
2629
init({ extensionContext: context, extensionPath: context.extensionPath });
2730

2831
generateCode(context);

src/lifecycle.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import * as path from 'path';
2+
import * as fs from 'fs-extra';
3+
import { window } from 'vscode';
4+
import { getSnippets } from './utils/materials';
5+
import { getEnv, rootPath } from './utils/vscodeEnv';
6+
7+
export const runActivate = () => {
8+
const templateList = getSnippets().filter((s) => s.preview.runActivate);
9+
templateList.forEach((template) => {
10+
const scriptFile = path.join(template!.path, 'script/index.js');
11+
if (fs.existsSync(scriptFile)) {
12+
// delete eval('require').cache[eval('require').resolve(scriptFile)];
13+
const script = eval('require')(scriptFile);
14+
if (script.onActivate) {
15+
const context = {
16+
workspaceRootPath: rootPath,
17+
env: getEnv(),
18+
materialPath: template!.path,
19+
code: '',
20+
};
21+
try {
22+
script.onActivate(context);
23+
} catch (ex: any) {
24+
window.showErrorMessage(`${template.name}${ex.toString()}`);
25+
}
26+
}
27+
}
28+
});
29+
};

src/utils/materials.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export const getLocalMaterials = (
3333
notShowInintellisense?: boolean;
3434
showInRunSnippetScript?: boolean;
3535
showInRunSnippetScriptOnExplorer?: boolean;
36+
runActivate?: boolean;
3637
schema?: string;
3738
chatGPT?: {
3839
commandPrompt?: string;
@@ -188,6 +189,7 @@ export function getSnippets() {
188189
notShowInintellisense?: boolean;
189190
showInRunSnippetScript?: boolean;
190191
showInRunSnippetScriptOnExplorer?: boolean;
192+
runActivate?: boolean;
191193
schema?: string;
192194
chatGPT?: {
193195
commandPrompt?: string;

0 commit comments

Comments
 (0)