-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.js
More file actions
76 lines (63 loc) · 2.44 KB
/
Copy pathextension.js
File metadata and controls
76 lines (63 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const vscode = require('vscode');
const fs = require('fs');
const path = require('path');
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
let page_action_disposable = vscode.commands.registerCommand('chrome-extension-helper.page_action', page_action);
let browser_action_disposable = vscode.commands.registerCommand('chrome-extension-helper.browser_action',browser_action);
context.subscriptions.push(page_action_disposable);
context.subscriptions.push(browser_action_disposable);
}
exports.activate = activate;
// this method is called when your extension is deactivated
function deactivate() {}
module.exports = {
activate,
deactivate
}
const templates = require('./templates');
async function build_extension(type){
var projectName = await vscode.window.showInputBox({"prompt":"Enter a name for your new project",
"placeHolder":"hello_world",});
if (!projectName) return vscode.window.showErrorMessage("Project name empty");
const folder = await vscode.window.showOpenDialog({
canSelectFolders: true,
openLabel: "Select a folder to create the project in"
});
if (!folder || folder.length !== 1) return;
const folderName = folder[0]["path"];
const fullpath = path.join(folderName,projectName);
if (fs.existsSync(fullpath))
return vscode.window.showErrorMessage("A folder named "+projectName+" already exists");
fs.mkdirSync(fullpath);
createManifest(fullpath,projectName,type);
createPopupHtml(fullpath,projectName);
createEmptyFiles(fullpath);
const S = !(!vscode.workspace.workspaceFolders || !vscode.workspace.workspaceFolders.length);
await vscode.commands.executeCommand("vscode.openFolder", vscode.Uri.file(fullpath),S);
}
async function page_action(){
build_extension("page_action");
}
function browser_action(){
build_extension("browser_action");
}
function createManifest(fullpath,projectName,type){
var manifest = templates.getManifest(projectName,type);
fs.writeFileSync(path.join(fullpath, "manifest.json"), manifest);
}
function createPopupHtml(fullpath,projectName){
var popup = templates.getPopup(projectName);
fs.writeFileSync(path.join(fullpath, "popup.html"),popup);
}
function createEmptyFiles(fullpath){
const js = path.join(fullpath,"js");
const img = path.join(fullpath,"img");
fs.mkdirSync(js);
fs.mkdirSync(img);
fs.writeFileSync(path.join(js, "popup.js"),"");
fs.writeFileSync(path.join(js, "eventPage.js"),"");
fs.writeFileSync(path.join(fullpath, "options.html"),"");
}