-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.js
executable file
·63 lines (53 loc) · 1.75 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
/**
* @author Diego Alberto Molina Vera
* @copyright 2016 - 2020
*/
const {
commands,
window
} = require('vscode');
const path = require('path');
const fs = require('fs');
const Minifier = require('./cssMinifier.js');
function activate(context) {
const minifier = new Minifier();
const disposable = commands.registerCommand('extension.minify', () => {
const {
activeTextEditor
} = window;
if (activeTextEditor.document.languageId === 'css') {
const { document } = activeTextEditor;
const content = document.getText().split('\n');
const { fileName } = document;
const filePath = path.dirname(fileName);
const name = path.basename(fileName).replace('css', 'min.css');
const savePath = path.join(filePath, name);
minifier.setContent(content);
// removes the exadecimal
minifier.replaceFullHexadecimalByShorten();
// removes the white spaces
minifier.cleanWhiteSpace();
// removes the zero values with units
minifier.cleanUnitsZeroValue();
// removes the zero prefix from float values
minifier.cleanZeroPrefixFloat();
// replace none by 0
minifier.replaceNoneByZero();
// removes single and double quotes
minifier.cleanQuotes();
minifier.getMinifiedCSS()
.then(modifiedContent => {
fs.writeFile(savePath, modifiedContent, () => {
window.showInformationMessage(`A minified file has been created with the name: ${name}`);
});
}).catch(window.showErrorMessage);
} else {
window.showWarningMessage('This extension must be use on a CSS file');
}
});
context.subscriptions.push(disposable);
}
exports.activate = activate;
function deactivate() {
}
exports.deactivate = deactivate;