forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile-manager.js
More file actions
37 lines (32 loc) · 1002 Bytes
/
file-manager.js
File metadata and controls
37 lines (32 loc) · 1002 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
34
35
36
37
/* eslint-disable no-unused-vars */
/* eslint-disable func-names */
export default function(loaderContext, files) {
return {
install(less, pluginManager) {
function CSBFileManager() {}
CSBFileManager.prototype = new less.FileManager();
CSBFileManager.prototype.constructor = CSBFileManager;
CSBFileManager.prototype.supports = function(filename) {
return true;
};
CSBFileManager.prototype.resolve = function(filename) {
return new Promise((resolve, reject) => {
try {
loaderContext.addDependency(filename);
const module = files[filename];
resolve(module);
} catch (e) {
reject(e);
}
});
};
CSBFileManager.prototype.loadFile = function(filename) {
return this.resolve(filename).then(code => ({
contents: code,
filename,
}));
};
pluginManager.addFileManager(new CSBFileManager());
},
};
}