Skip to content

Commit f6227ce

Browse files
authored
Merge pull request #587 from devchat-ai/parameterize-packaging
Parameterize packaging
2 parents 6a8393e + e0a9f0a commit f6227ce

File tree

17 files changed

+152
-149
lines changed

17 files changed

+152
-149
lines changed

.env.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
EXTENSION_NAME=devchat
2+
PUBLISHER=merico
3+
ASSISTANT_NAME_EN=DevChat
4+
ASSISTANT_NAME_ZH=DevChat
5+
EXTENSION_ICON=/path/to/extension_icon.png
6+
SIDEBAR_ICON=/path/to/sidebar_icon.svg
7+
DIFF_APPLY_ICON=/path/to/diff_apply_icon.svg

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ actions_backup/
1515
.DS_Store
1616

1717
__pycache__/
18+
*.log

.vscode/launch.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"${workspaceFolder}/dist/**/*.js"
1717
],
1818
"preLaunchTask": "${defaultBuildTask}",
19+
"postDebugTask": "npm: postbuild",
1920
"env": {
2021
"COMPLETE_DEBUG": "true"
2122
}

.vscode/tasks.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@
3535
"npm: watch-tests"
3636
],
3737
"problemMatcher": []
38+
},
39+
{
40+
"type": "npm",
41+
"script": "postbuild",
42+
"problemMatcher": [],
43+
"label": "npm: postbuild",
44+
"detail": "npm run postbuild"
3845
}
3946
]
4047
}

