Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add post install/update scripts to simplify package management #13581

Merged
merged 8 commits into from
Apr 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .scripts/install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env node

'use strict';

const glob = require("glob"),
exec = require('child_process').exec,
packageFileName = 'package.json';

const assetPaths = glob.sync("./src/OrchardCore.{Modules,Themes}/*/" + packageFileName, {});

assetPaths.forEach(function (assetPath) {
let path = assetPath.substring(0, assetPath.length - packageFileName.length);
console.log(`Running 'npm install' on '${assetPath}'`);

exec('npm install', {
'cwd': path
}, (error, stdout, stderr) => {
if (error) {
console.log(`Failed to run 'npm install' on '${assetPath}'`, error);
}
})
});
55 changes: 55 additions & 0 deletions .scripts/project.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env node

'use strict';

if(process.argv.length !== 4) {

console.log('Invalid arguments. This command accepts a single project-name argument.');

return;
}

const actionName = process.argv[2];

if(actionName != 'install' && actionName != 'update') {

console.log('Invalid arguments. The first argument should be either "install" or "udpate".');

return;
}

const projectName = process.argv[3];

const glob = require("glob"),
exec = require('child_process').exec,
packageFileName = 'package.json';

const projects = glob.sync("./src/OrchardCore.{Modules,Themes}/*" + projectName + "*/" + packageFileName, {});

if(projects.length == 0) {

console.log('Unable to find a project with a name that contains the name ' + process.argv[2]);

return;
}

if(projects.length > 1) {

console.log('Found multiple projects that contains the name ' + process.argv[2] + '. Please specify a more specific name.');
console.log('Here is a list of the matches found');
console.log(projects);

return;
}

const path = projects[0].substring(0, projects[0].length - packageFileName.length);

console.log(`Running 'npm ${actionName}' on '${projects[0]}'`);

exec('npm ' + actionName, {
'cwd': path
}, (error, stdout, stderr) => {
if (error) {
console.log(`Failed to run 'npm ${actionName}' on '${projects[0]}'`, error);
}
});
21 changes: 21 additions & 0 deletions .scripts/update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env node

'use strict';

const glob = require("glob"),
exec = require('child_process').exec,
packageFileName = 'package.json';

const assetPaths = glob.sync("./src/OrchardCore.{Modules,Themes}/*/" + packageFileName, {});

assetPaths.forEach(function (assetPath) {
let path = assetPath.substring(0, assetPath.length - packageFileName.length);
console.log(`Running 'npm update' on '${assetPath}'`);
exec('npm update', {
'cwd': path
}, (error, stdout, stderr) => {
if (error) {
console.log(`Failed to run 'npm update' on '${assetPath}'`, error);
}
})
});
13 changes: 13 additions & 0 deletions package-lock.json

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

26 changes: 6 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,10 @@
"build": "gulp build",
"rebuild": "gulp rebuild",
"watch": " gulp watch",
"install:orchardcore.admindashboard": "cd src/OrchardCore.Modules/OrchardCore.AdminDashboard && npm install",
"install:orchardcore.adminmenu": "cd src/OrchardCore.Modules/OrchardCore.AdminMenu && npm install",
"install:orchardcore.apis.graphql": "cd src/OrchardCore.Modules/OrchardCore.Apis.GraphQL && npm install",
"install:orchardcore.liquid": "cd src/OrchardCore.Modules/OrchardCore.Liquid && npm install",
"install:orchardcore.markdown": "cd src/OrchardCore.Modules/OrchardCore.Markdown && npm install",
"install:orchardcore.media": "cd src/OrchardCore.Modules/OrchardCore.Media && npm install",
"install:orchardcore.resources": "cd src/OrchardCore.Modules/OrchardCore.Resources && npm install",
"install:orchardcore.setup": "cd src/OrchardCore.Modules/OrchardCore.Setup && npm install",
"install:orchardcore.spatial": "cd src/OrchardCore.Modules/OrchardCore.Spatial && npm install",
"install:orchardcore.themes": "cd src/OrchardCore.Modules/OrchardCore.Themes && npm install",
"install:orchardcore.shortcodes": "cd src/OrchardCore.Modules/OrchardCore.Shortcodes && npm install",
"install:orchardcore.workflows": "cd src/OrchardCore.Modules/OrchardCore.Workflows && npm install",
"install:orchardcore.audittrail": "cd src/OrchardCore.Modules/OrchardCore.AuditTrail && npm install",
"install:orchardcore.theadmin": "cd src/OrchardCore.Themes/TheAdmin && npm install",
"install:orchardcore.theagencytheme": "cd src/OrchardCore.Themes/TheAgencyTheme && npm install",
"install:orchardcore.theblogtheme": "cd src/OrchardCore.Themes/TheBlogTheme && npm install",
"install:orchardcore.thecomingsoontheme": "cd src/OrchardCore.Themes/TheComingSoonTheme && npm install",
"install:orchardcore.thetheme": "cd src/OrchardCore.Themes/TheTheme && npm install",
"postinstall": "run-s install:*"
"postinstall": "node .scripts/install.js",
"update-projects": "node .scripts/update.js",
"install-project": "node .scripts/project.js install",
"update-project": "node .scripts/project.js update"
},
"devDependencies": {
"@babel/core": "^7.20.5",
Expand Down Expand Up @@ -59,6 +44,7 @@
"postcss": "8.4.19",
"postcss-rtl": "^2.0.0",
"rtlcss": "4.0.0",
"typescript": "^4.9.3"
"typescript": "^4.9.3",
"child_process": "^1.0.2"
}
}
12 changes: 6 additions & 6 deletions src/OrchardCore.Themes/TheTheme/package-lock.json

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