1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const fs = require("fs");
|
4 | const path = require("path");
|
5 | const workspace_1 = require("@nrwl/workspace");
|
6 | const allMigrations = fs
|
7 | .readdirSync(path.join(__dirname, '/../../migrations'))
|
8 | .filter(f => f.endsWith('.js') && !f.endsWith('.d.js'))
|
9 | .map(file => ({
|
10 | migration: require(`../../migrations/${file}`).default,
|
11 | name: path.parse(file).name
|
12 | }));
|
13 | const latestMigration = readLatestMigration();
|
14 | const migrationsToRun = calculateMigrationsToRun(allMigrations, latestMigration);
|
15 | if (migrationsToRun.length === 0) {
|
16 | console.log('No migrations to run');
|
17 | process.exit(0);
|
18 | }
|
19 | printMigrationsNames(latestMigration, migrationsToRun);
|
20 | runMigrations(migrationsToRun);
|
21 | updateLatestMigration();
|
22 | console.log('All migrations run successfully');
|
23 | function readLatestMigration() {
|
24 | const angularCli = workspace_1.readWorkspaceConfigPath();
|
25 | return angularCli.project.latestMigration;
|
26 | }
|
27 | function calculateMigrationsToRun(migrations, latestMigration) {
|
28 | const startingWith = latestMigration
|
29 | ? migrations.findIndex(item => item.name === latestMigration) + 1
|
30 | : 0;
|
31 | return migrations.slice(startingWith);
|
32 | }
|
33 | function printMigrationsNames(latestMigration, migrations) {
|
34 | console.log(`Nx will run the following migrations (after ${latestMigration}):`);
|
35 | migrations.forEach(m => {
|
36 | console.log(`- ${m.name}`);
|
37 | });
|
38 | console.log('---------------------------------------------');
|
39 | }
|
40 | function runMigrations(migrations) {
|
41 | migrations.forEach(m => {
|
42 | try {
|
43 | console.log(`Running ${m.name}`);
|
44 | console.log(m.migration.description);
|
45 | m.migration.run();
|
46 | console.log('---------------------------------------------');
|
47 | }
|
48 | catch (e) {
|
49 | console.error(`Migration ${m.name} failed`);
|
50 | console.error(e);
|
51 | console.error(`Please run 'git checkout .'`);
|
52 | process.exit(1);
|
53 | }
|
54 | });
|
55 | }
|
56 | function updateLatestMigration() {
|
57 |
|
58 | workspace_1.updateJsonFile('.angular-cli.json', angularCliJson => {
|
59 | angularCliJson.project.latestMigration =
|
60 | migrationsToRun[migrationsToRun.length - 1].name;
|
61 | });
|
62 | }
|