UNPKG

@lenne.tech/cli

Version:

lenne.Tech CLI: lt

78 lines (77 loc) 4.08 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const dev_bootstrap_1 = require("../../lib/dev-bootstrap"); const dev_install_helper_1 = require("../../lib/dev-install-helper"); const dev_migrate_helper_1 = require("../../lib/dev-migrate-helper"); const dev_project_1 = require("../../lib/dev-project"); /** * One-time per-machine setup for `lt dev`. * * Owns the full Caddy lifecycle through a dedicated LaunchAgent * (macOS) / systemd-user unit (Linux), bypassing `brew services caddy` * (whose plist hardcodes a different Caddyfile path and crash-loops). * The actual steps live in `lib/dev-install-helper.ts#runInstall` so * `lt dev init` can reuse them without a cross-command call. * * Auto-chaining: when run from inside an lt-dev-capable project that is * not yet registered, it initializes that project afterwards (the same * work `lt dev init` does). The chain is one hop deep and cannot recurse * because it calls the `runMigrate` *helper* — never the init command * (see `dev-bootstrap.ts`). Pass `--skip-init` to opt out. */ const InstallCommand = { alias: ['i'], description: 'Setup Caddy service for lt dev', hidden: false, name: 'install', run: (toolbox) => __awaiter(void 0, void 0, void 0, function* () { const { filesystem, parameters, print: { colors, info, success, warning }, } = toolbox; const result = yield (0, dev_install_helper_1.runInstall)(toolbox); // Fatal preconditions — nothing more to do, and an auto-init would be // premature (the user must install caddy / use a supported OS first). if (result.unsupported) { if (!parameters.options.fromGluegunMenu) process.exit(1); return 'dev install: unsupported platform'; } if (result.caddyMissing) { if (!parameters.options.fromGluegunMenu) process.exit(1); return 'dev install: caddy missing'; } // Auto-chain: if we're inside an un-initialized lt-dev project, run the // project init now. Calling the runMigrate HELPER (not the init command) // makes infinite recursion structurally impossible. `--skip-init` opts out. const layout = (0, dev_project_1.resolveLayout)(filesystem.cwd(), filesystem); const runInitAfter = (0, dev_bootstrap_1.shouldRunInitAfterInstall)({ isProject: (0, dev_bootstrap_1.isLtDevProject)(layout), projectInitialized: (0, dev_bootstrap_1.isProjectInitialized)(layout), skipInit: parameters.options.skipInit === true, }); if (runInitAfter) { info(''); info(colors.dim('Un-initialized lt dev project detected here — running `lt dev init` ...')); (0, dev_migrate_helper_1.printMigrateResult)(toolbox, (0, dev_migrate_helper_1.runMigrate)({ layout })); } info(''); if (result.blocked) { warning('Setup incomplete. Address the items above and re-run `lt dev install`.'); } else { success('Setup complete. Use `lt dev init` in a project, then `lt dev up`.'); } if (!parameters.options.fromGluegunMenu) process.exit(result.blocked ? 1 : 0); return result.blocked ? 'dev install: incomplete' : 'dev install: ok'; }), }; module.exports = InstallCommand;