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 _libLang = require("@verekia/lib-lang");
|
11 |
|
12 | var _safe = _interopRequireDefault(require("colors/safe"));
|
13 |
|
14 | var _checkSetup = require("@sharyn/check-setup");
|
15 |
|
16 | var _shared = require("./shared");
|
17 |
|
18 | var _commands = require("./commands");
|
19 |
|
20 |
|
21 | var hasDocker = (0, _checkSetup.hasFile)('docker-compose.yml');
|
22 | var hasHeroku = (0, _checkSetup.hasFile)('Procfile');
|
23 | var hasSeeds = (0, _checkSetup.hasFile)('/src/_db/seeds');
|
24 |
|
25 | var getDbTestProcessId = function getDbTestProcessId() {
|
26 | var dbTestContainerName = 'db-test';
|
27 | var result = (0, _child_process.execSync)("docker ps -q --filter=\"name=".concat(dbTestContainerName, "\"")).toString();
|
28 | var ids = result.split(_os.EOL).filter(function (x) {
|
29 | return x;
|
30 | });
|
31 |
|
32 | if (ids.length > 1) {
|
33 | throw Error("Multiple running processes found for ".concat(dbTestContainerName));
|
34 | }
|
35 |
|
36 | return ids[0];
|
37 | };
|
38 |
|
39 | var mySpawn = function mySpawn(cmd) {
|
40 |
|
41 | console.log("".concat(_safe.default.magenta("[sharyn/cli]"), " ").concat(_safe.default.gray(cmd)).replace(/\.\/node_modules\/\.bin\//g, ''));
|
42 | return (0, _child_process.spawn)(cmd, {
|
43 | shell: true,
|
44 | stdio: 'inherit'
|
45 | });
|
46 | };
|
47 |
|
48 | var sequence = function sequence(arr) {
|
49 | return arr.join(' && ');
|
50 | };
|
51 |
|
52 | var taskName = process.argv[2];
|
53 | (0, _libLang.swit)(taskName, [['dev', function () {
|
54 | var firstCommands = [];
|
55 | hasDocker && firstCommands.push(_commands.DOCKER_UP);
|
56 | _shared.knexConfigPath && firstCommands.push(_commands.DOCKER_WAIT_PG, _commands.dbMigr);
|
57 | _shared.knexConfigPath && hasSeeds && firstCommands.push(_commands.dbSeed);
|
58 | firstCommands.push(_commands.rmBundle);
|
59 | mySpawn(sequence(firstCommands)).on('close', function (code) {
|
60 | if (code === 0) {
|
61 | mySpawn(_commands.serverWatch);
|
62 | mySpawn(_commands.clientWatch);
|
63 | }
|
64 | });
|
65 | }], ['dev-ssr-only', function () {
|
66 | var commands = [];
|
67 | hasDocker && commands.push(_commands.DOCKER_UP);
|
68 | _shared.knexConfigPath && commands.push(_commands.DOCKER_WAIT_PG, _commands.dbMigr);
|
69 | _shared.knexConfigPath && hasSeeds && commands.push(_commands.dbSeed);
|
70 | commands.push(_commands.serverWatchSsrOnly);
|
71 | mySpawn(sequence(commands));
|
72 | }], ['dev-no-ssr', function () {
|
73 | var firstCommands = [];
|
74 | hasDocker && firstCommands.push(_commands.DOCKER_UP);
|
75 | _shared.knexConfigPath && firstCommands.push(_commands.DOCKER_WAIT_PG, _commands.dbMigr);
|
76 | _shared.knexConfigPath && hasSeeds && firstCommands.push(_commands.dbSeed);
|
77 | firstCommands.push(_commands.rmBundle);
|
78 | mySpawn(sequence(firstCommands)).on('close', function (code) {
|
79 | if (code === 0) {
|
80 | mySpawn(_commands.serverWatchNoSsr);
|
81 | mySpawn(_commands.clientWatch);
|
82 | }
|
83 | });
|
84 | }], ['local-prod', function () {
|
85 | var commands = [];
|
86 | hasDocker && commands.push(_commands.DOCKER_UP);
|
87 | _shared.knexConfigPath && commands.push(_commands.DOCKER_WAIT_PG, _commands.dbMigr);
|
88 | _shared.knexConfigPath && hasSeeds && commands.push(_commands.dbSeed);
|
89 | commands.push(_commands.rmLibAndBundle, _commands.clientBuild, _commands.babel);
|
90 | hasHeroku ? commands.push(_commands.herokuLocalProd) : commands.push(_commands.nodeLocalProd);
|
91 | mySpawn(sequence(commands));
|
92 | }], ['build-prod', function () {
|
93 | return mySpawn(sequence([_commands.rmLibAndBundle, _commands.clientBuild, _commands.babel]));
|
94 | }], ['lint', function () {
|
95 | return mySpawn(sequence([_commands.lint, _commands.typecheck]));
|
96 | }], ['test', function () {
|
97 | var commands = [];
|
98 | var testDbId = getDbTestProcessId();
|
99 | hasDocker && testDbId && commands.push((0, _commands.dockerDownTest)(testDbId));
|
100 | hasDocker && commands.push(_commands.DOCKER_UP_TEST);
|
101 | _shared.knexConfigPath && commands.push(_commands.DOCKER_WAIT_PG_TEST, _commands.dbMigrTest);
|
102 | commands.push(_commands.rmBundle, _commands.testUnit, _commands.clientBuild, _commands.testE2E);
|
103 | mySpawn(sequence(commands));
|
104 | }], ['lint-test', function () {
|
105 | var commands = [_commands.lint, _commands.typecheck];
|
106 | var testDbId = getDbTestProcessId();
|
107 | hasDocker && testDbId && commands.push((0, _commands.dockerDownTest)(testDbId));
|
108 | hasDocker && commands.push(_commands.DOCKER_UP_TEST);
|
109 | _shared.knexConfigPath && commands.push(_commands.DOCKER_WAIT_PG_TEST, _commands.dbMigrTest);
|
110 | commands.push(_commands.rmBundle, _commands.testUnit, _commands.clientBuild, _commands.testE2E);
|
111 | mySpawn(sequence(commands));
|
112 | }], ['migrate-db', function () {
|
113 | return mySpawn(_commands.dbMigr);
|
114 | }], ['stats', function () {
|
115 | return mySpawn(_commands.stats);
|
116 | }]], function () {
|
117 |
|
118 | console.error("".concat(taskName, " is not a valid @sharyn/cli command."));
|
119 | process.exit(1);
|
120 | }); |
\ | No newline at end of file |