@unsetsoft/ryunix-presets 1.0.0 → 1.0.14

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.
@@ -0,0 +1,85 @@
1
+ export interface Settings {
2
+ static: {
3
+ favicon: boolean
4
+ customTemplate: string | false
5
+ seo: {
6
+ pageLang: string
7
+ title: string
8
+ meta: {
9
+ description?: string
10
+ keywords?: string
11
+ subject?: string
12
+ copyright?: string
13
+ language?: string
14
+ robots?: string
15
+ revised?: string
16
+ abstract?: string
17
+ topic?: string
18
+ summary?: string
19
+ classification?: string
20
+ author?: string
21
+ designer?: string
22
+ replyTo?: string
23
+ owner?: string
24
+ url?: string
25
+ identifierURL?: string
26
+ directory?: string
27
+ pageName?: string
28
+ category?: string
29
+ coverage?: string
30
+ distribution?: string
31
+ rating?: string
32
+ revisitAfter?: string
33
+ subtitle?: string
34
+ target?: string
35
+ handheldFriendly?: string
36
+ mobileOptimized?: string
37
+ date?: string
38
+ searchDate?: string
39
+ dcTitle?: string
40
+ resourceLoaderDynamicStyles?: string
41
+ medium?: string
42
+ syndicationSource?: string
43
+ originalSource?: string
44
+ verifyV1?: string
45
+ yKey?: string
46
+ pageKey?: string
47
+ itemPropName?: string
48
+ [key: string]: any
49
+ }
50
+ }
51
+ }
52
+
53
+ eslint: {
54
+ files: string[]
55
+ plugins: Record<string, any>
56
+ rules: Record<string, any>
57
+ }
58
+
59
+ webpack: {
60
+ production: boolean
61
+ root: string
62
+ output: {
63
+ buildDirectory: string
64
+ }
65
+ target: string
66
+ resolve: {
67
+ alias: Record<string, any>
68
+ fallback: Record<string, any>
69
+ extensions: string[]
70
+ }
71
+ plugins: object[]
72
+ devServer: {
73
+ port: number
74
+ proxy: Record<string, any>
75
+ allowedHosts: 'auto' | 'all' | string[]
76
+ }
77
+ externals: object[]
78
+ module: {
79
+ rules: object[]
80
+ }
81
+ experiments: {
82
+ lazyCompilation: boolean
83
+ }
84
+ }
85
+ }
@@ -0,0 +1,31 @@
1
+ import config from './utils/config.cjs'
2
+ import { resolveApp } from './utils/index.mjs'
3
+ import { defineConfig } from 'eslint/config'
4
+ const dir = process.cwd()
5
+
6
+ const eslintConfig = defineConfig([
7
+ {
8
+ files: ['**/*.ryx', ...config?.eslint?.files],
9
+ languageOptions: {
10
+ ecmaVersion: 2021,
11
+ sourceType: 'module',
12
+
13
+ parserOptions: {
14
+ ecmaFeatures: {
15
+ jsx: true,
16
+ },
17
+ extraFileExtensions: ['.ryx'],
18
+ },
19
+ },
20
+ settings: {
21
+ react: {
22
+ pragma: 'Ryunix.createElement', // Para JSX transpile a Ryunix.createElement
23
+ fragment: 'Ryunix.Fragment', // Para fragmentos JSX
24
+ },
25
+ },
26
+ plugins: config?.eslint?.plugins,
27
+ rules: config?.eslint?.rules,
28
+ },
29
+ ])
30
+
31
+ export default eslintConfig
@@ -0,0 +1,6 @@
1
+ import webpackConfig from './webpack.config.mjs'
2
+
3
+ const ryunixWebpack = () => webpackConfig
4
+
5
+ export default ryunixWebpack
6
+ export { ryunixWebpack }
@@ -0,0 +1,19 @@
1
+ <!doctype html>
2
+ <html lang="<%= htmlWebpackPlugin.options.pageLang %>">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
6
+ <meta
7
+ name="framework"
8
+ content="<%= htmlWebpackPlugin.options.info.framework %>"
9
+ version="<%= htmlWebpackPlugin.options.info.version %>"
10
+ />
11
+ <meta name="mode" content="<%= htmlWebpackPlugin.options.info.mode %>" />
12
+ <link rel="icon" href="/favicon.png" />
13
+ <title><%= htmlWebpackPlugin.options.title %></title>
14
+ </head>
15
+ <body>
16
+ <noscript>You need to enable JavaScript to run this app.</noscript>
17
+ <div id="__ryunix"></div>
18
+ </body>
19
+ </html>
@@ -0,0 +1,190 @@
1
+ 'use strict'
2
+ const { getConfig } = require('./settingfile.cjs')
3
+ const reactPlugin = require('eslint-plugin-react')
4
+ const config = getConfig()
5
+
6
+ const defaultSettings = {
7
+ experimental: {
8
+ ssg: {
9
+ sitemap: {
10
+ // allow sitemap generation
11
+ enable: config?.experimental?.ssg?.sitemap?.enable
12
+ ? config.experimental.ssg.sitemap.enable
13
+ : false,
14
+ // base url. ex: https://example.com
15
+ baseURL: config?.experimental?.ssg?.sitemap?.baseURL
16
+ ? config.experimental.ssg.sitemap.baseURL
17
+ : false,
18
+ // global settings for the sitemap.
19
+ settings: config?.experimental?.ssg?.sitemap?.settings
20
+ ? {
21
+ changefreq: config.experimental.ssg.sitemap.settings.changefreq
22
+ ? config.experimental.ssg.sitemap.settings.changefreq
23
+ : 'weekly',
24
+ priority: config.experimental.ssg.sitemap.settings.priority
25
+ ? config.experimental.ssg.sitemap.settings.priority
26
+ : '0.7',
27
+ }
28
+ : {
29
+ // default values
30
+ changefreq: 'weekly',
31
+ priority: '0.7',
32
+ },
33
+ },
34
+ // prerendered pages
35
+ // TODO: better form to import from routing system. but for now is the best method.
36
+ // NEXT: rename this! :)
37
+ prerender: config?.experimental?.ssg?.prerender
38
+ ? config.experimental.ssg.prerender
39
+ : [],
40
+ },
41
+ env: config?.experimental?.env ? config.experimental.env : {},
42
+ },
43
+ static: {
44
+ favicon: config?.static?.favicon ? config.static.favicon : false,
45
+ // if is true, public/index.html are required.
46
+ customTemplate: config?.static?.customTemplate
47
+ ? config.static.customTemplate
48
+ : false,
49
+
50
+ // global SEO.
51
+ seo: {
52
+ pageLang: config?.static?.seo?.pageLang
53
+ ? config.static.seo.pageLang
54
+ : 'en',
55
+ title: config?.static?.seo?.title
56
+ ? config.static.seo.title
57
+ : 'Ryunix App',
58
+ meta: config?.static?.seo?.meta ? config.static.seo.meta : {},
59
+ },
60
+ ssg: {}, // TODO: Move experimental.ssg here.
61
+ },
62
+
63
+ eslint: {
64
+ files: config?.eslint?.files ? config.eslint.files : ['**/*.ryx'],
65
+ plugins: config?.eslint?.plugins
66
+ ? {
67
+ react: reactPlugin,
68
+ ...config.eslint.plugins,
69
+ }
70
+ : {
71
+ react: reactPlugin,
72
+ },
73
+ rules: config?.eslint?.rules
74
+ ? {
75
+ 'max-len': config.eslint.rules['max-len']
76
+ ? config.eslint.rules['max-len']
77
+ : ['error', { code: 400 }],
78
+ camelcase: config.eslint.rules.camelcase
79
+ ? config.eslint.rules.camelcase
80
+ : 'off',
81
+ 'no-unused-vars': config.eslint.rules['no-unused-vars']
82
+ ? config.eslint.rules['no-unused-vars']
83
+ : 'warn',
84
+ 'no-console': config.eslint.rules['no-console']
85
+ ? config.eslint.rules['no-console']
86
+ : 'off',
87
+ 'no-underscore-dangle': config.eslint.rules['no-underscore-dangle']
88
+ ? config.eslint.rules['no-underscore-dangle']
89
+ : ['error', { allow: ['id_', '_id'] }],
90
+ 'arrow-body-style': config.eslint.rules['arrow-body-style']
91
+ ? config.eslint.rules['arrow-body-style']
92
+ : 'off',
93
+ indent: config.eslint.rules.indent
94
+ ? config.eslint.rules.indent
95
+ : 'warn',
96
+ 'consistent-return': config.eslint.rules['consistent-return']
97
+ ? config.eslint.rules['consistent-return']
98
+ : 'off',
99
+ 'no-else-return': config.eslint.rules['no-else-return']
100
+ ? config.eslint.rules['no-else-return']
101
+ : 'off',
102
+ 'global-require': config.eslint.rules['global-require']
103
+ ? config.eslint.rules['global-require']
104
+ : 'off',
105
+ 'no-param-reassign': config.eslint.rules['no-param-reassign']
106
+ ? config.eslint.rules['no-param-reassign']
107
+ : ['error', { props: false }],
108
+ 'new-cap': config.eslint.rules['new-cap']
109
+ ? config.eslint.rules['new-cap']
110
+ : 'off',
111
+ 'arrow-parens': config.eslint.rules['arrow-parens']
112
+ ? config.eslint.rules['arrow-parens']
113
+ : 'off',
114
+ 'prefer-destructuring': config.eslint.rules['prefer-destructuring']
115
+ ? config.eslint.rules['prefer-destructuring']
116
+ : 'warn',
117
+ 'no-nested-ternary': config.eslint.rules['no-nested-ternary']
118
+ ? config.eslint.rules['no-nested-ternary']
119
+ : 'off',
120
+ 'react/jsx-uses-vars': config.eslint.rules['react/jsx-uses-vars']
121
+ ? config.eslint.rules['react/jsx-uses-vars']
122
+ : 'warn',
123
+ // by default only this
124
+ 'react/jsx-uses-react': 'off',
125
+ 'react/react-in-jsx-scope': 'off',
126
+ ...config.eslint.rules,
127
+ }
128
+ : {
129
+ 'max-len': ['error', { code: 400 }],
130
+ camelcase: 'off',
131
+ 'no-unused-vars': 'warn',
132
+ 'no-console': 'off',
133
+ 'no-underscore-dangle': ['error', { allow: ['id_', '_id'] }],
134
+ 'arrow-body-style': 'off',
135
+ indent: 'warn',
136
+ 'consistent-return': 'off',
137
+ 'no-else-return': 'off',
138
+ 'global-require': 'off',
139
+ 'no-param-reassign': ['error', { props: false }],
140
+ 'new-cap': 'off',
141
+ 'arrow-parens': 'off',
142
+ 'prefer-destructuring': 'warn',
143
+ 'no-nested-ternary': 'off',
144
+ 'react/jsx-uses-vars': 'warn',
145
+ 'react/jsx-uses-react': 'off',
146
+ 'react/react-in-jsx-scope': 'off',
147
+ },
148
+ },
149
+
150
+ webpack: {
151
+ production: config?.webpack?.production ?? false,
152
+ root: config?.webpack?.root ? config.webpack.root : 'src',
153
+ output: {
154
+ buildDirectory: config?.webpack?.output?.buildDirectory
155
+ ? config.webpack.output.buildDirectory
156
+ : '.ryunix',
157
+ },
158
+ target: config?.webpack?.target ? config.webpack.target : 'web',
159
+ resolve: {
160
+ alias: config?.webpack?.resolve?.alias
161
+ ? config.webpack.resolve.alias
162
+ : {},
163
+ fallback: config?.webpack?.resolve?.fallback
164
+ ? config.webpack.resolve.fallback
165
+ : {},
166
+ extensions: config?.webpack?.resolve?.extensions
167
+ ? config.webpack.resolve.extensions
168
+ : [],
169
+ },
170
+ plugins: config?.webpack?.plugins ? config.webpack.plugins : [],
171
+ devServer: {
172
+ port: config?.webpack?.server?.port ? config.webpack.server.port : 3000,
173
+ proxy: config?.webpack?.server?.proxy ? config.webpack.server.proxy : [],
174
+ allowedHosts: config?.webpack?.server?.allowedHosts
175
+ ? config.webpack.server.allowedHosts
176
+ : 'auto',
177
+ },
178
+ externals: config?.webpack?.externals ? config.webpack.externals : [{}],
179
+ module: {
180
+ rules: config?.webpack?.module?.rules ? config.webpack.module.rules : [],
181
+ },
182
+ experiments: {
183
+ lazyCompilation: config?.webpack?.experiments?.lazyCompilation
184
+ ? config.webpack.experiments.lazyCompilation
185
+ : false,
186
+ },
187
+ },
188
+ }
189
+
190
+ module.exports = defaultSettings
@@ -0,0 +1,14 @@
1
+ 'use strict'
2
+ const fs = require('fs')
3
+ const path = require('path')
4
+
5
+ const envPath = path.join(process.cwd(), '.env')
6
+
7
+ const envExist = () => {
8
+ if (fs.existsSync(envPath)) {
9
+ return true
10
+ }
11
+
12
+ return false
13
+ }
14
+ module.exports = envExist
@@ -0,0 +1,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(__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
+ }
@@ -0,0 +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
+ }