Create packages/package.json on server start
This commit is contained in:
parent
7fbba14b69
commit
e3a2fa7dd1
@ -2,6 +2,7 @@
|
||||
|
||||
const log = require("../log");
|
||||
const fs = require("fs");
|
||||
const fsextra = require("fs-extra");
|
||||
const path = require("path");
|
||||
const colors = require("chalk");
|
||||
const program = require("commander");
|
||||
@ -36,6 +37,9 @@ try {
|
||||
// fs.statSync will throw if config.js does not exist (e.g. first run)
|
||||
}
|
||||
|
||||
// Create packages/package.json
|
||||
createPackagesFolder();
|
||||
|
||||
// Merge config key-values passed as CLI options into the main config
|
||||
Helper.mergeConfig(Helper.config, program.config);
|
||||
|
||||
@ -62,6 +66,31 @@ if (program.rawArgs.length < 3) {
|
||||
program.help();
|
||||
}
|
||||
|
||||
function createPackagesFolder() {
|
||||
const packagesPath = Helper.getPackagesPath();
|
||||
const packagesConfig = path.join(packagesPath, "package.json");
|
||||
|
||||
// Create node_modules folder, otherwise yarn will start walking upwards to find one
|
||||
fsextra.ensureDirSync(path.join(packagesPath, "node_modules"));
|
||||
|
||||
// Create package.json with private set to true, if it doesn't exist already
|
||||
if (!fs.existsSync(packagesConfig)) {
|
||||
fs.writeFileSync(
|
||||
packagesConfig,
|
||||
JSON.stringify(
|
||||
{
|
||||
private: true,
|
||||
description:
|
||||
"Packages for The Lounge. All packages in node_modules directory will be automatically loaded.",
|
||||
dependencies: {},
|
||||
},
|
||||
null,
|
||||
"\t"
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function verifyFileOwner() {
|
||||
if (!process.getuid) {
|
||||
return;
|
||||
|
@ -12,8 +12,6 @@ program
|
||||
.on("--help", Utils.extraHelp)
|
||||
.action(function(packageName) {
|
||||
const fs = require("fs");
|
||||
const fsextra = require("fs-extra");
|
||||
const path = require("path");
|
||||
const packageJson = require("package-json");
|
||||
|
||||
if (!fs.existsSync(Helper.getConfigPath())) {
|
||||
@ -44,28 +42,6 @@ program
|
||||
|
||||
log.info(`Installing ${colors.green(json.name + " v" + json.version)}...`);
|
||||
|
||||
const packagesPath = Helper.getPackagesPath();
|
||||
const packagesConfig = path.join(packagesPath, "package.json");
|
||||
|
||||
// Create node_modules folder, otherwise yarn will start walking upwards to find one
|
||||
fsextra.ensureDirSync(path.join(packagesPath, "node_modules"));
|
||||
|
||||
// Create package.json with private set to true, if it doesn't exist already
|
||||
if (!fs.existsSync(packagesConfig)) {
|
||||
fs.writeFileSync(
|
||||
packagesConfig,
|
||||
JSON.stringify(
|
||||
{
|
||||
private: true,
|
||||
description:
|
||||
"Packages for The Lounge. All packages in node_modules directory will be automatically loaded.",
|
||||
},
|
||||
null,
|
||||
"\t"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return Utils.executeYarnCommand("add", "--exact", `${json.name}@${json.version}`)
|
||||
.then(() => {
|
||||
log.info(
|
||||
|
@ -74,7 +74,7 @@ function getEnabledPackages(packageJson) {
|
||||
const json = JSON.parse(fs.readFileSync(packageJson, "utf-8"));
|
||||
return Object.keys(json.dependencies);
|
||||
} catch (e) {
|
||||
//
|
||||
log.error(`Failed to read packages/package.json: ${colors.red(e)}`);
|
||||
}
|
||||
|
||||
return [];
|
||||
|
Loading…
Reference in New Issue
Block a user