From e1dbd2888a355e4575b5037167d082667d370acd Mon Sep 17 00:00:00 2001 From: "Dennis Ameling (he/him)" Date: Sat, 20 Aug 2022 14:31:24 +0200 Subject: [PATCH] Add option for skipping Git working tree check --- README.md | 6 ++++++ bin/cli.js | 9 +++++++-- bin/commands/migrate.js | 10 ++++++---- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 81c91c7..96f8246 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,12 @@ To bypass the prompts use one of the following commands: yarn @strapi/codemods migrate:application ``` +💡 If you want to skip the Git working tree check, run the command with the `--skip-working-tree-check` argument. This is especially useful for monorepos where Strapi doesn't have its own `.git` directory. + +```bash +yarn @strapi/codemods migrate:application --skip-working-tree-check +``` + - `Plugin` migration ```bash diff --git a/bin/cli.js b/bin/cli.js index 3591dd9..197dfbe 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -42,9 +42,14 @@ program // `$ strapi-codemods migrate:application` program .command('migrate:application [path]') + .option( + "--skip-working-tree-check", + "Skip checking whether the Git working tree is clean. Especially useful for monorepos.", + undefined + ) .description('Migrate a v3 Strapi application to v4') - .action(async (path) => { - await migrate('application', path); + .action(async (path, options) => { + await migrate('application', path, undefined, options); }); // `$ strapi-codemods migrate:plugin` diff --git a/bin/commands/migrate.js b/bin/commands/migrate.js index 66d9ebc..6667b65 100644 --- a/bin/commands/migrate.js +++ b/bin/commands/migrate.js @@ -13,7 +13,7 @@ const { migratePlugin, migrateApiFolder, migrateDependencies, migrateApplication // Global utils const { isPathStrapiApp, logger, isCleanGitRepo, promptUser } = require('../../lib/global/utils'); -const migrate = async (type, path, pathForV4Plugin) => { +const migrate = async (type, path, pathForV4Plugin, cliOptions) => { // Check the path exists const exists = await fs.pathExists(resolve(path)); if (!exists) { @@ -24,7 +24,7 @@ const migrate = async (type, path, pathForV4Plugin) => { try { switch (type) { case 'application': - await migrateApplicationToV4(path); + await migrateApplicationToV4(path, cliOptions); break; case 'dependencies': await migrateDependenciesToV4(path); @@ -40,7 +40,7 @@ const migrate = async (type, path, pathForV4Plugin) => { }; // `strapi-codemods migrate:application` -const migrateApplicationToV4 = async (path) => { +const migrateApplicationToV4 = async (path, cliOptions) => { const promptOptions = { type: 'input', name: 'path', @@ -51,7 +51,9 @@ const migrateApplicationToV4 = async (path) => { const options = await promptUser(promptOptions); const projectPath = path || options.path; - await isCleanGitRepo(projectPath); + if (!cliOptions.skipWorkingTreeCheck) { + await isCleanGitRepo(projectPath); + } await isPathStrapiApp(projectPath); await migrateDependencies(projectPath); await migrateApplicationFolderStructure(projectPath);