1 | #! /usr/bin/env node
|
2 | "use strict";
|
3 |
|
4 | var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
|
5 |
|
6 | var _os = require("os");
|
7 |
|
8 | var _child_process = require("child_process");
|
9 |
|
10 | var _swit = _interopRequireDefault(require("@sharyn/util/swit"));
|
11 |
|
12 | var _safe = _interopRequireDefault(require("colors/safe"));
|
13 |
|
14 | var _checkSetup = require("@sharyn/check-setup");
|
15 |
|
16 | var _env = require("@sharyn/env");
|
17 |
|
18 | var _shared = require("./shared");
|
19 |
|
20 | var _commands = require("./commands");
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | var hasDocker = (0, _checkSetup.hasFile)('docker-compose.yml');
|
26 | var hasHeroku = (0, _checkSetup.hasFile)('Procfile');
|
27 | var hasSeeds = (0, _checkSetup.hasFile)('/src/_db/seeds');
|
28 |
|
29 | var getDbTestProcessId = function getDbTestProcessId(containerName) {
|
30 | var result = (0, _child_process.execSync)("docker ps -q --filter=\"name=".concat(containerName, "\"")).toString();
|
31 | var ids = result.split(_os.EOL).filter(function (x) {
|
32 | return x;
|
33 | });
|
34 |
|
35 | if (ids.length > 1) {
|
36 | throw Error("Multiple running processes found for ".concat(containerName));
|
37 | }
|
38 |
|
39 | return ids[0];
|
40 | };
|
41 |
|
42 | var mySpawn = function mySpawn(cmd) {
|
43 |
|
44 | console.log("".concat(_safe.default.magenta("[sharyn/cli]"), " ").concat(_safe.default.gray(cmd)).replace(/\.\/node_modules\/\.bin\//g, ''));
|
45 | return (0, _child_process.spawn)(cmd, {
|
46 | shell: true,
|
47 | stdio: 'inherit'
|
48 | });
|
49 | };
|
50 |
|
51 | var mySpawnSync = function mySpawnSync(cmd) {
|
52 |
|
53 | console.log("".concat(_safe.default.magenta("[sharyn/cli]"), " ").concat(_safe.default.gray(cmd)).replace(/\.\/node_modules\/\.bin\//g, ''));
|
54 | return (0, _child_process.spawnSync)(cmd, {
|
55 | shell: true,
|
56 | stdio: 'inherit'
|
57 | });
|
58 | };
|
59 |
|
60 | var sequence = function sequence(arr) {
|
61 | return arr.join(' && ');
|
62 | };
|
63 |
|
64 | var taskName = process.argv[2];
|
65 | var result = (0, _swit.default)(taskName, [['dev', function () {
|
66 | var firstCommands = [];
|
67 | hasDocker && firstCommands.push(_commands.DOCKER_UP);
|
68 | hasDocker && _shared.knexConfigPath && firstCommands.push(_commands.DOCKER_WAIT_PG, _commands.dbMigr);
|
69 | hasDocker && _shared.knexConfigPath && hasSeeds && firstCommands.push(_commands.dbSeed);
|
70 | firstCommands.push(_commands.rmBundle);
|
71 | mySpawnSync(sequence(firstCommands));
|
72 | mySpawn(_commands.serverWatch);
|
73 | mySpawn(_commands.clientWatch);
|
74 | }], ['dev-ssr-only', function () {
|
75 | var commands = [];
|
76 | hasDocker && commands.push(_commands.DOCKER_UP);
|
77 | hasDocker && _shared.knexConfigPath && commands.push(_commands.DOCKER_WAIT_PG, _commands.dbMigr);
|
78 | hasDocker && _shared.knexConfigPath && hasSeeds && commands.push(_commands.dbSeed);
|
79 | commands.push(_commands.serverWatchSsrOnly);
|
80 | mySpawnSync(sequence(commands));
|
81 | }], ['dev-no-ssr', function () {
|
82 | var firstCommands = [];
|
83 | hasDocker && firstCommands.push(_commands.DOCKER_UP);
|
84 | hasDocker && _shared.knexConfigPath && firstCommands.push(_commands.DOCKER_WAIT_PG, _commands.dbMigr);
|
85 | hasDocker && _shared.knexConfigPath && hasSeeds && firstCommands.push(_commands.dbSeed);
|
86 | firstCommands.push(_commands.rmBundle);
|
87 | mySpawnSync(sequence(firstCommands));
|
88 | mySpawn(_commands.serverWatchNoSsr);
|
89 | mySpawn(_commands.clientWatch);
|
90 | }], ['local-prod', function () {
|
91 | var commands = [];
|
92 | hasDocker && commands.push(_commands.DOCKER_UP);
|
93 | hasDocker && _shared.knexConfigPath && commands.push(_commands.DOCKER_WAIT_PG, _commands.dbMigr);
|
94 | hasDocker && _shared.knexConfigPath && hasSeeds && commands.push(_commands.dbSeed);
|
95 | commands.push(_commands.rmLibAndBundle, _commands.clientBuild, _commands.babel);
|
96 | hasHeroku ? commands.push(_commands.herokuLocalProd) : commands.push(_commands.nodeLocalProd);
|
97 | mySpawnSync(sequence(commands));
|
98 | }], ['build-prod', function () {
|
99 | return mySpawnSync(sequence([_commands.rmLibAndBundle, _commands.clientBuild, _commands.babel]));
|
100 | }], ['lint', function () {
|
101 | return mySpawnSync(sequence([_commands.lint, _commands.typecheck]));
|
102 | }], ['test', function () {
|
103 | var commands = [_commands.rmBundle, _commands.testUnit, _commands.clientBuild];
|
104 | var testDbIdInitial = getDbTestProcessId('db-test');
|
105 | var testRedisIdInitial = getDbTestProcessId('redis-test');
|
106 | hasDocker && testDbIdInitial && commands.push((0, _commands.dockerDownTest)(testDbIdInitial));
|
107 | hasDocker && testRedisIdInitial && commands.push((0, _commands.dockerDownTest)(testRedisIdInitial));
|
108 | hasDocker && commands.push(_commands.DOCKER_UP_TEST);
|
109 | hasDocker && _shared.knexConfigPath && commands.push(_commands.DOCKER_WAIT_PG_TEST, _commands.dbMigrTest);
|
110 | commands.push(_commands.testE2E);
|
111 | var cmdResult = mySpawnSync(sequence(commands));
|
112 | var testDbIdFinal = getDbTestProcessId('db-test');
|
113 | var testRedisIdFinal = getDbTestProcessId('redis-test');
|
114 | var cleanupCommands = [];
|
115 | hasDocker && testDbIdFinal && cleanupCommands.push((0, _commands.dockerDownTest)(testDbIdFinal));
|
116 | hasDocker && testRedisIdFinal && cleanupCommands.push((0, _commands.dockerDownTest)(testRedisIdFinal));
|
117 | cleanupCommands.length > 0 && mySpawnSync(sequence(cleanupCommands));
|
118 | _env.TESTING_SOUND && mySpawnSync(_commands.SAY_DONE);
|
119 | return cmdResult;
|
120 | }], ['lint-test', function () {
|
121 | var commands = [_commands.lint, _commands.typecheck, _commands.rmBundle, _commands.testUnit, _commands.clientBuild];
|
122 | var testDbIdInitial = getDbTestProcessId('db-test');
|
123 | var testRedisIdInitial = getDbTestProcessId('redis-test');
|
124 | hasDocker && testDbIdInitial && commands.push((0, _commands.dockerDownTest)(testDbIdInitial));
|
125 | hasDocker && testRedisIdInitial && commands.push((0, _commands.dockerDownTest)(testRedisIdInitial));
|
126 | hasDocker && commands.push(_commands.DOCKER_UP_TEST);
|
127 | hasDocker && _shared.knexConfigPath && commands.push(_commands.DOCKER_WAIT_PG_TEST, _commands.dbMigrTest);
|
128 | commands.push(_commands.testE2E);
|
129 | var cmdResult = mySpawnSync(sequence(commands));
|
130 | var testDbIdFinal = getDbTestProcessId('db-test');
|
131 | var testRedisIdFinal = getDbTestProcessId('redis-test');
|
132 | var cleanupCommands = [];
|
133 | hasDocker && testDbIdFinal && cleanupCommands.push((0, _commands.dockerDownTest)(testDbIdFinal));
|
134 | hasDocker && testRedisIdFinal && cleanupCommands.push((0, _commands.dockerDownTest)(testRedisIdFinal));
|
135 | cleanupCommands.length > 0 && mySpawnSync(sequence(cleanupCommands));
|
136 | _env.TESTING_SOUND && mySpawnSync(_commands.SAY_DONE);
|
137 | return cmdResult;
|
138 | }], ['lint-test-storybook', function () {
|
139 | var commands = [_commands.lint, _commands.typecheck, _commands.rmBundle, _commands.testUnit, _commands.clientBuild];
|
140 | var testDbIdInitial = getDbTestProcessId('db-test');
|
141 | var testRedisIdInitial = getDbTestProcessId('redis-test');
|
142 | hasDocker && testDbIdInitial && commands.push((0, _commands.dockerDownTest)(testDbIdInitial));
|
143 | hasDocker && testRedisIdInitial && commands.push((0, _commands.dockerDownTest)(testRedisIdInitial));
|
144 | hasDocker && commands.push(_commands.DOCKER_UP_TEST);
|
145 | hasDocker && _shared.knexConfigPath && commands.push(_commands.DOCKER_WAIT_PG_TEST, _commands.dbMigrTest);
|
146 | commands.push(_commands.testE2E);
|
147 | var cmdResult = mySpawnSync(sequence(commands));
|
148 | var testDbIdFinal = getDbTestProcessId('db-test');
|
149 | var testRedisIdFinal = getDbTestProcessId('redis-test');
|
150 | var postTestsCommands = [];
|
151 | hasDocker && testDbIdFinal && postTestsCommands.push((0, _commands.dockerDownTest)(testDbIdFinal));
|
152 | hasDocker && testRedisIdFinal && postTestsCommands.push((0, _commands.dockerDownTest)(testRedisIdFinal));
|
153 |
|
154 | if ((cmdResult === null || cmdResult === void 0 ? void 0 : cmdResult.status) === 0) {
|
155 | postTestsCommands.push(_commands.BUILD_STORYBOOK);
|
156 | postTestsCommands.push(_commands.GIT_ADD_STORYBOOK);
|
157 | }
|
158 |
|
159 | postTestsCommands.length > 0 && mySpawnSync(sequence(postTestsCommands));
|
160 | _env.TESTING_SOUND && mySpawnSync(_commands.SAY_DONE);
|
161 | return cmdResult;
|
162 | }], ['deploy-staging', function () {
|
163 | var commands = [_commands.PUSH_ORIGIN_MASTER, _commands.PUSH_HEROKU_STAGING_MASTER];
|
164 | _env.HEROKU_DEPLOYMENT_SOUND && commands.push(_commands.SAY_DONE);
|
165 | mySpawnSync(sequence(commands));
|
166 | }], ['promote', function () {
|
167 | var commands = [_commands.HEROKU_PIPELINE_PROMOTE];
|
168 | _env.HEROKU_DEPLOYMENT_SOUND && commands.push(_commands.SAY_DONE);
|
169 | mySpawnSync(sequence(commands));
|
170 | }], ['deploy-prod', function () {
|
171 | var commands = [_commands.PUSH_ORIGIN_MASTER, _commands.PUSH_HEROKU_STAGING_MASTER, _commands.HEROKU_PIPELINE_PROMOTE];
|
172 | _env.HEROKU_DEPLOYMENT_SOUND && commands.push(_commands.SAY_DONE);
|
173 | mySpawnSync(sequence(commands));
|
174 | }], ['migrate-db', function () {
|
175 | return mySpawnSync(_commands.dbMigr);
|
176 | }], ['stats', function () {
|
177 | return mySpawnSync(_commands.stats);
|
178 | }], ['sound', function () {
|
179 | return mySpawnSync(_commands.SAY_DONE);
|
180 | }], ['storybook', function () {
|
181 | return mySpawnSync(_commands.startStorybook);
|
182 | }], ['build-storybook', function () {
|
183 | return mySpawnSync(_commands.BUILD_STORYBOOK);
|
184 | }]], function () {
|
185 |
|
186 | console.error("".concat(taskName, " is not a valid @sharyn/cli command."));
|
187 | process.exit(1);
|
188 | });
|
189 |
|
190 | if (result) {
|
191 | process.exit(result.status);
|
192 | } |
\ | No newline at end of file |