I am currently working on a task in my gulpfile.js that involves uploading an app using Gulp and SharePoint.
'use strict';
const gulp = require('gulp');
const build = require('@microsoft/sp-build-web');
const spsync = require('gulp-spsync-creds').sync;
const sppkgDeploy = require('node-sppkg-deploy');
const config = require('./dev-config.json');
var coreOptions = {
siteUrl: config.coreOptions.siteUrl,
appCatalog: config.coreOptions.appCatalog
};
var creds = {
username: config.creds.username,
password: config.creds.password
};
build.task('upload-single-app', {
execute: (config) => {
return new Promise((resolve, reject) => {
const pluginList = require('./config/plugin-deployment.json');
if (pluginList)
{
for (let i = 0; i < pluginList.plugins.length; i++) {
const folderLocation = `./plugins/` + pluginList.plugins[i].name;
for (let x = 0; x < pluginList.plugins[i].sites.length; x++) {
console.log(pluginList.plugins[i].sites[x]);
return gulp.src(folderLocation)
.pipe(spsync({
"username": creds.username,
"password": creds.password,
"site": coreOptions.siteUrl + pluginList.plugins[i].sites[x],
"libraryPath": coreOptions.appCatalog,
"publish":: true
}))
.on('finish', resolve);
}//end inner for
}// end for
} else {
console.log("Plugin list is empty");
}
});
}
});
Here is the JSON data that drives this process:
{
"plugins":
[
{
"name": "Bluebeam.OpenRevuExtension.sppkg",
"description": "some description",
"version":"20.2.30.5",
"sites":["sp_site1","sp_site2"]
}
]
}
Upon running the code, the package successfully deploys to site1 but not site 2 without any errors. The output looks like this:
devbox:plugintest admin$ gulp upload-single-app
Build target: DEBUG
[14:51:48] Using gulpfile /src/plugintest/gulpfile.js
[14:51:48] Starting gulp
[14:51:48] Starting 'upload-single-app'...
sp_site1
[14:51:48] Uploading Bluebeam.OpenRevuExtension.sppkg
[14:51:50] Upload successful 1919ms
[14:51:51] Published file 982ms
[14:51:51] Finished 'upload-single-app' after 2.92 s
[14:51:51] ==================[ Finished ]==================
[14:51:52] Project plugintest version:1.0.0
[14:51:52] Build tools version:3.12.1
[14:51:52] Node version:v10.24.1
[14:51:52] Total duration:6.48 s
I'm considering refactoring the code into two separate tasks to handle deployment to multiple sites asynchronously. Here is a pseudocode example of what I have in mind:
build.task('main', {
for each plugin in json file {
for each site I need to deploy to {
call build.task('upload_app');
call build.task('deploy_app');
}
}
});
Do you think this approach is suitable? Any suggestions on how to implement it effectively?
Thank you.