-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
69 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
import { configFileName, configDirPath } from '../utils/config.js'; | ||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
|
||
export default (program) => { | ||
program | ||
.command('init') | ||
.description( | ||
`Copies default config file into the given path directory or inside ${configDirPath}`, | ||
) | ||
.argument('[path]', 'directory path to copy config into') | ||
.action(async (targetDirectory = configDirPath) => { | ||
if (!fs.existsSync(targetDirectory)) { | ||
fs.mkdirSync(targetDirectory, { recursive: true }); | ||
} | ||
|
||
const defaultConfigPath = path.join(__dirname, '../config.default.jsonc'); | ||
const targetFilePath = path.resolve(targetDirectory, configFileName); | ||
|
||
if (fs.existsSync(targetFilePath)) { | ||
console.error( | ||
`Error: The file ${configFileName} already exists in '${targetDirectory}'. Please remove or rename it.`, | ||
); | ||
return; | ||
} | ||
|
||
fs.copyFile(defaultConfigPath, targetFilePath, (error) => { | ||
if (error) { | ||
console.error('Error copying the config file:', error); | ||
} else { | ||
console.log( | ||
`Config was successfully initialized in ${targetFilePath}`, | ||
); | ||
console.log('Edit it using the following command:'); | ||
console.log(` nano '${targetFilePath}'`); | ||
} | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
|
||
export const packageInfo = JSON.parse( | ||
fs.readFileSync(path.join(__dirname, '../package.json'), 'utf8'), | ||
); |