(
input: string[],
flags: { [name: string]: any },
cwd: string
)
| 35 | } |
| 36 | |
| 37 | export async function run( |
| 38 | input: string[], |
| 39 | flags: { [name: string]: any }, |
| 40 | cwd: string |
| 41 | ) { |
| 42 | const packages = await getPackages(cwd); |
| 43 | const rootDir = packages.root.dir; |
| 44 | |
| 45 | if (input[0] === "init") { |
| 46 | validateCommandFlags("init", flags); |
| 47 | await init(rootDir); |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | if (!fs.existsSync(path.resolve(rootDir, ".changeset"))) { |
| 52 | error("There is no .changeset folder. "); |
| 53 | error( |
| 54 | "If this is the first time `changesets` have been used in this project, run `yarn changeset init` to get set up." |
| 55 | ); |
| 56 | error( |
| 57 | "If you expected there to be changesets, you should check git history for when the folder was removed to ensure you do not lose any configuration." |
| 58 | ); |
| 59 | throw new ExitError(1); |
| 60 | } |
| 61 | |
| 62 | let config: Config; |
| 63 | try { |
| 64 | config = await read(rootDir, packages); |
| 65 | } catch (e) { |
| 66 | let oldConfigExists = await fs.pathExists( |
| 67 | path.resolve(rootDir, ".changeset/config.js") |
| 68 | ); |
| 69 | if (oldConfigExists) { |
| 70 | error( |
| 71 | "It looks like you're using the version 1 `.changeset/config.js` file" |
| 72 | ); |
| 73 | error("You'll need to convert it to a `.changeset/config.json` file"); |
| 74 | error( |
| 75 | "The format of the config object has significantly changed in v2 as well" |
| 76 | ); |
| 77 | error( |
| 78 | " - we thoroughly recommend looking at the changelog for this package for what has changed" |
| 79 | ); |
| 80 | throw new ExitError(1); |
| 81 | } else { |
| 82 | throw e; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | if (input.length < 1) { |
| 87 | const { empty, open, since, message, ...rest }: CliOptions = flags; |
| 88 | validateCommandFlags("add", rest); |
| 89 | await add(rootDir, { empty, open, since, message }, config); |
| 90 | } else if (input[0] !== "pre" && input.length > 1) { |
| 91 | error( |
| 92 | "Too many arguments passed to changesets - we only accept the command name as an argument" |
| 93 | ); |
| 94 | } else { |
no test coverage detected