MCPcopy Index your code
hub / github.com/commitizen/cz-cli / init

Function init

src/commitizen/init.js:51–99  ·  view source on GitHub ↗

* Runs npm install for the adapter then modifies the config.commitizen as needed

(repoPath, adapterNpmName, {
  save = false,
  saveDev = true,
  saveExact = false,
  force = false,
  yarn = false,
  dev = false,
  exact = false,
  pnpm = false,
  includeCommitizen = false
} = defaultInitOptions)

Source from the content-addressed store, hash-verified

49 * Runs npm install for the adapter then modifies the config.commitizen as needed
50 */
51function init (repoPath, adapterNpmName, {
52 save = false,
53 saveDev = true,
54 saveExact = false,
55 force = false,
56 yarn = false,
57 dev = false,
58 exact = false,
59 pnpm = false,
60 includeCommitizen = false
61} = defaultInitOptions) {
62
63 // Don't let things move forward if required args are missing
64 checkRequiredArguments(repoPath, adapterNpmName);
65
66 // Load the current adapter config
67 let adapterConfig = loadAdapterConfig(repoPath);
68
69 const packageManager = yarn ? 'yarn' : pnpm ? 'pnpm' : 'npm';
70
71 // Get the npm string mappings based on the arguments provided
72 const stringMappings = getInstallStringMappings({ save, dev, saveDev, saveExact, force }, packageManager);
73
74 // Generate a string that represents the npm install command
75 const installAdapterCommand = generateInstallAdapterCommand(stringMappings, adapterNpmName, packageManager);
76
77 const installCommitizenCommand = generateInstallAdapterCommand(stringMappings, 'commitizen', packageManager);
78
79 // Check for previously installed adapters
80 if (adapterConfig && adapterConfig.path && adapterConfig.path.length > 0 && !force) {
81 throw new Error(`A previous adapter is already configured. Use --force to override
82 adapterConfig.path: ${adapterConfig.path}
83 repoPath: ${repoPath}
84 CLI_PATH: ${CLI_PATH}
85 installAdapterCommand: ${installAdapterCommand}
86 adapterNpmName: ${adapterNpmName}
87 `);
88 }
89
90 try {
91 childProcess.execSync(installAdapterCommand, { cwd: repoPath });
92 if(includeCommitizen) {
93 childProcess.execSync(installCommitizenCommand, { cwd: repoPath });
94 }
95 addPathToAdapterConfig(CLI_PATH, repoPath, adapterNpmName);
96 } catch (e) {
97 console.error(e);
98 }
99}
100
101/**
102 * Checks to make sure that the required arguments are passed

Callers 1

bootstrapFunction · 0.90

Calls 5

checkRequiredArgumentsFunction · 0.85
loadAdapterConfigFunction · 0.85
getInstallStringMappingsFunction · 0.85
addPathToAdapterConfigFunction · 0.85

Tested by

no test coverage detected