• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ipetinate / clingon / 9651901754

24 Jun 2024 08:21PM UTC coverage: 94.098% (-4.8%) from 98.875%
9651901754

push

github

web-flow
Merge pull request #52 from ipetinate/feat/advanced-command

feat: Advanced command

427 of 440 branches covered (97.05%)

Branch coverage included in aggregate %.

979 of 1128 new or added lines in 15 files covered. (86.79%)

35 existing lines in 4 files now uncovered.

3033 of 3237 relevant lines covered (93.7%)

2.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

55.65
/src/utils/init-action.js
1
import { join } from 'node:path'
1✔
2

1✔
3
import {
1✔
4
  checkFileExists,
1✔
5
  createFileWithContent,
1✔
6
  readFileContent
1✔
7
} from './file.js'
1✔
8
import {
1✔
9
  checkDirectoriesTree,
1✔
10
  createDir,
1✔
11
  getLocalLibDirname
1✔
12
} from './directory.js'
1✔
13
import { createPresetsFolder } from './preset.js'
1✔
14
import {
1✔
15
  globalCoreFiles,
1✔
16
  presetsCoreFiles,
1✔
17
  templateCoreFiles
1✔
18
} from '../constants/init.js'
1✔
19
import { splitPathString } from './string.js'
1✔
20

1✔
21
/*
1✔
22
 * ----------------------------------------
1✔
23
 *             Global Config
1✔
24
 * ----------------------------------------
1✔
25
 */
1✔
26

1✔
27
/**
1✔
28
 * Get config file path
1✔
29
 *
1✔
30
 * @param {boolean} examples Should generate examples
1✔
31
 * @returns {() => ({ fullPath: string, examples: examples })}
1✔
32
 */
1✔
33
export function getConfigFilePath(examples) {
1✔
34
  return () => {
2✔
35
    const fullPath = join(process.cwd(), 'clingon.config.json')
2✔
36
    const fileExists = checkFileExists(fullPath)
2✔
37

2✔
38
    if (!fileExists) {
2!
NEW
39
      return { fullPath: undefined, examples }
×
NEW
40
    }
×
41

2✔
42
    return { fullPath, examples }
2✔
43
  }
2✔
44
}
2✔
45

1✔
46
/**
1✔
47
 * Create the config file if it does not exist
1✔
48
 *
1✔
49
 * @param {{ fullPath: string, examples: boolean }} props Props
1✔
50
 * @returns {{ fullPath: string, examples: boolean }}
1✔
51
 */
1✔
52
export function createFileIfNotExists({ examples, fullPath }) {
1✔
53
  if (fullPath) {
1✔
54
    console.info('\n✅ You already have config at: ', fullPath)
1✔
55

1✔
56
    return fullPath
1✔
57
  }
1!
58

×
NEW
59
  const success = createFolderAssets(globalCoreFiles, process.cwd())
×
60

×
61
  if (success) {
×
NEW
62
    console.info(
×
NEW
63
      '🌎 Global config file created at: ',
×
NEW
64
      join(process.cwd(), 'clingon.config.json')
×
NEW
65
    )
×
66
  } else {
×
67
    console.error('❌ Error: Cannot create global config file, try again.')
×
68
  }
×
69

×
NEW
70
  return { fullPath, examples }
×
71
}
1✔
72

1✔
73
/*
1✔
74
 * ----------------------------------------
1✔
75
 *             Presets Folder
1✔
76
 * ----------------------------------------
1✔
77
 */
1✔
78

1✔
79
const presetsDir = 'presets'
1✔
80
const dotClingonDir = '.clingon'
1✔
81
const presetsFullDir = join(process.cwd(), dotClingonDir, presetsDir)
1✔
82

1✔
83
/**
1✔
84
 * Check if `.clingon/prests` folder exists
1✔
85
 *
1✔
86
 * @returns {() => ({ exists: boolean, examples: boolean })}
1✔
87
 */
1✔
88
export function checkIfPresetFolderAlreadyExists(examples) {
1✔
89
  const exists = checkDirectoriesTree([dotClingonDir, presetsDir])
1✔
90

1✔
91
  return () => ({ exists, examples })
1✔
92
}
1✔
93

1✔
94
/**
1✔
95
 * Create `.clingon/prests` if not exists
1✔
96
 *
1✔
97
 * @param {{ exists: boolean, examples: boolean }} props Props
1✔
98
 */
1✔
99
export function createPresetFolderIfNotExists({ exists, examples }) {
1✔
NEW
100
  if (exists && !examples) {
×
NEW
101
    console.info('\n✅ You already have presets folder at: ', presetsFullDir)
×
102

×
NEW
103
    return { exists, examples }
×
NEW
104
  }
×
NEW
105

×
NEW
106
  exists = createDir(presetsFullDir)
×
NEW
107

×
NEW
108
  if (exists) {
×
NEW
109
    const message = examples
×
NEW
110
      ? 'Presets examples created at: '
×
NEW
111
      : 'Presets created at: '
×
NEW
112

×
NEW
113
    console.info(`\n🎛️  ${message}`, presetsFullDir)
×
NEW
114
  } else {
×
NEW
115
    console.error('\n❌ Error: cannot create presets dir, try again.')
×
NEW
116
  }
×
NEW
117

×
NEW
118
  return { exists, examples }
×
NEW
119
}
×
120

