|
| 1 | +import execa from "execa" |
| 2 | + |
| 3 | +type Package = { |
| 4 | + readonly name: string |
| 5 | + readonly minVersion: string |
| 6 | +} |
| 7 | + |
| 8 | +type InstallPackageOptions = { |
| 9 | + dev?: boolean |
| 10 | +} |
| 11 | +export const yarnAdd = async ( |
| 12 | + npmPackage: Package | Package[], |
| 13 | + options?: InstallPackageOptions |
| 14 | +) => { |
| 15 | + const packageArray = Array.isArray(npmPackage) ? npmPackage : [npmPackage] |
| 16 | + |
| 17 | + const packagesWithVersions = packageArray.map((pkg) => |
| 18 | + getQuotedNameVersionCombo(pkg) |
| 19 | + ) |
| 20 | + |
| 21 | + let yarnAddCommand = "yarn add" |
| 22 | + if (options != null && options.dev != null && options.dev) { |
| 23 | + yarnAddCommand += " --dev" |
| 24 | + } |
| 25 | + packagesWithVersions.forEach((packageWithVersion) => { |
| 26 | + yarnAddCommand += ` ${packageWithVersion}` |
| 27 | + }) |
| 28 | + return execa(yarnAddCommand) |
| 29 | +} |
| 30 | + |
| 31 | +export const getQuotedNameVersionCombo = (npmPackage: Package) => { |
| 32 | + return `"${npmPackage.name}@^${npmPackage.minVersion}"` |
| 33 | +} |
| 34 | + |
1 | 35 | export const packages = { |
2 | | - yarn: "yarn@1", |
3 | | - prettier: "prettier@2", |
4 | | - "eslint-config-prettier": "eslint-config-prettier@8", |
5 | | - "@emotion/react": "@emotion/react@11", |
6 | | - "@emotion/styled": "@emotion/styled@11", |
7 | | - "@emotion/babel-plugin": "@emotion/babel-plugin@11", |
8 | | - "react-hook-form": "react-hook-form@7", |
9 | | - formik: "formik@2", |
10 | | - "framer-motion": "framer-motion@4", |
11 | | - "create-next-app": "create-next-app@11", |
12 | | - mrm: "mrm@2", |
| 36 | + yarn: { |
| 37 | + name: "yarn", |
| 38 | + minVersion: "1.0.0", |
| 39 | + }, |
| 40 | + prettier: { |
| 41 | + name: "prettier", |
| 42 | + minVersion: "2.0.0", |
| 43 | + }, |
| 44 | + "eslint-config-prettier": { |
| 45 | + name: "eslint-config-prettier", |
| 46 | + minVersion: "8.0.0", |
| 47 | + }, |
| 48 | + "@emotion/react": { |
| 49 | + name: "@emotion/react", |
| 50 | + minVersion: "11.0.0", |
| 51 | + }, |
| 52 | + "@emotion/styled": { |
| 53 | + name: "@emotion/styled", |
| 54 | + minVersion: "11.0.0", |
| 55 | + }, |
| 56 | + "@emotion/babel-plugin": { |
| 57 | + name: "@emotion/babel-plugin", |
| 58 | + minVersion: "11.0.0", |
| 59 | + }, |
| 60 | + "styled-components": { |
| 61 | + name: "styled-components", |
| 62 | + minVersion: "5.0.0", |
| 63 | + }, |
| 64 | + "@types/styled-components": { |
| 65 | + name: "@types/styled-components", |
| 66 | + minVersion: "5.0.0", |
| 67 | + }, |
| 68 | + "babel-plugin-styled-components": { |
| 69 | + name: "babel-plugin-styled-components", |
| 70 | + minVersion: "1.0.0", |
| 71 | + }, |
| 72 | + "react-hook-form": { |
| 73 | + name: "react-hook-form", |
| 74 | + minVersion: "7.0.0", |
| 75 | + }, |
| 76 | + formik: { |
| 77 | + name: "formik", |
| 78 | + minVersion: "2.0.0", |
| 79 | + }, |
| 80 | + "framer-motion": { |
| 81 | + name: "framer-motion", |
| 82 | + minVersion: "4.0.0", |
| 83 | + }, |
| 84 | + "create-next-app": { |
| 85 | + name: "create-next-app", |
| 86 | + minVersion: "11.0.0", |
| 87 | + }, |
| 88 | + mrm: { |
| 89 | + name: "mrm", |
| 90 | + minVersion: "3.0.0", |
| 91 | + }, |
| 92 | + "mrm-task-lint-staged": { |
| 93 | + name: "mrm-task-lint-staged", |
| 94 | + minVersion: "6.0.0", |
| 95 | + }, |
13 | 96 | } as const |
0 commit comments