@alessiofrittoli/package-configs 1.8.0-alpha.3 → 1.8.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/scripts/install-dependencies.cjs +142 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alessiofrittoli/package-configs",
|
|
3
|
-
"version": "1.8.0-alpha.
|
|
3
|
+
"version": "1.8.0-alpha.4",
|
|
4
4
|
"description": "Utility library that offers base configurations for your packages.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": {
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"types": "./dist/index.d.mts",
|
|
41
41
|
"files": [
|
|
42
42
|
"dist",
|
|
43
|
-
"scripts/
|
|
43
|
+
"scripts/install-dependencies.cjs"
|
|
44
44
|
],
|
|
45
45
|
"exports": {
|
|
46
46
|
".": {
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
const { execSync } = require('child_process')
|
|
2
|
+
const prompts = require('prompts')
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Check whether script is running in a CI environment.
|
|
6
|
+
*
|
|
7
|
+
* @remarks Check if `CI` or `GITHUB_ACTIONS` is `true` or `GITHUB_WORKFLOW` is defined.
|
|
8
|
+
*
|
|
9
|
+
* @returns `true` if the script is running in a CI environment, `false` otherwise.
|
|
10
|
+
*/
|
|
11
|
+
const isCIEnv = () =>
|
|
12
|
+
process.env.CI === 'true' ||
|
|
13
|
+
process.env.GITHUB_ACTIONS === 'true' ||
|
|
14
|
+
typeof process.env.GITHUB_WORKFLOW !== 'undefined'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Removes duplicate values from an array.
|
|
18
|
+
*
|
|
19
|
+
* @param array The input array.
|
|
20
|
+
* @returns The filtered array.
|
|
21
|
+
*/
|
|
22
|
+
const arrayUnique = array => (array.length <= 0 ? array : [...new Set(array)])
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Retrieves the root directory of the current process.
|
|
26
|
+
*
|
|
27
|
+
* @returns The root directory of the current process, determined by the `INIT_CWD` environment variable if set,
|
|
28
|
+
* otherwise the current working directory.
|
|
29
|
+
*/
|
|
30
|
+
const getProcessRoot = () => process.env.INIT_CWD || process.cwd()
|
|
31
|
+
|
|
32
|
+
const installDependencies = async () => {
|
|
33
|
+
if (isCIEnv()) {
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const cwd = getProcessRoot()
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
const { installDeps } = await prompts([
|
|
41
|
+
{
|
|
42
|
+
type: 'confirm',
|
|
43
|
+
name: 'installDeps',
|
|
44
|
+
message: 'Would you like to install optional dependencies?',
|
|
45
|
+
initial: true,
|
|
46
|
+
},
|
|
47
|
+
])
|
|
48
|
+
|
|
49
|
+
if (!installDeps) {
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const { _dependenciesChoice } = await prompts([
|
|
54
|
+
{
|
|
55
|
+
type: 'multiselect',
|
|
56
|
+
name: '_dependenciesChoice',
|
|
57
|
+
message: "Please, select which tool you're going to use",
|
|
58
|
+
choices: [
|
|
59
|
+
{
|
|
60
|
+
title: 'Vite',
|
|
61
|
+
selected: true,
|
|
62
|
+
description: 'Will install Vite',
|
|
63
|
+
value: ['vite'],
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
title: 'Vitest',
|
|
67
|
+
selected: true,
|
|
68
|
+
description: 'Will install Vitest',
|
|
69
|
+
value: ['vitest', '@vitest/coverage-v8'],
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
title: 'Oxlint',
|
|
73
|
+
selected: true,
|
|
74
|
+
description: 'Will install Oxlint',
|
|
75
|
+
value: ['oxlint', 'oxlint-tsgolint'],
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
title: 'Prettier',
|
|
79
|
+
selected: true,
|
|
80
|
+
description: 'Will install Prettier',
|
|
81
|
+
value: ['prettier', 'prettier-plugin-sort-imports'],
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
title: 'tsdown',
|
|
85
|
+
selected: true,
|
|
86
|
+
description: 'Will install tsdown',
|
|
87
|
+
value: ['tsdown'],
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
title: 'ESLint',
|
|
91
|
+
selected: false,
|
|
92
|
+
description: 'Will install ESLint dev dependencies',
|
|
93
|
+
value: [
|
|
94
|
+
'eslint',
|
|
95
|
+
'@eslint/compat',
|
|
96
|
+
'@eslint/eslintrc',
|
|
97
|
+
'@eslint/js',
|
|
98
|
+
'globals',
|
|
99
|
+
'typescript-eslint',
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
title: 'Next.js',
|
|
104
|
+
description: 'Will install Next.js related ESLint dev dependencies',
|
|
105
|
+
selected: false,
|
|
106
|
+
value: [
|
|
107
|
+
'eslint',
|
|
108
|
+
'@eslint/compat',
|
|
109
|
+
'@eslint/eslintrc',
|
|
110
|
+
'@eslint/js',
|
|
111
|
+
'globals',
|
|
112
|
+
'typescript-eslint',
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
},
|
|
117
|
+
])
|
|
118
|
+
|
|
119
|
+
if (!_dependenciesChoice) {
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const dependenciesChoice = arrayUnique(_dependenciesChoice.flatMap(c => c))
|
|
124
|
+
|
|
125
|
+
let engine = 'npm'
|
|
126
|
+
|
|
127
|
+
try {
|
|
128
|
+
execSync('pnpm -v', { cwd, stdio: 'ignore' })
|
|
129
|
+
engine = 'pnpm'
|
|
130
|
+
} catch {
|
|
131
|
+
engine = 'npm'
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const installCommand = engine === 'npm' ? 'npm install --save-dev' : 'pnpm add --save-dev'
|
|
135
|
+
|
|
136
|
+
execSync(`${installCommand} ${dependenciesChoice.join(' ')}`, { cwd, stdio: 'inherit' })
|
|
137
|
+
} catch {
|
|
138
|
+
return
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
installDependencies().catch(console.error)
|