1 | #!/usr/bin/env node
|
2 | const fs = require('fs')
|
3 | const path = require('path')
|
4 | const colors = require('./colors')
|
5 | const readline = require('readline')
|
6 |
|
7 | const rl = readline.createInterface({
|
8 | input: process.stdin,
|
9 | output: process.stdout
|
10 | })
|
11 |
|
12 | function createCustomFile (homeFilePath, theme) {
|
13 | const themePath = path.resolve(__dirname, `themes/${theme}.js`)
|
14 | if (!fs.existsSync(themePath)) {
|
15 | console.error(colors.red('[x] '), 'Sorry, this theme is not installed!\n')
|
16 | return
|
17 | }
|
18 | try {
|
19 | fs.copyFileSync(
|
20 | themePath,
|
21 | homeFilePath,
|
22 | )
|
23 | console.log(
|
24 | 'Created file at ' + colors.bold.underline(homeFilePath) +
|
25 | '\nFeel free to apply changes to that file.',
|
26 | '\nFollow the comments in it, or refer to our documentation.'
|
27 | )
|
28 | } catch (error) {
|
29 | console.error(colors.red('[x] '), 'Could not create your custom file!\n', error)
|
30 | }
|
31 | }
|
32 |
|
33 | module.exports = function (homePath, theme = 'default') {
|
34 | const homeFilePath = path.resolve(homePath, '.bash_profile.js')
|
35 | let fileExists = false
|
36 | try {
|
37 | fs.accessSync(homeFilePath)
|
38 | fileExists = true
|
39 | } catch (error) {}
|
40 | if (fileExists) {
|
41 | rl.question('You already have a custom file in your home directory.\n' +
|
42 | `Are your sure you want to ${colors.bold('overwrite')} it?\n`+
|
43 | 'You WILL LOOSE any customization you had in your ~/.bash_profile.js and this can\'t be undone!\n' +
|
44 | `\n yes or no ? `, (answer) => {
|
45 | console.log('')
|
46 | if (answer.toLowerCase().startsWith('y')) {
|
47 | createCustomFile(homeFilePath, theme)
|
48 | }
|
49 | rl.close()
|
50 | });
|
51 | } else {
|
52 | createCustomFile(homeFilePath, theme)
|
53 | rl.close()
|
54 | }
|
55 | } |
\ | No newline at end of file |