-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Netanel Basal
committed
Sep 10, 2019
1 parent
459136a
commit 77cecfc
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} | ||
}); | ||
}); | ||
}); |