@unsetsoft/ryunix-presets 1.0.16 → 1.0.18

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.
@@ -1,203 +1,210 @@
1
- import { createHash } from 'node:crypto'
2
- import { resolve } from 'path'
3
-
4
- import { promises as fs } from 'fs'
5
- import { join, dirname } from 'path'
6
- import { fileURLToPath } from 'url'
7
- import logger from 'terminal-log'
8
- import chalk from 'chalk'
9
-
10
- const resolveApp = (appDirectory, relativePath) =>
11
- resolve(appDirectory, relativePath)
12
-
13
- function getPackageManager() {
14
- const agent = process.env.npm_config_user_agent
15
-
16
- if (!agent) {
17
- const parent = process.env._
18
-
19
- if (!parent) {
20
- return 'npm'
21
- }
22
-
23
- if (parent.endsWith('pnpx') || parent.endsWith('pnpm')) return 'pnpm'
24
- if (parent.endsWith('bunx') || parent.endsWith('bun')) return 'bun'
25
- if (parent.endsWith('yarn')) return 'yarn'
26
-
27
- return 'npm'
28
- }
29
-
30
- const [program] = agent.split('/')
31
-
32
- if (program === 'yarn') return 'yarn'
33
- if (program === 'pnpm') return 'pnpm'
34
- if (program === 'bun') return 'bun'
35
-
36
- return 'npm'
37
- }
38
-
39
- const ENV_HASH = (env) => {
40
- const hash = createHash('md5')
41
- hash.update(JSON.stringify(env))
42
-
43
- return hash.digest('hex')
44
- }
45
-
46
- const RYUNIX_APP = /^RYUNIX_APP_/i
47
-
48
- const getEnviroment = () =>
49
- Object.keys(process.env)
50
- .filter((key) => RYUNIX_APP.test(key))
51
- .reduce(
52
- (env, key) => {
53
- env[key] = process.env[key]
54
- return env
55
- },
56
- {
57
- NODE_ENV: process.env.NODE_ENV || 'development',
58
- },
59
- )
60
-
61
- const getPackageVersion = async () => {
62
- const __dirname = dirname(fileURLToPath(import.meta.url)) // Para obtener el directorio actual
63
- const packageJsonPath = join(__dirname, '..', '..', '..', 'ryunixjs', 'package.json')
64
- const data = await fs.readFile(packageJsonPath, 'utf-8')
65
- const packageJson = JSON.parse(data)
66
- return packageJson
67
- }
68
-
69
- async function cleanCacheDir(dirPath) {
70
- try {
71
- await fs.access(dirPath)
72
- await fs.rm(dirPath, { recursive: true, force: true })
73
- logger.info(
74
- `webpack cache cleaned ${chalk.bold(chalk.green('successfully'))}`,
75
- )
76
- } catch (err) {
77
- // Directory does not exist or some error occurred
78
- if (err.code === 'ENOENT') {
79
- logger.info(`webpack cache cleaned ${chalk.red('failed')}`)
80
- } else {
81
- throw err // or handle error accordingly
82
- }
83
- }
84
- }
85
-
86
- async function cleanBuildDirectory(dirPath) {
87
- try {
88
- await fs.access(dirPath)
89
- await fs.rm(dirPath, { recursive: true, force: true })
90
- logger.info(
91
- `static folder cleaned ${chalk.bold(chalk.green('successfully'))}`,
92
- )
93
- } catch (err) {
94
- // Directory does not exist or some error occurred
95
-
96
- if (err.code === 'ENOENT') {
97
- logger.info(`static folder cleaned ${chalk.red('failed')}`)
98
- } else {
99
- throw err // or handle error accordingly
100
- }
101
- }
102
- }
103
-
104
- // utils/convertFlatToClassic.js
105
- export function convertFlatToClassic(configArray) {
106
- const combined = {
107
- env: {},
108
- globals: {},
109
- parserOptions: {},
110
- plugins: new Set(),
111
- extends: new Set(),
112
- rules: {},
113
- parser: undefined,
114
- }
115
-
116
- const invalidKeys = new Set()
117
-
118
- for (const cfg of configArray) {
119
- // Detectar keys inválidas
120
- for (const key of Object.keys(cfg)) {
121
- if (
122
- ![
123
- 'env',
124
- 'globals',
125
- 'parserOptions',
126
- 'plugins',
127
- 'extends',
128
- 'rules',
129
- 'parser',
130
- 'languageOptions',
131
- ].includes(key)
132
- ) {
133
- invalidKeys.add(key)
134
- }
135
- }
136
-
137
- // Combinar env
138
- if (cfg.env) Object.assign(combined.env, cfg.env)
139
-
140
- // Combinar globals
141
- if (cfg.globals) Object.assign(combined.globals, cfg.globals)
142
-
143
- // Combinar parserOptions
144
- if (cfg.languageOptions?.parserOptions) {
145
- Object.assign(combined.parserOptions, cfg.languageOptions.parserOptions)
146
- } else if (cfg.parserOptions) {
147
- Object.assign(combined.parserOptions, cfg.parserOptions)
148
- }
149
-
150
- // Combinar plugins
151
- if (cfg.plugins) {
152
- if (Array.isArray(cfg.plugins)) {
153
- cfg.plugins.forEach((p) => combined.plugins.add(p))
154
- } else if (typeof cfg.plugins === 'object' && cfg.plugins !== null) {
155
- Object.keys(cfg.plugins).forEach((p) => combined.plugins.add(p))
156
- }
157
- }
158
-
159
- // Combinar extends
160
- if (cfg.extends) {
161
- if (Array.isArray(cfg.extends)) {
162
- cfg.extends.forEach((e) => combined.extends.add(e))
163
- } else if (typeof cfg.extends === 'string') {
164
- combined.extends.add(cfg.extends)
165
- }
166
- }
167
-
168
- // Combinar reglas
169
- if (cfg.rules) Object.assign(combined.rules, cfg.rules)
170
-
171
- // Parser
172
- if (cfg.languageOptions?.parser) {
173
- combined.parser = cfg.languageOptions.parser
174
- } else if (cfg.parser) {
175
- combined.parser = cfg.parser
176
- }
177
- }
178
-
179
- return {
180
- env: Object.keys(combined.env).length ? combined.env : undefined,
181
- globals: Object.keys(combined.globals).length
182
- ? combined.globals
183
- : undefined,
184
- parserOptions: Object.keys(combined.parserOptions).length
185
- ? combined.parserOptions
186
- : undefined,
187
- plugins: combined.plugins.size ? Array.from(combined.plugins) : undefined,
188
- extends: combined.extends.size ? Array.from(combined.extends) : undefined,
189
- rules: combined.rules,
190
- parser: combined.parser,
191
- }
192
- }
193
-
194
- export {
195
- getPackageManager,
196
- ENV_HASH,
197
- getEnviroment,
198
- resolveApp,
199
- RYUNIX_APP,
200
- getPackageVersion,
201
- cleanCacheDir,
202
- cleanBuildDirectory,
203
- }
1
+ import { createHash } from 'node:crypto'
2
+ import { resolve } from 'path'
3
+
4
+ import { promises as fs } from 'fs'
5
+ import { join, dirname } from 'path'
6
+ import { fileURLToPath } from 'url'
7
+ import logger from 'terminal-log'
8
+ import chalk from 'chalk'
9
+
10
+ const resolveApp = (appDirectory, relativePath) =>
11
+ resolve(appDirectory, relativePath)
12
+
13
+ function getPackageManager() {
14
+ const agent = process.env.npm_config_user_agent
15
+
16
+ if (!agent) {
17
+ const parent = process.env._
18
+
19
+ if (!parent) {
20
+ return 'npm'
21
+ }
22
+
23
+ if (parent.endsWith('pnpx') || parent.endsWith('pnpm')) return 'pnpm'
24
+ if (parent.endsWith('bunx') || parent.endsWith('bun')) return 'bun'
25
+ if (parent.endsWith('yarn')) return 'yarn'
26
+
27
+ return 'npm'
28
+ }
29
+
30
+ const [program] = agent.split('/')
31
+
32
+ if (program === 'yarn') return 'yarn'
33
+ if (program === 'pnpm') return 'pnpm'
34
+ if (program === 'bun') return 'bun'
35
+
36
+ return 'npm'
37
+ }
38
+
39
+ const ENV_HASH = (env) => {
40
+ const hash = createHash('md5')
41
+ hash.update(JSON.stringify(env))
42
+
43
+ return hash.digest('hex')
44
+ }
45
+
46
+ const RYUNIX_APP = /^RYUNIX_APP_/i
47
+
48
+ const getEnviroment = () =>
49
+ Object.keys(process.env)
50
+ .filter((key) => RYUNIX_APP.test(key))
51
+ .reduce(
52
+ (env, key) => {
53
+ env[key] = process.env[key]
54
+ return env
55
+ },
56
+ {
57
+ NODE_ENV: process.env.NODE_ENV || 'development',
58
+ },
59
+ )
60
+
61
+ const getPackageVersion = async () => {
62
+ const __dirname = dirname(fileURLToPath(import.meta.url)) // Para obtener el directorio actual
63
+ const packageJsonPath = join(
64
+ __dirname,
65
+ '..',
66
+ '..',
67
+ '..',
68
+ 'ryunixjs',
69
+ 'package.json',
70
+ )
71
+ const data = await fs.readFile(packageJsonPath, 'utf-8')
72
+ const packageJson = JSON.parse(data)
73
+ return packageJson
74
+ }
75
+
76
+ async function cleanCacheDir(dirPath) {
77
+ try {
78
+ await fs.access(dirPath)
79
+ await fs.rm(dirPath, { recursive: true, force: true })
80
+ logger.info(
81
+ `webpack cache cleaned ${chalk.bold(chalk.green('successfully'))}`,
82
+ )
83
+ } catch (err) {
84
+ // Directory does not exist or some error occurred
85
+ if (err.code === 'ENOENT') {
86
+ logger.info(`webpack cache cleaned ${chalk.red('failed')}`)
87
+ } else {
88
+ throw err // or handle error accordingly
89
+ }
90
+ }
91
+ }
92
+
93
+ async function cleanBuildDirectory(dirPath) {
94
+ try {
95
+ await fs.access(dirPath)
96
+ await fs.rm(dirPath, { recursive: true, force: true })
97
+ logger.info(
98
+ `static folder cleaned ${chalk.bold(chalk.green('successfully'))}`,
99
+ )
100
+ } catch (err) {
101
+ // Directory does not exist or some error occurred
102
+
103
+ if (err.code === 'ENOENT') {
104
+ logger.info(`static folder cleaned ${chalk.red('failed')}`)
105
+ } else {
106
+ throw err // or handle error accordingly
107
+ }
108
+ }
109
+ }
110
+
111
+ // utils/convertFlatToClassic.js
112
+ export function convertFlatToClassic(configArray) {
113
+ const combined = {
114
+ env: {},
115
+ globals: {},
116
+ parserOptions: {},
117
+ plugins: new Set(),
118
+ extends: new Set(),
119
+ rules: {},
120
+ parser: undefined,
121
+ }
122
+
123
+ const invalidKeys = new Set()
124
+
125
+ for (const cfg of configArray) {
126
+ // Detectar keys inválidas
127
+ for (const key of Object.keys(cfg)) {
128
+ if (
129
+ ![
130
+ 'env',
131
+ 'globals',
132
+ 'parserOptions',
133
+ 'plugins',
134
+ 'extends',
135
+ 'rules',
136
+ 'parser',
137
+ 'languageOptions',
138
+ ].includes(key)
139
+ ) {
140
+ invalidKeys.add(key)
141
+ }
142
+ }
143
+
144
+ // Combinar env
145
+ if (cfg.env) Object.assign(combined.env, cfg.env)
146
+
147
+ // Combinar globals
148
+ if (cfg.globals) Object.assign(combined.globals, cfg.globals)
149
+
150
+ // Combinar parserOptions
151
+ if (cfg.languageOptions?.parserOptions) {
152
+ Object.assign(combined.parserOptions, cfg.languageOptions.parserOptions)
153
+ } else if (cfg.parserOptions) {
154
+ Object.assign(combined.parserOptions, cfg.parserOptions)
155
+ }
156
+
157
+ // Combinar plugins
158
+ if (cfg.plugins) {
159
+ if (Array.isArray(cfg.plugins)) {
160
+ cfg.plugins.forEach((p) => combined.plugins.add(p))
161
+ } else if (typeof cfg.plugins === 'object' && cfg.plugins !== null) {
162
+ Object.keys(cfg.plugins).forEach((p) => combined.plugins.add(p))
163
+ }
164
+ }
165
+
166
+ // Combinar extends
167
+ if (cfg.extends) {
168
+ if (Array.isArray(cfg.extends)) {
169
+ cfg.extends.forEach((e) => combined.extends.add(e))
170
+ } else if (typeof cfg.extends === 'string') {
171
+ combined.extends.add(cfg.extends)
172
+ }
173
+ }
174
+
175
+ // Combinar reglas
176
+ if (cfg.rules) Object.assign(combined.rules, cfg.rules)
177
+
178
+ // Parser
179
+ if (cfg.languageOptions?.parser) {
180
+ combined.parser = cfg.languageOptions.parser
181
+ } else if (cfg.parser) {
182
+ combined.parser = cfg.parser
183
+ }
184
+ }
185
+
186
+ return {
187
+ env: Object.keys(combined.env).length ? combined.env : undefined,
188
+ globals: Object.keys(combined.globals).length
189
+ ? combined.globals
190
+ : undefined,
191
+ parserOptions: Object.keys(combined.parserOptions).length
192
+ ? combined.parserOptions
193
+ : undefined,
194
+ plugins: combined.plugins.size ? Array.from(combined.plugins) : undefined,
195
+ extends: combined.extends.size ? Array.from(combined.extends) : undefined,
196
+ rules: combined.rules,
197
+ parser: combined.parser,
198
+ }
199
+ }
200
+
201
+ export {
202
+ getPackageManager,
203
+ ENV_HASH,
204
+ getEnviroment,
205
+ resolveApp,
206
+ RYUNIX_APP,
207
+ getPackageVersion,
208
+ cleanCacheDir,
209
+ cleanBuildDirectory,
210
+ }
@@ -1,33 +1,33 @@
1
- 'use strict'
2
-
3
- const fs = require('fs')
4
- const path = require('path')
5
-
6
- const defaultConfigFile = path.join(process.cwd(), 'ryunix.config.js')
7
- const commonConfigFile = path.join(process.cwd(), 'ryunix.config.cjs')
8
-
9
- const configFileExist = () => {
10
- return fs.existsSync(defaultConfigFile) || fs.existsSync(commonConfigFile)
11
- }
12
-
13
- const getConfig = () => {
14
- try {
15
- if (fs.existsSync(defaultConfigFile)) {
16
- const { default: config } = require(defaultConfigFile)
17
-
18
- return config
19
- } else if (fs.existsSync(commonConfigFile)) {
20
- const config = require(commonConfigFile)
21
- return config
22
- }
23
-
24
- return {}
25
- } catch (error) {
26
- console.error(error)
27
- }
28
- }
29
-
30
- module.exports = {
31
- getConfig,
32
- configFileExist,
33
- }
1
+ 'use strict'
2
+
3
+ const fs = require('fs')
4
+ const path = require('path')
5
+
6
+ const defaultConfigFile = path.join(process.cwd(), 'ryunix.config.js')
7
+ const commonConfigFile = path.join(process.cwd(), 'ryunix.config.cjs')
8
+
9
+ const configFileExist = () => {
10
+ return fs.existsSync(defaultConfigFile) || fs.existsSync(commonConfigFile)
11
+ }
12
+
13
+ const getConfig = () => {
14
+ try {
15
+ if (fs.existsSync(defaultConfigFile)) {
16
+ const { default: config } = require(defaultConfigFile)
17
+
18
+ return config
19
+ } else if (fs.existsSync(commonConfigFile)) {
20
+ const config = require(commonConfigFile)
21
+ return config
22
+ }
23
+
24
+ return {}
25
+ } catch (error) {
26
+ console.error(error)
27
+ }
28
+ }
29
+
30
+ module.exports = {
31
+ getConfig,
32
+ configFileExist,
33
+ }