mirror of
https://github.com/konvajs/konva.git
synced 2025-10-15 12:34:52 +08:00
import fixes
This commit is contained in:
33
rename-imports.js
Normal file
33
rename-imports.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import FileHound from 'filehound';
|
||||
import fs from 'fs';
|
||||
|
||||
const files = FileHound.create().paths('./lib').ext('js').find();
|
||||
|
||||
files.then((filePaths) => {
|
||||
filePaths.forEach((filepath) => {
|
||||
fs.readFile(filepath, 'utf8', (err, text) => {
|
||||
if (!text.match(/import .* from/g)) {
|
||||
return;
|
||||
}
|
||||
text = text.replace(/(import .* from\s+['"])(.*)(?=['"])/g, '$1$2.js');
|
||||
if (text.match(/export .* from/g)) {
|
||||
text = text.replace(/(export .* from\s+['"])(.*)(?=['"])/g, '$1$2.js');
|
||||
}
|
||||
|
||||
if (err) throw err;
|
||||
|
||||
// stupid replacement back
|
||||
text = text.replace(
|
||||
"import * as canvas from 'canvas.js';",
|
||||
"import * as canvas from 'canvas';"
|
||||
);
|
||||
|
||||
console.log(`writing to ${filepath}`);
|
||||
fs.writeFile(filepath, text, function (err) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user