UNPKG

literate-elm

Version:

Runs literate Elm code blocks and calculates Elm expressions

67 lines 3.38 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()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.runElm = exports.installElmPackage = exports.patchElmJson = exports.initializeElmProject = void 0; const run_elm_1 = __importDefault(require("@kachkaev/run-elm")); const execa_1 = __importDefault(require("execa")); const fs_extra_1 = require("fs-extra"); const path_1 = require("path"); const initializeElmProject = (projectDirectory) => __awaiter(void 0, void 0, void 0, function* () { const childProcess = (0, execa_1.default)("elm", ["init"], { cwd: projectDirectory, stdin: undefined, }); if (childProcess.stdin) { childProcess.stdin.write("\n"); } yield childProcess; }); exports.initializeElmProject = initializeElmProject; const patchElmJson = (projectPath, callback) => __awaiter(void 0, void 0, void 0, function* () { const pathToElmJson = (0, path_1.resolve)(projectPath, "elm.json"); const packageContents = yield JSON.parse(yield (0, fs_extra_1.readFile)(pathToElmJson, "utf8")); yield (0, fs_extra_1.writeFile)(pathToElmJson, JSON.stringify(callback(packageContents) || packageContents), "utf8"); }); exports.patchElmJson = patchElmJson; const installElmPackage = (projectDirectory, packageName, packageVersion) => __awaiter(void 0, void 0, void 0, function* () { if (packageVersion !== "latest") { // https://github.com/elm/compiler/issues/1759 throw new Error("Installing dependencies rather than latest is currently not supported by elm install v0.19"); // waiting for elm install to support version picking // await patchElmJson(projectDirectory, (elmJson) => { // elmJson.dependencies.direct[packageName] = resolveVersion(packageVersion); // }); } const childProcess = (0, execa_1.default)("elm", ["install", packageName], { cwd: projectDirectory, stdin: undefined, }); if (childProcess.stdin) { childProcess.stdin.write("\n"); } yield childProcess; // TODO: return meaningful error when elm package is not installed // see https://github.com/jwoLondon/litvis/issues/27 }); exports.installElmPackage = installElmPackage; const runElm = (projectDirectory, modulePath, outputSymbolName) => __awaiter(void 0, void 0, void 0, function* () { const result = yield (0, run_elm_1.default)(modulePath, { report: "json", outputName: outputSymbolName, projectDir: projectDirectory, }); return result; }); exports.runElm = runElm; //# sourceMappingURL=tools.js.map