Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/project/init-script.ts
Views: 687
/*1* This file is part of CoCalc: Copyright © 2022 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/*6This runs a script configured via the --init [str] parameter.7*/89import { spawn } from "node:child_process";10import { openSync, constants } from "node:fs";11import { join } from "node:path";12import { homedir } from "node:os";13import { access } from "node:fs/promises";1415import { change_filename_extension } from "@cocalc/util/misc";1617import { getOptions } from "./init-program";18import { getLogger } from "./logger";1920const { info } = getLogger("init-script");2122export async function run() {23if (!getOptions().init) return;2425const initScript = join(homedir(), getOptions().init);2627try {28await access(initScript, constants.R_OK);29} catch {30info(`"${initScript}" does not exist`);31return;32}3334try {35info(`running "${initScript}"`);3637const out = openSync(change_filename_extension(initScript, "log"), "w");38const err = openSync(change_filename_extension(initScript, "err"), "w");3940// we don't detach the process, because otherwise it stays around when restarting the project41spawn("bash", [initScript], {42stdio: ["ignore", out, err],43});44} catch (err) {45info(`Problem running "${initScript}" -- ${err}`);46}47}484950