package.json

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
{
2-
"name": "devchat",
3-
"displayName": "DevChat",
2+
"name": "${EXTENSION_NAME}",
3+
"displayName": "${ASSISTANT_NAME_ZH}",
44
"description": "Write prompts, not code",
55
"version": "0.1.74",
66
"icon": "assets/devchat.png",
7-
"publisher": "merico",
7+
"publisher": "${PUBLISHER}",
88
"engines": {
99
"vscode": "^1.75.0"
1010
},
11+
"assistantNames": {
12+
"ASSISTANT_NAME_EN": "${ASSISTANT_NAME_EN}",
13+
"ASSISTANT_NAME_ZH": "${ASSISTANT_NAME_ZH}"
14+
},
1115
"repository": {
1216
"type": "git",
1317
"url": "https://github.com/devchat-ai/devchat-vscode.git"
@@ -72,7 +76,7 @@
7276
"activitybar": [
7377
{
7478
"id": "devchat-sidebar",
75-
"title": "DevChat",
79+
"title": "${ASSISTANT_NAME_ZH}",
7680
"icon": "assets/devchat_icon.svg"
7781
}
7882
]
@@ -82,7 +86,7 @@
8286
{
8387
"type": "webview",
8488
"id": "devchat-view",
85-
"name": "DevChat"
89+
"name": "${ASSISTANT_NAME_ZH}"
8690
}
8791
]
8892
},
@@ -103,27 +107,27 @@
103107
},
104108
{
105109
"command": "devchat.addContext",
106-
"title": "Devchat:Add to DevChat"
110+
"title": "${ASSISTANT_NAME_EN}:Add to ${ASSISTANT_NAME_EN}"
107111
},
108112
{
109113
"command": "devchat.askForCode",
110-
"title": "Devchat:Add to DevChat"
114+
"title": "${ASSISTANT_NAME_EN}:Add to ${ASSISTANT_NAME_EN}"
111115
},
112116
{
113117
"command": "devchat.askForFile",
114-
"title": "Devchat:Add to DevChat"
118+
"title": "${ASSISTANT_NAME_EN}:Add to ${ASSISTANT_NAME_EN}"
115119
},
116120
{
117121
"command": "devchat.addConext_chinese",
118-
"title": "Devchat:添加到DevChat"
122+
"title": "${ASSISTANT_NAME_ZH}:添加到${ASSISTANT_NAME_ZH}"
119123
},
120124
{
121125
"command": "devchat.askForCode_chinese",
122-
"title": "Devchat:添加到DevChat"
126+
"title": "${ASSISTANT_NAME_ZH}:添加到${ASSISTANT_NAME_ZH}"
123127
},
124128
{
125129
"command": "devchat.askForFile_chinese",
126-
"title": "Devchat:添加到DevChat"
130+
"title": "${ASSISTANT_NAME_ZH}:添加到${ASSISTANT_NAME_ZH}"
127131
},
128132
{
129133
"command": "DevChat.InstallCommands",
@@ -137,32 +141,32 @@
137141
},
138142
{
139143
"command": "DevChat.Chat",
140-
"title": "Chat with DevChat",
144+
"title": "Chat with ${ASSISTANT_NAME_EN}",
141145
"category": "DevChat"
142146
},
143147
{
144148
"command": "devchat.explain",
145-
"title": "Devchat:Generate Explain"
149+
"title": "${ASSISTANT_NAME_EN}:Generate Explain"
146150
},
147151
{
148152
"command": "devchat.explain_chinese",
149-
"title": "Devchat:代码解释"
153+
"title": "${ASSISTANT_NAME_ZH}:代码解释"
150154
},
151155
{
152156
"command": "devchat.comments",
153-
"title": "Devchat:Generate Comments"
157+
"title": "${ASSISTANT_NAME_EN}:Generate Comments"
154158
},
155159
{
156160
"command": "devchat.comments_chinese",
157-
"title": "Devchat:生成注释"
161+
"title": "${ASSISTANT_NAME_ZH}:生成注释"
158162
},
159163
{
160164
"command": "devchat.fix",
161-
"title": "Devchat:Fix this"
165+
"title": "${ASSISTANT_NAME_EN}:Fix this"
162166
},
163167
{
164168
"command": "devchat.fix_chinese",
165-
"title": "Devchat:修复此"
169+
"title": "${ASSISTANT_NAME_ZH}:修复此"
166170
},
167171
{
168172
"command": "DevChat.codecomplete_callback",
@@ -171,12 +175,12 @@
171175
},
172176
{
173177
"command": "DevChat.quickFixAskDevChat",
174-
"title": "Ask DevChat",
178+
"title": "Ask ${ASSISTANT_NAME_EN}",
175179
"category": "DevChat"
176180
},
177181
{
178182
"command": "DevChat.quickFixUsingDevChat",
179-
"title": "Ask DevChat",
183+
"title": "Ask ${ASSISTANT_NAME_EN}",
180184
"category": "DevChat"
181185
}
182186
],
@@ -344,10 +348,14 @@
344348
"vscode:uninstall": "node ./dist/uninstall",
345349
"vscode:prepublish": "npm run package",
346350
"compile": "webpack",
347-
"watch": "webpack --watch",
351+
"watch": "node prebuild.js && webpack --watch",
352+
"prebuild": "node prebuild.js",
353+
"postbuild": "git checkout -- assets package.json",
354+
"prepackage": "node prebuild.js",
355+
"postpackage": "git checkout -- assets package.json",
348356
"package": "webpack --mode production --devtool hidden-source-map",
349357
"compile-tests": "tsc -p . --outDir out",
350-
"watch-tests": "tsc -p . -w --outDir out",
358+
"watch-tests": "npm run prebuild && tsc -p . -w --outDir out",
351359
"pretest": "npm run compile-tests && npm run compile && npm run lint",
352360
"lint": "eslint src --ext ts",
353361
"test": "mocha",

prebuild.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
require('dotenv').config()
2+
3+
const fs = require('fs')
4+
const path = require('path')
5+
6+
function copyIcon(src, dst) {
7+
if (!src) {
8+
console.warn(`Icon path for ${dst} is not defined in your environment variables`)
9+
return
10+
}
11+
console.log(`Replacing icon ${dst} by ${src}`)
12+
if (!fs.existsSync(src)) {
13+
console.warn(`Icon file ${src} does not exist.`)
14+
return
15+
}
16+
17+
const destPath = path.join(__dirname, 'assets', dst)
18+
19+
try {
20+
fs.copyFileSync(src, destPath)
21+
fs.chmodSync(destPath, 0o644)
22+
} catch(e) {
23+
console.warn(`Failed to copy logo ${e}`)
24+
}
25+
}
26+
27+
function updatePackageJson() {
28+
const placeholders = {
29+
EXTENSION_NAME: process.env.EXTENSION_NAME || "devchat",
30+
PUBLISHER: process.env.PUBLISHER || "merico",
31+
ASSISTANT_NAME_EN: process.env.ASSISTANT_NAME_EN || "DevChat",
32+
ASSISTANT_NAME_ZH: process.env.ASSISTANT_NAME_ZH || "DevChat"
33+
}
34+
console.log(`Updating package.json, env: ${JSON.stringify(placeholders)}`)
35+
36+
let packageJson = fs.readFileSync('package.json', 'utf8');
37+
38+
// Replace placeholders
39+
Object.entries(placeholders).forEach(([key, value]) => {
40+
const regex = new RegExp(`\\$\\{${key}\\}`, 'g');
41+
packageJson = packageJson.replace(regex, value);
42+
});
43+
44+
fs.writeFileSync('package.json', packageJson);
45+
}
46+
47+
copyIcon(process.env.EXTENSION_ICON, 'devchat.png')
48+
copyIcon(process.env.SIDEBAR_ICON, 'devchat_icon.svg')
49+
copyIcon(process.env.DIFF_APPLY_ICON, 'devchat_apply.svg')
50+
51+
updatePackageJson()

