Created
November 4, 2022 16:35
-
-
Save klcodanr/933c757e758a707a2280a0d1d05e0c68 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const fs = require("fs"); | |
const Path = require("path"); | |
const winston = require("winston"); | |
const { | |
FileSystemUploadOptions, | |
FileSystemUpload, | |
} = require("@adobe/aem-upload"); | |
const log = winston.createLogger({ | |
format: winston.format.simple(), | |
transports: [new winston.transports.Console()], | |
}); | |
const args = process.argv.slice(2); | |
if (args.length !== 3) { | |
throw new Error( | |
"Missing required arguments: aem-asset-import-example <config.json> <sourcepath> <targetpath>" | |
); | |
} | |
const { AEM_HOST, AEM_PASSWORD, AEM_USERNAME } = require(args[0]); | |
const source = Path.normalize(args[1]); | |
const target = `${AEM_HOST}${args[2]}`; | |
if (!fs.existsSync(source) || !fs.lstatSync(source).isDirectory()) { | |
throw new Error(`Source ${source} does not exist or is not a directory`); | |
} | |
log.info(`Importing assets from ${source} to ${target}`); | |
const options = new FileSystemUploadOptions() | |
.withUrl(target) | |
.withDeepUpload(true) | |
.withBasicAuth(AEM_USERNAME + ":" + AEM_PASSWORD); | |
const fileUpload = new FileSystemUpload({ log }); | |
fileUpload | |
.upload(options, [source]) | |
.then(() => console.log(`Upload complete!`)) | |
.catch((err) => console.error("Upload Failed!", err)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment