-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add SharePoint deployment workflow (patch)
- Loading branch information
Showing
5 changed files
with
2,102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
53 changes: 53 additions & 0 deletions
53
scripts/deployment/deploy-files-to-sharepoint/deploy-files-to-sharepoint.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/env node | ||
|
||
const path = require('path'); | ||
const fs = require('fs').promises; | ||
const { spsave } = require('spsave'); | ||
|
||
async function main() { | ||
const coreOptions = { | ||
siteUrl: process.argv[2], | ||
}; | ||
|
||
const credentialOptions = { | ||
clientId: process.env.SHAREPOINT_CLIENT_ID, | ||
clientSecret: process.env.SHAREPOINT_CLIENT_SECRET, | ||
}; | ||
|
||
const basePath = process.argv[4]; | ||
|
||
async function pushFile(filePath, fileName, fileContent) { | ||
await spsave(coreOptions, credentialOptions, { | ||
filePath: filePath.replace(new RegExp(`^${ basePath }/`), ''), | ||
fileName, | ||
fileContent | ||
}); | ||
} | ||
|
||
async function processDir(dirPath) { | ||
const entities = await fs.readdir(dirPath); | ||
for (const entity of entities) { | ||
const entityFullPath = path.join(dirPath, entity); | ||
const stat = await fs.stat(entityFullPath); | ||
|
||
if (stat.isDirectory()) { | ||
await processDir(entityFullPath); | ||
continue; | ||
} | ||
|
||
const fileContent = await fs.readFile(entityFullPath); | ||
await pushFile(dirPath, entity, fileContent); | ||
} | ||
} | ||
|
||
await processDir(basePath); | ||
} | ||
|
||
main().then(() => { | ||
console.log('Successfully uploaded files to SharePoint.'); | ||
process.exit(0); | ||
}, (e) => { | ||
console.error('An error occurred while uploading files to SharePoint:'); | ||
console.error(e); | ||
process.exit(-1); | ||
}); |
Oops, something went wrong.