1✔
121
/**
1✔
122
 * Create readme and meta file at `.clingon/templates`
1✔
123
 *
1✔
124
 * @param {{ exists: boolean, examples: boolean }} props Props
1✔
125
 */
1✔
126
export function createPresetsFolderAssets({ examples, exists }) {
1✔
NEW
127
  if (!examples) return
×
NEW
128

×
NEW
129
  try {
×
NEW
130
    if (!exists) throw new Error('Cannot create folder to place files')
×
NEW
131

×
NEW
132
    createFolderAssets(presetsCoreFiles, presetsFullDir)
×
NEW
133
  } catch (error) {
×
NEW
134
    console.error(error)
×
NEW
135
  }
×
136
}
×
137

1✔
138
/*
1✔
139
 * ----------------------------------------
1✔
140
 *             Templates Folder
1✔
141
 * ----------------------------------------
1✔
142
 */
1✔
143

1✔
144
const templatesDir = 'templates'
1✔
145
const templatesFullDir = join(process.cwd(), dotClingonDir, templatesDir)
1✔
146

1✔
147
/**
1✔
148
 * Check if `.clingon/templates` folder exists
1✔
149
 */
1✔
150
export function checkIfTemplateFolderAlreadyExists(examples) {
1✔
NEW
151
  const exists = checkDirectoriesTree([dotClingonDir, templatesDir])
×
NEW
152

×
NEW
153
  return () => ({ exists, examples })
×
154
}
×
155

1✔
156
/**
1✔
157
 * Create `.clingon/templates` if not exists
1✔
158
 *
1✔
159
 * @param {{ exists: boolean, examples: boolean }} props Props
1✔
160
 */
1✔
161
export function createTemplateFolderIfNotExists({ examples, exists }) {
1✔
NEW
162
  if (exists && !examples) {
×
NEW
163
    console.info(
×
NEW
164
      '\n✅ You already have templates folder at: ',
×
NEW
165
      templatesFullDir
×
166
    )
×
NEW
167

×
NEW
168
    return { examples, exists }
×
NEW
169
  }
×
NEW
170

×
NEW
171
  exists = createDir(templatesFullDir)
×
NEW
172

×
NEW
173
  if (exists) {
×
NEW
174
    const message = examples
×
NEW
175
      ? 'Templates examples created at:'
×
NEW
176
      : 'Templates created at:'
×
NEW
177

×
NEW
178
    console.info(`\n📂 ${message} `, templatesFullDir)
×
NEW
179
  } else {
×
NEW
180
    console.error('\n❌ Error: cannot create templates dir, try again')
×
181
  }
×
182

×
NEW
183
  return { examples, exists }
×
NEW
184
}
×
185

1✔
186
/**
1✔
187
 * Create readme and meta file at `.clingon/templates`
1✔
188
 *
1✔
189
 * @param {{ exists: boolean, examples: boolean }} props Props
1✔
190
 */
1✔
191
export function createTemplateFolderAssets({ examples, exists }) {
1✔
NEW
192
  if (!examples) return
×
NEW
193

×
NEW
194
  try {
×
NEW
195
    if (!exists) throw new Error('Cannot create folder to place files')
×
196

×
NEW
197
    createFolderAssets(templateCoreFiles, templatesFullDir)
×
NEW
198
  } catch (error) {
×
NEW
199
    console.error(error)
×
NEW
200
  }
×
NEW
201
}
×
202

1✔
203
/*
1✔
204
 * ----------------------------------------
1✔
205
 *             Handle Examples
1✔
206
 * ----------------------------------------
1✔
207
 */
1✔
208

1✔
209
/**
1✔
210
 * Create file based on json
1✔
211
 *
1✔
212
 * @param {{ folder: string, target: string, files: string[] }} data Data
1✔
213
 */
1✔
214
export function createFolderAssets(data, path) {
1✔
NEW
215
  try {
×
NEW
216
    const localDirname = getLocalLibDirname()
×
NEW
217

×
NEW
218
    data.forEach((item) => {
×
NEW
219
      let target = join(path, item.target)
×
NEW
220

×
NEW
221
      let exists = checkDirectoriesTree(splitPathString(target))
×
NEW
222

×
NEW
223
      if (!exists) createDir(target)
×
NEW
224

×
NEW
225
      item.files.forEach((file) => {
×
NEW
226
        const fileName = join(target, file)
×
NEW
227

×
NEW
228
        const fileContent = readFileContent(
×
NEW
229
          join(localDirname, item.folder, file)
×
NEW
230
        )
×
NEW
231

×
NEW
232
        return createFileWithContent(fileName, fileContent)
×
NEW
233
      })
×
NEW
234
    })
×
NEW
235

×
NEW
236
    return true
×
NEW
237
  } catch (error) {
×
NEW
238
    console.error(error)
×
NEW
239
  }
×
240
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc