|
| 1 | +const path = require('path'); |
| 2 | +const replace = require('replace-in-file').sync; |
| 3 | +const remove = require('del').sync; |
| 4 | + |
| 5 | +const srcPath = path.join(__dirname, '..', 'src'); |
| 6 | +const testPath = path.join(__dirname, '..', 'test'); |
| 7 | +const srcAndTestPath = `{${testPath},${srcPath}}`; |
| 8 | +const routerPath = path.join(srcPath, 'interfaces', 'http', 'router.js'); |
| 9 | +const containerPath = path.join(srcPath, 'container.js'); |
| 10 | + |
| 11 | +// Remove the references of the files that will be removed |
| 12 | + |
| 13 | +replace({ |
| 14 | + files: routerPath, |
| 15 | + from: /\s*apiRouter.*UsersController'\)\);/, |
| 16 | + to: '' |
| 17 | +}); |
| 18 | + |
| 19 | +replace({ |
| 20 | + files: containerPath, |
| 21 | + from: [ |
| 22 | + /\s*const.*app\/user'\);/, |
| 23 | + /\s*const.*UsersRepository'\);/, |
| 24 | + /\, User: UserModel/, |
| 25 | + /\s*usersRepository.*\}\]/, |
| 26 | + /\,\s*UserModel/, |
| 27 | + /createUser.*\n/, |
| 28 | + /\s*getAllUsers.*GetAllUsers/, |
| 29 | + ], |
| 30 | + to: '' |
| 31 | +}); |
| 32 | + |
| 33 | +// Remove example app files |
| 34 | + |
| 35 | +remove([ |
| 36 | + path.join(srcAndTestPath, 'app', 'user', '**'), |
| 37 | + path.join(srcAndTestPath, 'domain', 'user', '**'), |
| 38 | + path.join(srcAndTestPath, 'infra', 'user', '**'), |
| 39 | + path.join(srcPath, 'infra', 'database', 'migrate', '*.js'), |
| 40 | + path.join(srcPath, 'infra', 'database', 'seeds', '*.js'), |
| 41 | + path.join(srcPath, 'infra', 'database', 'models', 'User.js'), |
| 42 | + path.join(srcPath, 'interfaces', 'http', 'user', '**'), |
| 43 | + path.join(testPath, 'api', 'users', '**'), |
| 44 | + path.join(testPath, 'support', 'factories', '*.js') |
| 45 | +]); |
| 46 | + |
| 47 | +// Remove `cleanup` command from package.json |
| 48 | + |
| 49 | +replace({ |
| 50 | + files: path.join(__dirname, '..', 'package.json'), |
| 51 | + from: /\,\s*\"cleanup.*cleanup\.js\"/, |
| 52 | + to: '' |
| 53 | +}); |
0 commit comments