-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(create-plugin): introduce updates as migrations
Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com> Co-authored-by: Levente Balogh <balogh.levente.hu@gmail.com>
- Loading branch information
1 parent
b2e8333
commit a0b402b
Showing
32 changed files
with
1,244 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,3 +46,4 @@ playwright/.auth | |
|
||
# Used in CI to pass built packages to the next job | ||
packed-artifacts/ | ||
.mise.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,49 @@ | ||
import chalk from 'chalk'; | ||
import minimist from 'minimist'; | ||
import { UDPATE_CONFIG } from '../constants.js'; | ||
import { printBlueBox, printRedBox } from '../utils/utils.console.js'; | ||
import { getOnlyExistingInCwd, removeFilesInCwd } from '../utils/utils.files.js'; | ||
import { standardUpdate } from './update.standard.command.js'; | ||
import { migrationUpdate } from './update.migrate.command.js'; | ||
import { isGitDirectory, isGitDirectoryClean } from '../utils/utils.git.js'; | ||
import { updateGoSdkAndModules } from '../utils/utils.goSdk.js'; | ||
import { updateNpmScripts, updatePackageJson } from '../utils/utils.npm.js'; | ||
import { getPackageManagerFromUserAgent } from '../utils/utils.packageManager.js'; | ||
import { isPluginDirectory, updateDotConfigFolder } from '../utils/utils.plugin.js'; | ||
import { getGrafanaRuntimeVersion, getVersion } from '../utils/utils.version.js'; | ||
import { printRedBox } from '../utils/utils.console.js'; | ||
import chalk from 'chalk'; | ||
import { isPluginDirectory } from '../utils/utils.plugin.js'; | ||
|
||
export const update = async (argv: minimist.ParsedArgs) => { | ||
const { packageManagerName } = getPackageManagerFromUserAgent(); | ||
try { | ||
if (!(await isGitDirectory()) && !argv.force) { | ||
printRedBox({ | ||
title: 'You are not inside a git directory', | ||
content: `In order to proceed please run "git init" in the root of your project and commit your changes.\n | ||
if (!(await isGitDirectory()) && !argv.force) { | ||
printRedBox({ | ||
title: 'You are not inside a git directory', | ||
content: `In order to proceed please run "git init" in the root of your project and commit your changes.\n | ||
(This check is necessary to make sure that the updates are easy to revert and don't mess with any changes you currently have. | ||
In case you want to proceed as is please use the ${chalk.bold('--force')} flag.)`, | ||
}); | ||
}); | ||
|
||
process.exit(1); | ||
} | ||
process.exit(1); | ||
} | ||
|
||
if (!(await isGitDirectoryClean()) && !argv.force) { | ||
printRedBox({ | ||
title: 'Please clean your repository working tree before updating.', | ||
subtitle: '(Commit your changes or stash them.)', | ||
content: `(This check is necessary to make sure that the updates are easy to revert and don't mess with any changes you currently have. | ||
if (!(await isGitDirectoryClean()) && !argv.force) { | ||
printRedBox({ | ||
title: 'Please clean your repository working tree before updating.', | ||
subtitle: '(Commit your changes or stash them.)', | ||
content: `(This check is necessary to make sure that the updates are easy to revert and don't mess with any changes you currently have. | ||
In case you want to proceed as is please use the ${chalk.bold('--force')} flag.)`, | ||
}); | ||
|
||
process.exit(1); | ||
} | ||
|
||
if (!isPluginDirectory() && !argv.force) { | ||
printRedBox({ | ||
title: 'Are you inside a plugin directory?', | ||
subtitle: 'We couldn\'t find a "src/plugin.json" file under your current directory.', | ||
content: `(Please make sure to run this command from the root of your plugin folder. In case you want to proceed as is please use the ${chalk.bold( | ||
'--force' | ||
)} flag.)`, | ||
}); | ||
}); | ||
|
||
process.exit(1); | ||
} | ||
process.exit(1); | ||
} | ||
|
||
// Updating the plugin (.config/, NPM package dependencies, package.json scripts) | ||
// (More info on the why: https://docs.google.com/document/d/15dm4WV9v7Ga9Z_Hp3CJMf2D3meuTyEWqBc3omqiOksQ) | ||
// ------------------- | ||
await updateDotConfigFolder(); | ||
updateNpmScripts(); | ||
updatePackageJson({ | ||
onlyOutdated: true, | ||
ignoreGrafanaDependencies: false, | ||
if (!isPluginDirectory() && !argv.force) { | ||
printRedBox({ | ||
title: 'Are you inside a plugin directory?', | ||
subtitle: 'We couldn\'t find a "src/plugin.json" file under your current directory.', | ||
content: `(Please make sure to run this command from the root of your plugin folder. In case you want to proceed as is please use the ${chalk.bold( | ||
'--force' | ||
)} flag.)`, | ||
}); | ||
await updateGoSdkAndModules(process.cwd()); | ||
|
||
const filesToRemove = getOnlyExistingInCwd(UDPATE_CONFIG.filesToRemove); | ||
if (filesToRemove.length) { | ||
removeFilesInCwd(filesToRemove); | ||
} | ||
|
||
printBlueBox({ | ||
title: 'Update successful ✔', | ||
content: `${chalk.bold('@grafana/* package version:')} ${getGrafanaRuntimeVersion()} | ||
${chalk.bold('@grafana/create-plugin version:')} ${getVersion()} | ||
process.exit(1); | ||
} | ||
|
||
${chalk.bold.underline('Next steps:')} | ||
- 1. Run ${chalk.bold(`${packageManagerName} install`)} to install the package updates | ||
- 2. Check if you encounter any breaking changes | ||
(refer to our migration guide: https://grafana.com/developers/plugin-tools/migration-guides/update-from-grafana-versions/) | ||
${chalk.bold('Do you have questions?')} | ||
Please don't hesitate to reach out in one of the following ways: | ||
- Open an issue in https://github.com/grafana/plugin-tools | ||
- Ask a question in the community forum at https://community.grafana.com/c/plugin-development/30 | ||
- Join our community slack channel at https://slack.grafana.com/`, | ||
}); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
printRedBox({ | ||
title: 'Something went wrong while updating your plugin.', | ||
content: error.message, | ||
}); | ||
} else { | ||
console.error(error); | ||
} | ||
if (argv.experimentalUpdates) { | ||
return await migrationUpdate(argv); | ||
} | ||
|
||
return await standardUpdate(); | ||
}; |
31 changes: 31 additions & 0 deletions
31
packages/create-plugin/src/commands/update.migrate.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import minimist from 'minimist'; | ||
import { gte } from 'semver'; | ||
import { getMigrationsToRun, runMigrations } from '../migrations/manager.js'; | ||
import { getConfig } from '../utils/utils.config.js'; | ||
import { getVersion } from '../utils/utils.version.js'; | ||
import { printHeader } from '../utils/utils.console.js'; | ||
|
||
export const migrationUpdate = async (argv: minimist.ParsedArgs) => { | ||
try { | ||
const projectCpVersion = getConfig().version; | ||
const packageCpVersion = getVersion(); | ||
|
||
if (gte(projectCpVersion, packageCpVersion)) { | ||
console.warn('Nothing to update, exiting.'); | ||
process.exit(0); | ||
} | ||
|
||
console.log(`Running migrations from ${projectCpVersion} to ${packageCpVersion}.`); | ||
|
||
const commitEachMigration = argv.commit; | ||
const migrations = getMigrationsToRun(projectCpVersion, packageCpVersion); | ||
await runMigrations(migrations, { commitEachMigration }); | ||
printHeader('the update command completed successfully.'); | ||
console.log(''); | ||
} catch (error) { | ||
printHeader('the update command encountered an error.'); | ||
console.log(''); | ||
console.error(error); | ||
process.exit(1); | ||
} | ||
}; |
Oops, something went wrong.