diff --git a/contentful-cli-migrations.js b/contentful-cli-migrations.js index 37145aa..b987f80 100644 --- a/contentful-cli-migrations.js +++ b/contentful-cli-migrations.js @@ -50,10 +50,6 @@ const DEFAULT_FIRST_MIGRATION = '0001-create-counter-content-type.cjs' latestMigrationNumber, migrationArray ) - - if (parsedArguments?.shouldInitialise) { - await createCounterEntry(environmentSingleton) - } } catch (error) { console.error('@@/ERROR:', error) } @@ -447,7 +443,9 @@ async function parseMigrationsToRun(parsedArguments, latestMigrationNumber) { const fileSystem = await import('fs') const folderMigrationScript = parsedArguments?.rootDestinationFolder - let files = fileSystem.readdirSync(folderMigrationScript) + const allFiles = fileSystem.readdirSync(folderMigrationScript) + const files = allFiles.filter(item => !/(^|\/)\.[^/.]/g.test(item)) + let migrationArray = [] let indexObject = [] let arrayLength = files.length @@ -558,24 +556,28 @@ async function performMigrations( .then(async () => { console.log('##/INFO: Migration ' + migrationScript + ' Done!') - // Update counter value - latestMigrationNumber++ - - // Write new Count into Entry - const fieldId = parsedArguments?.counterFieldId - const fieldLocale = parsedArguments?.counterLocale - const entrySavingCounter = await environmentSingleton.getEntry( - parsedArguments?.counterEntryId - ) - - entrySavingCounter.fields[fieldId][ - fieldLocale - ] = `${latestMigrationNumber}` - - entrySavingCounter - .update() - .then(callback()) - .catch(e => console.error('@@/ERROR: ' + e)) + if (!parsedArguments?.shouldInitialise) { + // Update counter value + latestMigrationNumber++ + + // Write new Count into Entry + const fieldId = parsedArguments?.counterFieldId + const fieldLocale = parsedArguments?.counterLocale + const entrySavingCounter = await environmentSingleton.getEntry( + parsedArguments?.counterEntryId + ) + + entrySavingCounter.fields[fieldId][ + fieldLocale + ] = `${latestMigrationNumber}` + + entrySavingCounter + .update() + .then(callback()) + .catch(e => console.error('@@/ERROR: ' + e)) + } else { + await createCounterEntry(environmentSingleton) + } }) .catch(e => console.error( diff --git a/package-lock.json b/package-lock.json index cfca4cd..0027648 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "contentful-cli-migrations", - "version": "0.1.0", + "version": "0.1.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "contentful-cli-migrations", - "version": "0.1.0", + "version": "0.1.1", "license": "MIT", "dependencies": { "async": "^3.2.2", diff --git a/package.json b/package.json index 363656e..103de96 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "contentful-cli-migrations", - "version": "0.1.0", + "version": "0.1.1", "type": "module", "description": "Contentful CLI Migration Tool", "homepage": "https://github.com/AtidaTech/contentful-cli-migrations",