src/contributes/quickFixProvider.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as vscode from "vscode";
22
import { collapseFileExculdeSelectRange } from "./codecomplete/ast/collapseBlock";
3+
import { ASSISTANT_NAME_EN } from "../util/constants";
34

45
class DevChatQuickFixProvider implements vscode.CodeActionProvider {
56
public static readonly providedCodeActionKinds = [
@@ -18,21 +19,21 @@ class DevChatQuickFixProvider implements vscode.CodeActionProvider {
1819

1920
const diagnostic = context.diagnostics[0];
2021
const quickFix = new vscode.CodeAction(
21-
"Ask DevChat",
22+
`Ask ${ASSISTANT_NAME_EN}`,
2223
vscode.CodeActionKind.QuickFix,
2324
);
2425
quickFix.isPreferred = false;
2526

2627
const fixUsingDevChat = new vscode.CodeAction(
27-
"Fix using DevChat",
28+
`Fix using ${ASSISTANT_NAME_EN}`,
2829
vscode.CodeActionKind.QuickFix,
2930
);
3031
fixUsingDevChat.isPreferred = true;
3132

3233
return new Promise(async (resolve) => {
3334
quickFix.command = {
3435
command: "DevChat.quickFixAskDevChat",
35-
title: "Ask DevChat",
36+
title: `Ask ${ASSISTANT_NAME_EN}`,
3637
arguments: [
3738
document,
3839
range,
@@ -42,7 +43,7 @@ class DevChatQuickFixProvider implements vscode.CodeActionProvider {
4243

4344
fixUsingDevChat.command = {
4445
command: "DevChat.quickFixUsingDevChat",
45-
title: "Fix using DevChat",
46+
title: `Fix using ${ASSISTANT_NAME_EN}`,
4647
arguments: [
4748
document,
4849
range,

src/extension.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { InlineCompletionProvider, registerCodeCompleteCallbackCommand } from ".
3535
import { indexDir } from "./contributes/codecomplete/astIndex";
3636
import registerQuickFixProvider from "./contributes/quickFixProvider";
3737
import { stopLocalService } from './util/localService';
38+
import { updateNames } from "./util/constants";
3839

3940

4041
async function migrateConfig() {
@@ -129,6 +130,8 @@ export async function fixDevChatApiBase() {
129130

130131
async function activate(context: vscode.ExtensionContext) {
131132
ExtensionContextHolder.context = context;
133+
const assistantNames = context.extension.packageJSON.assistantNames
134+
updateNames(assistantNames.ASSISTANT_NAME_EN, assistantNames.ASSISTANT_NAME_ZH)
132135

133136
logger.init(LoggerChannelVscode.getInstance());
134137
UiUtilWrapper.init(new UiUtilVscode());

src/handler/chatHandler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { ASSISTANT_NAME_EN } from '../util/constants';
12
import { UiUtilWrapper } from '../util/uiUtil';
23
import { MessageHandler } from './messageHandler';
34
import { isSending } from './sendMessage';
@@ -6,7 +7,7 @@ import { isSending } from './sendMessage';
67
export async function chatWithDevChat(panel, message: string) {
78
if (isSending()) {
89
// already sending, show error
9-
UiUtilWrapper.showErrorMessage("DevChat: A command is already being sent, please try again later.");
10+
UiUtilWrapper.showErrorMessage(`${ASSISTANT_NAME_EN}: A command is already being sent, please try again later.`);
1011
return;
1112
}
1213
MessageHandler.sendMessage(panel!, { command: 'chatWithDevChat', 'message': message });

0 commit comments

Comments
 (0)