UNPKG

@cardstack/cli

Version:

Command line tools for Cardstack.

68 lines 2.87 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const path_1 = require("path"); const typescript_memoize_1 = require("typescript-memoize"); const fs_extra_1 = require("fs-extra"); const exec_1 = __importDefault(require("./utils/exec")); const appName = "cardhost"; const cardstackDeps = ["hub", "jsonapi", "ephemeral"]; async function run(options) { let runner = new Runner(options); return runner.run(); } exports.default = run; class Runner { constructor({ "hub-dir": hubDir, ui }) { this.runningDir = hubDir; this.ui = ui; fs_extra_1.ensureDirSync(this.runningDir); } get appDir() { return path_1.join(this.runningDir, appName); } async run() { this.ensureAppReady(); } // if no app exists yet, copy it from blueprints into temp, and yarn install ensureAppReady() { let readyMarker = path_1.join(this.appDir, ".cardstack-ready"); if (!fs_extra_1.pathExistsSync(readyMarker)) { fs_extra_1.removeSync(this.appDir); this.applyBlueprints(); this.installDependencies(); fs_extra_1.writeFileSync(readyMarker, ""); } } applyBlueprints() { let blueprints = path_1.dirname(require.resolve('@cardstack/cardhost/package.json')); fs_extra_1.copySync(blueprints, this.appDir); } installDependencies() { let yarn = require.resolve("yarn/bin/yarn"); // when CARDSTACK_DEV is true, yarn link the Card SDK locally instead of using the published packages if (process.env.CARDSTACK_DEV) { for (let pkgName of cardstackDeps) { exec_1.default(yarn, ["link"], { cwd: path_1.join(__dirname, "..", pkgName) }, this.ui); } exec_1.default(yarn, ["link", ...cardstackDeps.map(d => `@cardstack/${d}`)], { cwd: this.appDir }, this.ui); } exec_1.default(yarn, ["install"], { cwd: this.appDir }, this.ui); } } __decorate([ typescript_memoize_1.Memoize() ], Runner.prototype, "appDir", null); //# sourceMappingURL=start.js.map