UNPKG

profoundjs

Version:

Profound.js Framework and Server

81 lines (66 loc) 2.18 kB
"use strict"; /* This is NPM lifecycle script: postinstall * Installs minimal files into the users's deployment directory: - package.json - start.js - complete_install.js * All additional installation is done by script 'npm run setup'. * After installation, user runs 'node complete_install.js', which creates configuration and kicks off 'npm run setup'. NOTE: Output from this script will be suppressed by NPM 7+, unless process ends with non-zero exit code. */ const fs = require("fs"); const iutils = require("./install_utils.js"); const path = require("path"); /* NOTE: install_info.json This file contains instructions for completing the installation. It tells the process what questions to ask and what commands to run. This file is shared with the GUI installer. If any changes are made to how install_info.json is processed in this script, the GUI installer will also need to be adjusted, retested, and updated. */ const install_info = require("./install_info.json"); const deployDir = iutils.getDeployDir(); if (!deployDir) { console.error("Can't find deployment directory."); process.exit(1); } // Install files. if (fileExists(path.join(deployDir, "package.json"))) { console.log("package.json exists."); } else { // Create user's skeleton package.json const packageJSON = JSON.stringify(install_info.packageJSON, null, 2) + "\n"; fs.writeFileSync(path.join(deployDir, "package.json"), packageJSON); console.log("package.json created."); } installFile("start.js"); installFile("complete_install.js", true); console.log("\nTo complete installation, run: node complete_install.js\n"); function fileExists(file) { try { const stats = fs.statSync(file); return stats.isFile(); } catch (error) { return false; } } function installFile(file, overwrite) { const dest = path.join(deployDir, file); if (overwrite !== true && fileExists(dest)) { console.log(`${file} exists.`); } else { fs.writeFileSync( dest, fs.readFileSync(path.join(__dirname, file)), { flag: overwrite === true ? "w" : "wx" } ); console.log(`${file} created.`); } }