-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextension.js
69 lines (62 loc) · 1.67 KB
/
extension.js
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
const vscode = require("vscode");
const ccarc = require("create-component-app").default;
const defaultConfig = {
type: "class",
jsExtension: "js",
cssExtension: "css",
includeTests: false,
includeStories: false,
indexFile: false,
connected: false,
componentMethods: []
};
/**
* Get the config options from settings preference and merge with the default options.
* @param {string} path of destination.
*/
function getConfig(path) {
return new Promise((resolve, reject) => {
const { ccarc } = vscode.workspace.getConfiguration();
vscode.window.showInputBox({ value: "ComponentName" }).then(name => {
if (!name) {
reject("Name is undefined");
}
const config = Object.assign({ path, name }, defaultConfig, ccarc);
resolve(config);
});
});
}
/**
* Get the config and create the components base on config
* @param {object} event from vscode.commands.registerCommand
*/
function createComponent(e) {
const path = e.toJSON().fsPath;
getConfig(path).then(
config => {
if (config.type === "custom") {
ccarc.generateFilesFromCustom(config);
}
ccarc.generateFiles(config);
},
error => {
vscode.window.showErrorMessage(error);
}
);
}
// this method is called when your extension is activated
function activate(context) {
try {
const disposable = vscode.commands.registerCommand(
"extension.create-component-app",
createComponent
);
context.subscriptions.push(disposable);
} catch (error) {
console.log(error);
}
}
exports.activate = activate;
// this method is called when your extension is deactivated
function deactivate() {}
exports.deactivate = deactivate;