-
Notifications
You must be signed in to change notification settings - Fork 3
/
extension.js
59 lines (52 loc) · 2 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
const vscode = require("vscode");
const fs = require("fs");
const path = require("path");
function activate(context) {
let disposable = vscode.workspace.onDidChangeConfiguration(async (e) => {
try {
if (e.affectsConfiguration("daisyui.useClass")) {
const isClass = vscode.workspace
.getConfiguration()
.get("daisyui.useClass"); // default false
// Load existing snippets
const snippetsPath = path.join(
context.extensionPath,
"./snippets/snippets.code-snippets"
);
const snippets = JSON.parse(
fs.readFileSync(snippetsPath, "utf8")
);
for (const snippetName in snippets) {
snippets[snippetName].body = snippets[snippetName].body.map(
(line) => {
// If isClass is true, replace 'className' with 'class'
// If isClass is false, replace 'class' with 'className'
return isClass
? line.replace(/className=/g, "class=")
: line.replace(/class=/g, "className=");
}
);
}
// Save back the modified snippets
fs.writeFileSync(
snippetsPath,
JSON.stringify(snippets, null, 4),
"utf8"
);
vscode.window.showInformationMessage(
`Snippets updated: attributes switched to '${
isClass ? "class" : "className"
}'.`
);
}
} catch (error) {
vscode.window.showErrorMessage(`Error: ${error.message}`);
}
});
context.subscriptions.push(disposable);
}
function deactivate() {}
module.exports = {
activate,
deactivate,
};