-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSSTypingLoader.js
More file actions
33 lines (26 loc) · 900 Bytes
/
CSSTypingLoader.js
File metadata and controls
33 lines (26 loc) · 900 Bytes
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
const fs = require('fs');
const banner =
'// This code was generated by a tool.\n// Changes to this file may cause incorrect behavior and will be lost if\n// the code is regenerated.\n\n// tslint:disable\n';
module.exports = function (content, ...args) {
const { resourcePath } = this;
const callback = this.async();
const matchClassNames = /^export var ([^=]+?) =/gm;
let classNameResults = [];
let declaration = '';
let matchResult = null;
console.log(resourcePath)
while ((matchResult = matchClassNames.exec(content)) !== null) {
classNameResults.push(matchResult[1]);
}
classNameResults.sort();
declaration = classNameResults
.map(className => `export declare const ${className}: string;\n`)
.join('');
fs.writeFile(
`${resourcePath}.d.ts`,
`${banner}\n${declaration}`,
function () {
callback(null, content, ...args);
},
);
};