@lenne.tech/cli
Version:
lenne.Tech CLI: lt
85 lines (84 loc) • 4.42 kB
JavaScript
;
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 caddy_1 = require("../../lib/caddy");
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");
const dev_service_1 = require("../../lib/dev-service");
/**
* Initialize an existing project for `lt dev` and apply idempotent
* env-aware patches. (Formerly `lt dev migrate`; `migrate` stays as an
* alias for backwards compatibility.)
*
* Idempotent — re-running with no changes is a no-op. Safe to invoke
* automatically after `lt fullstack init` or by developers manually.
*
* Auto-chaining: if the machine has not been prepared yet (`lt dev
* install` never ran), it runs install FIRST, then initializes the
* project. The chain is one hop deep and cannot recurse, because this
* command calls the `runInstall` *helper* — never the install command
* (see `dev-bootstrap.ts`). Pass `--skip-install` to opt out.
*
* Steps (delegated to `lib/dev-migrate-helper.ts#runMigrate`):
* 1. Resolve workspace layout (api/app dirs, root)
* 2. Build identity (slug + subdomains)
* 3. Patch hardcoded ports → env-aware fallbacks (config.env.ts,
* nuxt.config.ts, playwright.config.ts)
* 4. Inject CLAUDE.md URL block (root + each subproject)
* 5. Persist project to ~/.lenneTech/projects.json
* 6. Add `.lt-dev/` to .gitignore
*/
const InitCommand = {
alias: ['migrate', 'm'],
description: 'Init project for lt dev (idempotent)',
hidden: false,
name: 'init',
run: (toolbox) => __awaiter(void 0, void 0, void 0, function* () {
const { filesystem, parameters, print: { colors, error, info, success, warning }, } = toolbox;
const layout = (0, dev_project_1.resolveLayout)(filesystem.cwd(), filesystem);
if (!layout.apiDir && !layout.appDir) {
error('No API (src/config.env.ts) or App (nuxt.config.ts) project detected at this path.');
if (!parameters.options.fromGluegunMenu)
process.exit(1);
return 'dev init: not a project';
}
// Auto-chain: prepare the machine first if `lt dev install` never ran.
// `--skip-install` opts out. Calling the runInstall HELPER (not the
// install command) makes infinite recursion structurally impossible.
const runInstallFirst = (0, dev_bootstrap_1.shouldRunInstallBeforeInit)({
machinePrepared: (0, dev_bootstrap_1.isMachinePrepared)(),
platformSupported: (0, dev_service_1.platformSupported)() !== 'unsupported',
skipInstall: parameters.options.skipInstall === true,
});
if (runInstallFirst) {
info(colors.dim('Machine not prepared for lt dev yet — running `lt dev install` first ...'));
yield (0, dev_install_helper_1.runInstall)(toolbox, { auto: true });
}
const result = (0, dev_migrate_helper_1.runMigrate)({ layout });
(0, dev_migrate_helper_1.printMigrateResult)(toolbox, result);
info('');
success('Project initialized for lt dev.');
// Closing hint based on Caddy availability.
const caddyOk = yield (0, caddy_1.caddyAvailable)();
if (!caddyOk) {
warning('Caddy is not installed yet. Run `lt dev install` (installs caddy first), then `lt dev up`.');
}
else {
info('Start the project with `lt dev up`.');
}
if (!parameters.options.fromGluegunMenu)
process.exit();
return `dev init: ${result.identity.slug}`;
}),
};
module.exports = InitCommand;