UNPKG

@backstage/plugin-techdocs-node

Version:

Common node.js functionalities for TechDocs, to be shared between techdocs-backend plugin and techdocs-cli

52 lines (48 loc) 1.36 kB
'use strict'; var errors = require('@backstage/errors'); var node_stream = require('node:stream'); var helpers = require('../helpers.cjs.js'); class MigrateWriteStream extends node_stream.Writable { logger; removeOriginal; maxConcurrency; inFlight = 0; constructor(logger, removeOriginal, concurrency) { super({ objectMode: true }); this.logger = logger; this.removeOriginal = removeOriginal; this.maxConcurrency = concurrency; } _write(file, _encoding, next) { let shouldCallNext = true; let newFile; try { newFile = helpers.lowerCaseEntityTripletInStoragePath(file.name); } catch (e) { this.logger.warn(errors.toError(e).message); next(); return; } if (newFile === file.name) { next(); return; } this.inFlight++; if (this.inFlight < this.maxConcurrency) { next(); shouldCallNext = false; } const migrate = this.removeOriginal ? file.move.bind(file) : file.copy.bind(file); this.logger.debug(`Migrating ${file.name}`); migrate(newFile).catch( (e) => this.logger.warn(`Unable to migrate ${file.name}: ${e.message}`) ).finally(() => { this.inFlight--; if (shouldCallNext) { next(); } }); } } exports.MigrateWriteStream = MigrateWriteStream; //# sourceMappingURL=GoogleMigration.cjs.js.map