@toptal/davinci-codemod 0.3.5-alpha-fx-3043-live-edit-source-code.32 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @toptal/davinci-codemod
2
2
 
3
+ ## 0.3.5
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`e602ae7e`](https://github.com/toptal/davinci/commit/e602ae7edc7d075a4192052d6c04868f08fea0a7)]:
8
+ - @toptal/davinci-cli-shared@1.8.0
9
+
3
10
  ## 0.3.4
4
11
 
5
12
  ### Patch Changes
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@toptal/davinci-codemod",
3
+ "version": "0.3.5",
4
+ "description": "Collection of codemods and migration scripts.",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "keywords": [
9
+ "codemod"
10
+ ],
11
+ "author": "Toptal",
12
+ "homepage": "https://github.com/toptal/davinci/tree/master/packages/codemod#readme",
13
+ "license": "ISC",
14
+ "bin": {
15
+ "davinci-codemod": "bin/davinci-codemod.js"
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/toptal/davinci.git"
20
+ },
21
+ "scripts": {
22
+ "build:package": "../../bin/build-package.js",
23
+ "prepublishOnly": "../../bin/prepublish.js"
24
+ },
25
+ "dependencies": {
26
+ "@toptal/davinci-cli-shared": "1.8.0",
27
+ "fs-extra": "^10.1.0",
28
+ "globby": "^11.0.1",
29
+ "semver": "^7.3.7"
30
+ }
31
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toptal/davinci-codemod",
3
- "version": "0.3.5-alpha-fx-3043-live-edit-source-code.32+03510757",
3
+ "version": "0.3.5",
4
4
  "description": "Collection of codemods and migration scripts.",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -23,8 +23,9 @@
23
23
  "prepublishOnly": "../../bin/prepublish.js"
24
24
  },
25
25
  "dependencies": {
26
- "@toptal/davinci-cli-shared": "1.7.1-alpha-fx-3043-live-edit-source-code.32+03510757",
27
- "globby": "^11.0.1"
28
- },
29
- "gitHead": "035107574f40d5fe45939e734e0ea1639208de02"
26
+ "@toptal/davinci-cli-shared": "1.8.0",
27
+ "fs-extra": "^10.1.0",
28
+ "globby": "^11.0.1",
29
+ "semver": "^7.3.7"
30
+ }
30
31
  }
@@ -0,0 +1,109 @@
1
+ const fs = require('fs-extra')
2
+ const { createRequire } = require('module')
3
+ const semver = require('semver')
4
+ const { print, runSync } = require('@toptal/davinci-cli-shared')
5
+ const path = require('path')
6
+
7
+ const SUPPORTED_DAVINCI_RANGE = '21.x.x'
8
+
9
+ const DAVINCI_MODULES_TO_SPLIT = [
10
+ 'code',
11
+ 'engine',
12
+ 'graphql-codegen',
13
+ 'monorepo',
14
+ 'qa',
15
+ 'ci',
16
+ 'syntax',
17
+ 'storybook',
18
+ ].map(name => `@toptal/davinci-${name}`)
19
+
20
+ const checkPrerequisites = async () => {
21
+ const projectPackageJson = await fs.readJson('package.json')
22
+
23
+ const projectDavinciVersion =
24
+ projectPackageJson.devDependencies?.['@toptal/davinci'] ??
25
+ projectPackageJson.dependencies?.['@toptal/davinci']
26
+
27
+ if (!projectDavinciVersion) {
28
+ print.red(
29
+ `Current project at ${process.cwd()} doesn't have a dependency on @toptal/davinci`
30
+ )
31
+ console.log(
32
+ 'Be sure to run the migration script on a project that depends on it'
33
+ )
34
+ process.exit(1)
35
+ }
36
+
37
+ if (!semver.satisfies(SUPPORTED_DAVINCI_RANGE, projectDavinciVersion)) {
38
+ print.yellow(
39
+ `Your project's Davinci is currently on version ${projectDavinciVersion}, we only recommend running this command on version ${SUPPORTED_DAVINCI_RANGE}, the version script was tested to work with`
40
+ )
41
+ }
42
+ }
43
+
44
+ const installSubModulesIndependently = async () => {
45
+ // We need createRequire to access the require function for the current project, not from this script project
46
+ const projectRequire = createRequire(path.join(process.cwd(), 'package.json'))
47
+
48
+ let projectDavinciPackageJsonPath
49
+
50
+ try {
51
+ projectDavinciPackageJsonPath = projectRequire.resolve(
52
+ '@toptal/davinci/package.json'
53
+ )
54
+ } catch {
55
+ print.red(
56
+ "Couldn't find the current Davinci's installation in node_modules"
57
+ )
58
+ console.log('Be sure to run `yarn install` before running this script')
59
+ process.exit(1)
60
+ }
61
+
62
+ const projectDavinciPackageJson = await fs.readJson(
63
+ projectDavinciPackageJsonPath
64
+ )
65
+
66
+ const projectDavinciModulesWithVersions = Object.entries(
67
+ projectDavinciPackageJson.dependencies
68
+ )
69
+ .filter(([pkgName]) => DAVINCI_MODULES_TO_SPLIT.includes(pkgName))
70
+ .map(([pkgName, version]) => `${pkgName}@${version}`)
71
+
72
+ print.cyan(
73
+ '\nThe following packages will be added to your root package.json:\n'
74
+ )
75
+ print.green(
76
+ projectDavinciModulesWithVersions.map(pkg => ` - ${pkg}`).join('\n'),
77
+ '\n'
78
+ )
79
+
80
+ runSync('yarn', [
81
+ 'add',
82
+ '--dev',
83
+ '--ignore-workspace-root-check',
84
+ ...projectDavinciModulesWithVersions,
85
+ ])
86
+ }
87
+
88
+ const removeMainDavinciDependency = () => {
89
+ print.cyan(
90
+ '\nThe main davinci dependency will be now be removed of your package.json\n'
91
+ )
92
+ runSync('yarn', [
93
+ 'remove',
94
+ '--ignore-workspace-root-check',
95
+ '@toptal/davinci',
96
+ ])
97
+ }
98
+
99
+ const migrateToDavinciByParts = async () => {
100
+ await checkPrerequisites()
101
+
102
+ await installSubModulesIndependently()
103
+
104
+ removeMainDavinciDependency()
105
+
106
+ print.green('\nYour project now works with davinci-by parts! 🚀')
107
+ }
108
+
109
+ module.exports = migrateToDavinciByParts
@@ -9,7 +9,7 @@ const findCodemodPath = codemod =>
9
9
  .map(ext => path.join(codemodsDirectory, `${codemod}/index.${ext}`))
10
10
  .find(fs.existsSync)
11
11
 
12
- const runTransform = ({ codemod, inputFilesOption = [] }) => {
12
+ const runTransform = async ({ codemod, inputFilesOption = [] }) => {
13
13
  let inputFiles = inputFilesOption
14
14
 
15
15
  if (inputFilesOption.length === 0) {
@@ -26,13 +26,13 @@ const runTransform = ({ codemod, inputFilesOption = [] }) => {
26
26
  }
27
27
  const transformFunction = require(codemodPath)
28
28
 
29
- transformFunction(files)
29
+ await transformFunction(files)
30
30
  }
31
31
 
32
32
  const runCodemodCommandCreator = {
33
33
  command: 'run-codemod <codemod> [files...]',
34
34
  description: 'Run codemod or migration for your app',
35
- action: async ({ codemod, files }) => {
35
+ action: ({ codemod, files }) => {
36
36
  return runTransform({
37
37
  codemod,
38
38
  inputFilesOption: files,