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 " ); } 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));