MCPcopy Index your code
hub / github.com/changesets/changesets / init

Function init

packages/cli/src/commands/init/index.ts:18–75  ·  view source on GitHub ↗
(cwd: string)

Source from the content-addressed store, hash-verified

16)}\n`;
17
18export default async function init(cwd: string) {
19 const changesetBase = path.resolve(cwd, ".changeset");
20
21 if (fs.existsSync(changesetBase)) {
22 if (!fs.existsSync(path.join(changesetBase, "config.json"))) {
23 if (fs.existsSync(path.join(changesetBase, "config.js"))) {
24 error(
25 "It looks like you're using the version 1 `.changeset/config.js` file"
26 );
27 error(
28 "The format of the config object has significantly changed in v2 as well"
29 );
30 error(
31 " - we thoroughly recommend looking at the changelog for this package for what has changed"
32 );
33 error(
34 "Changesets will write the defaults for the new config, remember to transfer your options into the new config at `.changeset/config.json`"
35 );
36 } else {
37 error("It looks like you don't have a config file");
38 info(
39 "The default config file will be written at `.changeset/config.json`"
40 );
41 }
42 await fs.writeFile(
43 path.resolve(changesetBase, "config.json"),
44 defaultConfig
45 );
46 } else {
47 warn(
48 "It looks like you already have changesets initialized. You should be able to run changeset commands no problems."
49 );
50 }
51 } else {
52 await fs.copy(path.resolve(pkgPath, "./default-files"), changesetBase);
53 await fs.writeFile(
54 path.resolve(changesetBase, "config.json"),
55 defaultConfig
56 );
57
58 log(
59 `Thanks for choosing ${pc.green(
60 "changesets"
61 )} to help manage your versioning and publishing.\n`
62 );
63 log("You should be set up to start using changesets now!\n");
64
65 info(
66 "We have added a `.changeset` folder, and a couple of files to help you out:"
67 );
68 info(
69 `- ${pc.blue(
70 ".changeset/README.md"
71 )} contains information about using changesets`
72 );
73 info(`- ${pc.blue(".changeset/config.json")} is our default config`);
74 }
75}

Callers 1

runFunction · 0.85

Calls 4

errorFunction · 0.90
infoFunction · 0.90
warnFunction · 0.90
logFunction · 0.90

Tested by

no test coverage detected