Skip to content

Commit

Permalink
Merge pull request #744 from postmanlabs/deepinstall-made-package-man…
Browse files Browse the repository at this point in the history
…ager-aware

Perform installation according to package manager
  • Loading branch information
aman-v-singh authored May 27, 2024
2 parents e913e13 + 0ba874b commit c9f0527
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 16 deletions.
2 changes: 1 addition & 1 deletion npm/ci-requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pushd ./codegens/csharp-restsharp &>/dev/null;
sudo apt-get install dotnet-sdk-6.0
dotnet new console -o testProject -f net6.0
pushd ./testProject &>/dev/null;
dotnet add package RestSharp
dotnet add package RestSharp --version 110.0.0
popd &>/dev/null;
popd &>/dev/null;

Expand Down
29 changes: 19 additions & 10 deletions npm/deepinstall.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
var shell = require('shelljs'),
path = require('path'),
async = require('async'),
{ detect } = require('detect-package-manager'),
pm,
PRODUCTION_FLAG = '',
getSubfolders,
fs = require('fs'),
pwd = shell.pwd();
const args = process.argv,
PATH_TO_CODEGENS_FOLDER = path.resolve(__dirname, '../codegens');

if (args[2] && args[2] === 'dev') {
console.log('Dev flag detected running npm install');
}
else {
PRODUCTION_FLAG = '--no-audit --production';
}

getSubfolders = (folder) => {
return fs.readdirSync(folder)
.map((subfolder) => { return { path: path.join(folder, subfolder), name: subfolder}; })
Expand All @@ -23,6 +18,20 @@ getSubfolders = (folder) => {

async.series([
function (next) {
detect().then((res) => {
pm = res;
console.log('Detected package manager: ' + pm);
return next();
});
},
function (next) {
if (args[2] && args[2] === 'dev') {
console.log('Dev flag detected running ' + pm + ' install');
}
else {
PRODUCTION_FLAG = '--no-audit --production';
}

console.log('Running pre-package script');
var prepackagePath = path.resolve(__dirname, 'pre-package.js'),
commandOutput = shell.exec(`node "${prepackagePath}"`);
Expand All @@ -42,11 +51,11 @@ async.series([

var commandOut;

console.log(codegen.name + ': npm install ' + PRODUCTION_FLAG);
commandOut = shell.exec('npm install ' + PRODUCTION_FLAG, { silent: true });
console.log(codegen.name + ': ' + pm + ' install ' + PRODUCTION_FLAG);
commandOut = shell.exec(pm + ' install ' + PRODUCTION_FLAG, { silent: true });

if (commandOut.code !== 0) {
console.error('Failed to run npm install on codegen ' + codegen.name + ', here is the error:');
console.error('Failed to run ' + pm + ' install on codegen ' + codegen.name + ', here is the error:');
return next(commandOut.stderr);
}
console.log(commandOut.stdout);
Expand Down
116 changes: 114 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
"license": "Apache-2.0",
"homepage": "https://github.com/postmanlabs/code-generators",
"dependencies": {
"lodash": "4.17.21",
"async": "3.2.2",
"detect-package-manager": "3.0.2",
"lodash": "4.17.21",
"path": "0.12.7",
"postman-collection": "4.0.0",
"shelljs": "0.8.5"
Expand All @@ -35,18 +36,18 @@
"browserify": "14.5.0",
"chai": "4.3.7",
"chalk": "2.4.2",
"eslint": "5.16.0",
"dependency-check": "3.0.0",
"editorconfig": "0.15.3",
"eslint": "5.16.0",
"eslint-plugin-jsdoc": "3.15.1",
"eslint-plugin-lodash": "2.7.0",
"eslint-plugin-mocha": "4.12.1",
"eslint-plugin-security": "1.5.0",
"istanbul": "0.4.5",
"js-yaml": "3.14.1",
"newman": "5.3.2",
"jsdoc": "3.6.10",
"mocha": "6.2.3",
"newman": "5.3.2",
"nyc": "14.1.1",
"parse-gitignore": "1.0.1",
"pretty-ms": "3.2.0",
Expand Down

0 comments on commit c9f0527

Please sign in to comment.