Skip to content

Instantly share code, notes, and snippets.

@klcodanr
Created November 4, 2022 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klcodanr/933c757e758a707a2280a0d1d05e0c68 to your computer and use it in GitHub Desktop.
Save klcodanr/933c757e758a707a2280a0d1d05e0c68 to your computer and use it in GitHub Desktop.
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