Skip to content

Commit

Permalink
feat(lib): add migration script
Browse files Browse the repository at this point in the history
  • Loading branch information
Netanel Basal committed Sep 10, 2019
1 parent 459136a commit 77cecfc
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions migration/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const hasUntilDestroy = /import\s*{\s*[^}]*untilDestroyed[^}]*}\s*from\s*("|')ngx-take-until-destroy\1(?=[^]*untilDestroyed\(\w*\)[^]*)/;
const catchImport = /import\s*{\s*[^}]*untilDestroyed[^}]*}\s*from\s*("|')ngx-take-until-destroy['|"];/;

const glob = require('glob');
const fs = require('fs');

const base = `src/app`;

glob(`${base}/**/*.ts`, {}, function (er, files) {
files.forEach((path) => {
fs.readFile(path, 'utf8', function (err, text) {
if (hasUntilDestroy.test(text)) {
console.log(`Replaced ${path}`);
const result = text.replace(/((?:@\w*\([^]*\)[\n\s\r\t]*)(?=([\n\s\r\t]*export[\s\r\t]*class))\2)/, '@UntilDestroy()\n$1')
.replace(catchImport, `import { untilDestroyed, UntilDestroy } from '@ngneat/until-destroy';`);
fs.writeFile(path, result, 'utf8', function (err) {
if (err) return console.log(err);
});
}
});
});
});

0 comments on commit 77cecfc

Please sign in to comment.