Skip to content

Instantly share code, notes, and snippets.

@pasaran
Last active April 28, 2018 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pasaran/e8a58b7f2aea181866fc80b7bd75ebfe to your computer and use it in GitHub Desktop.
Save pasaran/e8a58b7f2aea181866fc80b7bd75ebfe to your computer and use it in GitHub Desktop.

Запускать как-то так:

$ gjs "/islands'" -l --nocolor | xargs ./fix-imports.js
#!/usr/bin/env node
/* eslint no-console: 0 */
const fs = require('fs');
for (let i = 2; i < process.argv.length; i++) {
const filename = process.argv[i];
if (filename === process.argv[1]) {
continue;
}
fixFilename(filename);
}
function fixFilename(filename) {
let content = fs.readFileSync(filename, 'utf-8');
content = content.replace(/^const\s*{\s*(.*?)\s*}\s*=\s*require\('auto-core\/react\/components\/islands'\);$/gm, function(_, components) {
if (components.indexOf(':') !== -1) {
console.error(`Skipping ${ filename }`);
return _;
}
return components.split(/\s*,\s*/g)
.map(function(name) {
name = name.trim();
if (!name) {
return null;
}
return `const ${ name } = require('auto-core/react/components/islands/${ name }');`;
})
.filter(Boolean)
.join('\n');
});
fs.writeFileSync(filename, content, 'utf-8');
}
@pasaran
Copy link
Author

pasaran commented Apr 28, 2018

gjs — это у меня вот такое. Наверное, find тоже сработает

#!/bin/sh

ag -G '.((js|ts)x?|json)$' --ignore '*.bundle.js' $@

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment