Files
NodeBB/src/cli/package-install.js
Julian Lam 0921230976 fix(style): updated code to follow new eslint recommendations
Squashed commit of the following:

commit f9ce878b26
Author: Julian Lam <julian@nodebb.org>
Date:   Tue Aug 13 14:30:46 2019 -0400

    fix(style): updated code to follow new eslint recommendations

commit 80dd370e41
Author: Julian Lam <julian@nodebb.org>
Date:   Tue Aug 13 14:14:58 2019 -0400

    fix(deps): update dependency sitemap to v4

    Squashed commit of the following:

    commit f4dd9cabb2
    Author: Julian Lam <julian@nodebb.org>
    Date:   Tue Aug 13 11:33:05 2019 -0400

        fix: resolved breaking changes from sitemap v4 upgrade

    commit 9043415ee1
    Merge: e3352b272 72590b346
    Author: Julian Lam <julian@nodebb.org>
    Date:   Tue Aug 13 11:09:55 2019 -0400

        Merge branch 'master' into renovate/sitemap-4.x

    commit e3352b272e
    Author: Renovate Bot <bot@renovateapp.com>
    Date:   Mon Aug 12 07:59:05 2019 +0000

        fix(deps): update dependency sitemap to v4

commit 8e3c0cdcae
Author: Renovate Bot <bot@renovateapp.com>
Date:   Fri Aug 9 00:49:51 2019 +0000

    fix(deps): update dependency commander to v3

commit 2104449d38
Author: Renovate Bot <bot@renovateapp.com>
Date:   Tue Aug 13 15:00:27 2019 +0000

    fix(deps): update dependency mongodb to v3.3.0

commit d2937f446a
Author: Barış Soner Uşaklı <barisusakli@gmail.com>
Date:   Tue Aug 13 10:36:48 2019 -0400

    feat: async/await admin/controllers

commit 1b97e8b199
Author: Misty (Bot) <deploy@nodebb.org>
Date:   Tue Aug 13 09:28:39 2019 +0000

    Latest translations and fallbacks

commit 69a48957a2
Author: Barış Soner Uşaklı <barisusakli@gmail.com>
Date:   Mon Aug 12 21:56:09 2019 -0400

    feat: async/await

commit b9b2a7e593
Author: Barış Soner Uşaklı <barisusakli@gmail.com>
Date:   Mon Aug 12 20:58:29 2019 -0400

    feat: async/await refactor

    controllers/accounts

commit a8d43a1759
Author: Baris Usakli <barisusakli@gmail.com>
Date:   Mon Aug 12 14:49:40 2019 -0400

    feat: async/await controllers/accounts

commit 2f25aae57b
Author: Barış Soner Uşaklı <barisusakli@gmail.com>
Date:   Sun Aug 11 23:09:50 2019 -0400

    fix: #7831, fix pagination

    convert to async/await

commit c9e83f2374
Author: Barış Soner Uşaklı <barisusakli@gmail.com>
Date:   Sun Aug 11 00:14:35 2019 -0400

    fix: remove empty line

commit 30be91b26c
Author: Barış Soner Uşaklı <barisusakli@gmail.com>
Date:   Sun Aug 11 00:13:41 2019 -0400

    fix: remove useless catchs and empty line

commit 2e4a71c0b6
Author: Renovate Bot <bot@renovateapp.com>
Date:   Sat Aug 10 06:51:50 2019 +0000

    chore(deps): update dependency eslint-config-airbnb-base to v14
2019-08-13 15:12:27 -04:00

93 lines
2.8 KiB
JavaScript

'use strict';
var path = require('path');
var fs = require('fs');
var cproc = require('child_process');
var packageFilePath = path.join(__dirname, '../../package.json');
var packageDefaultFilePath = path.join(__dirname, '../../install/package.json');
var modulesPath = path.join(__dirname, '../../node_modules');
function updatePackageFile() {
var oldPackageContents = {};
try {
oldPackageContents = JSON.parse(fs.readFileSync(packageFilePath, 'utf8'));
} catch (e) {
if (e.code !== 'ENOENT') {
throw e;
}
}
var defaultPackageContents = JSON.parse(fs.readFileSync(packageDefaultFilePath, 'utf8'));
var packageContents = { ...oldPackageContents, ...defaultPackageContents, dependencies: { ...oldPackageContents.dependencies, ...defaultPackageContents.dependencies } };
fs.writeFileSync(packageFilePath, JSON.stringify(packageContents, null, 2));
}
exports.updatePackageFile = updatePackageFile;
function installAll() {
var prod = global.env !== 'development';
var command = 'npm install';
try {
fs.accessSync(path.join(modulesPath, 'nconf/package.json'), fs.constants.R_OK);
var packageManager = require('nconf').get('package_manager');
if (packageManager === 'yarn') {
command = 'yarn';
}
} catch (e) {
// ignore
}
try {
cproc.execSync(command + (prod ? ' --production' : ''), {
cwd: path.join(__dirname, '../../'),
stdio: [0, 1, 2],
});
} catch (e) {
console.log('Error installing dependencies!');
console.log('message: ' + e.message);
console.log('stdout: ' + e.stdout);
console.log('stderr: ' + e.stderr);
throw e;
}
}
exports.installAll = installAll;
function preserveExtraneousPlugins() {
// Skip if `node_modules/` is not found or inaccessible
try {
fs.accessSync(modulesPath, fs.constants.R_OK);
} catch (e) {
return;
}
var isPackage = /^nodebb-(plugin|theme|widget|reward)-\w+/;
var packages = fs.readdirSync(modulesPath).filter(function (pkgName) {
return isPackage.test(pkgName);
});
var packageContents = JSON.parse(fs.readFileSync(packageFilePath, 'utf8'));
var extraneous = packages
// only extraneous plugins (ones not in package.json) which are not links
.filter(function (pkgName) {
const extraneous = !packageContents.dependencies.hasOwnProperty(pkgName);
const isLink = fs.lstatSync(path.join(modulesPath, pkgName)).isSymbolicLink();
return extraneous && !isLink;
})
// reduce to a map of package names to package versions
.reduce(function (map, pkgName) {
var pkgConfig = JSON.parse(fs.readFileSync(path.join(modulesPath, pkgName, 'package.json'), 'utf8'));
map[pkgName] = pkgConfig.version;
return map;
}, {});
// Add those packages to package.json
Object.assign(packageContents.dependencies, extraneous);
fs.writeFileSync(packageFilePath, JSON.stringify(packageContents, null, 2));
}
exports.preserveExtraneousPlugins = preserveExtraneousPlugins;