sharyn
Version:
Combines all the other packages under one.
192 lines (172 loc) • 9.04 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime-corejs2/helpers/interopRequireDefault");
var _os = require("os");
var _child_process = require("child_process");
var _swit = _interopRequireDefault(require("@sharyn/util/swit"));
var _safe = _interopRequireDefault(require("colors/safe"));
var _checkSetup = require("@sharyn/check-setup");
var _env = require("@sharyn/env");
var _shared = require("./shared");
var _commands = require("./commands");
// flow-disable-next-line
// flow-disable-next-line
// flow-disable-next-line
var hasDocker = (0, _checkSetup.hasFile)('docker-compose.yml');
var hasHeroku = (0, _checkSetup.hasFile)('Procfile');
var hasSeeds = (0, _checkSetup.hasFile)('/src/_db/seeds');
var getDbTestProcessId = function getDbTestProcessId(containerName) {
var result = (0, _child_process.execSync)("docker ps -q --filter=\"name=".concat(containerName, "\"")).toString();
var ids = result.split(_os.EOL).filter(function (x) {
return x;
});
if (ids.length > 1) {
throw Error("Multiple running processes found for ".concat(containerName));
}
return ids[0];
};
var mySpawn = function mySpawn(cmd) {
// eslint-disable-next-line no-console
console.log("".concat(_safe.default.magenta("[sharyn/cli]"), " ").concat(_safe.default.gray(cmd)).replace(/\.\/node_modules\/\.bin\//g, ''));
return (0, _child_process.spawn)(cmd, {
shell: true,
stdio: 'inherit'
});
};
var mySpawnSync = function mySpawnSync(cmd) {
// eslint-disable-next-line no-console
console.log("".concat(_safe.default.magenta("[sharyn/cli]"), " ").concat(_safe.default.gray(cmd)).replace(/\.\/node_modules\/\.bin\//g, ''));
return (0, _child_process.spawnSync)(cmd, {
shell: true,
stdio: 'inherit'
});
};
var sequence = function sequence(arr) {
return arr.join(' && ');
};
var taskName = process.argv[2];
var result = (0, _swit.default)(taskName, [['dev', function () {
var firstCommands = [];
hasDocker && firstCommands.push(_commands.DOCKER_UP);
hasDocker && _shared.knexConfigPath && firstCommands.push(_commands.DOCKER_WAIT_PG, _commands.dbMigr);
hasDocker && _shared.knexConfigPath && hasSeeds && firstCommands.push(_commands.dbSeed);
firstCommands.push(_commands.rmBundle);
mySpawnSync(sequence(firstCommands));
mySpawn(_commands.serverWatch);
mySpawn(_commands.clientWatch);
}], ['dev-ssr-only', function () {
var commands = [];
hasDocker && commands.push(_commands.DOCKER_UP);
hasDocker && _shared.knexConfigPath && commands.push(_commands.DOCKER_WAIT_PG, _commands.dbMigr);
hasDocker && _shared.knexConfigPath && hasSeeds && commands.push(_commands.dbSeed);
commands.push(_commands.serverWatchSsrOnly);
mySpawnSync(sequence(commands));
}], ['dev-no-ssr', function () {
var firstCommands = [];
hasDocker && firstCommands.push(_commands.DOCKER_UP);
hasDocker && _shared.knexConfigPath && firstCommands.push(_commands.DOCKER_WAIT_PG, _commands.dbMigr);
hasDocker && _shared.knexConfigPath && hasSeeds && firstCommands.push(_commands.dbSeed);
firstCommands.push(_commands.rmBundle);
mySpawnSync(sequence(firstCommands));
mySpawn(_commands.serverWatchNoSsr);
mySpawn(_commands.clientWatch);
}], ['local-prod', function () {
var commands = [];
hasDocker && commands.push(_commands.DOCKER_UP);
hasDocker && _shared.knexConfigPath && commands.push(_commands.DOCKER_WAIT_PG, _commands.dbMigr);
hasDocker && _shared.knexConfigPath && hasSeeds && commands.push(_commands.dbSeed);
commands.push(_commands.rmLibAndBundle, _commands.clientBuild, _commands.babel);
hasHeroku ? commands.push(_commands.herokuLocalProd) : commands.push(_commands.nodeLocalProd);
mySpawnSync(sequence(commands));
}], ['build-prod', function () {
return mySpawnSync(sequence([_commands.rmLibAndBundle, _commands.clientBuild, _commands.babel]));
}], ['lint', function () {
return mySpawnSync(sequence([_commands.lint, _commands.typecheck]));
}], ['test', function () {
var commands = [_commands.rmBundle, _commands.testUnit, _commands.clientBuild];
var testDbIdInitial = getDbTestProcessId('db-test');
var testRedisIdInitial = getDbTestProcessId('redis-test');
hasDocker && testDbIdInitial && commands.push((0, _commands.dockerDownTest)(testDbIdInitial));
hasDocker && testRedisIdInitial && commands.push((0, _commands.dockerDownTest)(testRedisIdInitial));
hasDocker && commands.push(_commands.DOCKER_UP_TEST);
hasDocker && _shared.knexConfigPath && commands.push(_commands.DOCKER_WAIT_PG_TEST, _commands.dbMigrTest);
commands.push(_commands.testE2E);
var cmdResult = mySpawnSync(sequence(commands));
var testDbIdFinal = getDbTestProcessId('db-test');
var testRedisIdFinal = getDbTestProcessId('redis-test');
var cleanupCommands = [];
hasDocker && testDbIdFinal && cleanupCommands.push((0, _commands.dockerDownTest)(testDbIdFinal));
hasDocker && testRedisIdFinal && cleanupCommands.push((0, _commands.dockerDownTest)(testRedisIdFinal));
cleanupCommands.length > 0 && mySpawnSync(sequence(cleanupCommands));
_env.TESTING_SOUND && mySpawnSync(_commands.SAY_DONE);
return cmdResult;
}], ['lint-test', function () {
var commands = [_commands.lint, _commands.typecheck, _commands.rmBundle, _commands.testUnit, _commands.clientBuild];
var testDbIdInitial = getDbTestProcessId('db-test');
var testRedisIdInitial = getDbTestProcessId('redis-test');
hasDocker && testDbIdInitial && commands.push((0, _commands.dockerDownTest)(testDbIdInitial));
hasDocker && testRedisIdInitial && commands.push((0, _commands.dockerDownTest)(testRedisIdInitial));
hasDocker && commands.push(_commands.DOCKER_UP_TEST);
hasDocker && _shared.knexConfigPath && commands.push(_commands.DOCKER_WAIT_PG_TEST, _commands.dbMigrTest);
commands.push(_commands.testE2E);
var cmdResult = mySpawnSync(sequence(commands));
var testDbIdFinal = getDbTestProcessId('db-test');
var testRedisIdFinal = getDbTestProcessId('redis-test');
var cleanupCommands = [];
hasDocker && testDbIdFinal && cleanupCommands.push((0, _commands.dockerDownTest)(testDbIdFinal));
hasDocker && testRedisIdFinal && cleanupCommands.push((0, _commands.dockerDownTest)(testRedisIdFinal));
cleanupCommands.length > 0 && mySpawnSync(sequence(cleanupCommands));
_env.TESTING_SOUND && mySpawnSync(_commands.SAY_DONE);
return cmdResult;
}], ['lint-test-storybook', function () {
var commands = [_commands.lint, _commands.typecheck, _commands.rmBundle, _commands.testUnit, _commands.clientBuild];
var testDbIdInitial = getDbTestProcessId('db-test');
var testRedisIdInitial = getDbTestProcessId('redis-test');
hasDocker && testDbIdInitial && commands.push((0, _commands.dockerDownTest)(testDbIdInitial));
hasDocker && testRedisIdInitial && commands.push((0, _commands.dockerDownTest)(testRedisIdInitial));
hasDocker && commands.push(_commands.DOCKER_UP_TEST);
hasDocker && _shared.knexConfigPath && commands.push(_commands.DOCKER_WAIT_PG_TEST, _commands.dbMigrTest);
commands.push(_commands.testE2E);
var cmdResult = mySpawnSync(sequence(commands));
var testDbIdFinal = getDbTestProcessId('db-test');
var testRedisIdFinal = getDbTestProcessId('redis-test');
var postTestsCommands = [];
hasDocker && testDbIdFinal && postTestsCommands.push((0, _commands.dockerDownTest)(testDbIdFinal));
hasDocker && testRedisIdFinal && postTestsCommands.push((0, _commands.dockerDownTest)(testRedisIdFinal));
if ((cmdResult === null || cmdResult === void 0 ? void 0 : cmdResult.status) === 0) {
postTestsCommands.push(_commands.BUILD_STORYBOOK);
postTestsCommands.push(_commands.GIT_ADD_STORYBOOK);
}
postTestsCommands.length > 0 && mySpawnSync(sequence(postTestsCommands));
_env.TESTING_SOUND && mySpawnSync(_commands.SAY_DONE);
return cmdResult;
}], ['deploy-staging', function () {
var commands = [_commands.PUSH_ORIGIN_MASTER, _commands.PUSH_HEROKU_STAGING_MASTER];
_env.HEROKU_DEPLOYMENT_SOUND && commands.push(_commands.SAY_DONE);
mySpawnSync(sequence(commands));
}], ['promote', function () {
var commands = [_commands.HEROKU_PIPELINE_PROMOTE];
_env.HEROKU_DEPLOYMENT_SOUND && commands.push(_commands.SAY_DONE);
mySpawnSync(sequence(commands));
}], ['deploy-prod', function () {
var commands = [_commands.PUSH_ORIGIN_MASTER, _commands.PUSH_HEROKU_STAGING_MASTER, _commands.HEROKU_PIPELINE_PROMOTE];
_env.HEROKU_DEPLOYMENT_SOUND && commands.push(_commands.SAY_DONE);
mySpawnSync(sequence(commands));
}], ['migrate-db', function () {
return mySpawnSync(_commands.dbMigr);
}], ['stats', function () {
return mySpawnSync(_commands.stats);
}], ['sound', function () {
return mySpawnSync(_commands.SAY_DONE);
}], ['storybook', function () {
return mySpawnSync(_commands.startStorybook);
}], ['build-storybook', function () {
return mySpawnSync(_commands.BUILD_STORYBOOK);
}]], function () {
// eslint-disable-next-line no-console
console.error("".concat(taskName, " is not a valid @sharyn/cli command."));
process.exit(1);
});
if (result) {
process.exit(result.status);
}