@newlogic-digital/core 3.0.0-next.3 → 3.0.0-next.5

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.
Files changed (3) hide show
  1. package/index.js +67 -92
  2. package/package.json +17 -13
  3. package/types/index.d.ts +2 -1
package/index.js CHANGED
@@ -1,56 +1,18 @@
1
1
  import fs from 'node:fs'
2
2
  import os from 'node:os'
3
- import { dirname, resolve, join, relative } from 'node:path'
4
- import postHtml from 'posthtml'
3
+ import { resolve, join } from 'node:path'
5
4
  import vituum from 'vituum'
6
- import posthtml from '@vituum/vite-plugin-posthtml'
7
5
  import latte from '@vituum/vite-plugin-latte'
8
- import twig from '@vituum/vite-plugin-twig'
9
6
  import juice from '@vituum/vite-plugin-juice'
10
7
  import send from '@vituum/vite-plugin-send'
11
- import tailwindcss from '@vituum/vite-plugin-tailwindcss'
12
8
  import { getPackageInfo, merge } from 'vituum/utils/common.js'
13
- import highlight from './src/prism.js'
14
9
  import twigOptions from './src/twig.js'
15
- import FastGlob from 'fast-glob'
16
- import fse from 'fs-extra'
17
- import pc from 'picocolors'
18
10
  import browserslistToEsbuild from 'browserslist-to-esbuild'
11
+ import browserslist from 'browserslist'
12
+ import { Features as LightningCssFeatures, browserslistToTargets } from 'lightningcss'
19
13
 
20
14
  const { name } = getPackageInfo(import.meta.url)
21
15
 
22
- const posthtmlPrism = {
23
- name: '@newlogic-digital/vite-plugin-posthtml-prism',
24
- enforce: 'post',
25
- transformIndexHtml: {
26
- order: 'post',
27
- handler: async (html, { filename }) => {
28
- filename = filename.replace('?raw', '')
29
-
30
- if (!filename.replace('.html', '').endsWith('ui.json')) {
31
- return
32
- }
33
-
34
- const plugins = [highlight({ inline: false })]
35
-
36
- const result = await postHtml(plugins).process(html)
37
-
38
- return result.html
39
- }
40
- }
41
- }
42
-
43
- const postcssImportSupports = {
44
- name: 'postcss-import-supports',
45
- transform(code, path) {
46
- if (path.endsWith('.css')) {
47
- return {
48
- code: code.replace('@media supports', '@supports')
49
- }
50
- }
51
- }
52
- }
53
-
54
16
  /**
55
17
  * @type {import('@newlogic-digital/core/types').PluginUserConfig}
56
18
  */
@@ -59,30 +21,26 @@ const defaultOptions = {
59
21
  cert: 'localhost',
60
22
  format: ['latte'],
61
23
  manualChunks: {},
62
- emails: {
63
- outputDir: resolve(process.cwd(), 'public/email'),
64
- appDir: resolve(process.cwd(), 'app/Templates/Emails')
65
- },
66
24
  vituum: {
67
25
  pages: {
68
26
  dir: './src/pages'
69
27
  }
70
28
  },
71
- posthtml: {
72
- root: resolve(process.cwd(), 'src')
73
- },
74
29
  juice: {
75
30
  paths: ['src/pages/email'],
76
31
  postcss: {
77
32
  globalData: {
78
- files: ['./src/emails/styles/main/base/config.css']
33
+ files: ['./src/styles/emails/theme/config.css']
79
34
  }
80
35
  }
81
36
  },
37
+ css: {
38
+ transformer: 'postcss',
39
+ lightningcss: {}
40
+ },
82
41
  tailwindcss: {},
83
42
  send: {},
84
43
  latte: {
85
- renderTransformedHtml: filename => dirname(filename).endsWith('email'),
86
44
  globals: {
87
45
  srcPath: resolve(process.cwd(), 'src'),
88
46
  templatesPath: resolve(process.cwd(), 'src/templates'),
@@ -96,8 +54,7 @@ const defaultOptions = {
96
54
  filters: {
97
55
  json: resolve(process.cwd(), 'node_modules/@newlogic-digital/core/latte/JsonFilter.js'),
98
56
  code: 'node_modules/@newlogic-digital/core/latte/CodeFilter.php'
99
- },
100
- ignoredPaths: ['**/views/email/**/!(*.test).latte', '**/emails/!(*.test).latte']
57
+ }
101
58
  },
102
59
  twig: twigOptions
103
60
  }
@@ -106,12 +63,15 @@ const defaultOptions = {
106
63
  * @param {import('@newlogic-digital/core/types').PluginUserConfig} options
107
64
  * @returns [import('vite').Plugin]
108
65
  */
109
- const plugin = (options = {}) => {
66
+ const plugin = async (options = {}) => {
110
67
  options = merge(defaultOptions, options)
111
68
 
112
69
  const templatesPlugins = []
70
+ const tailwindcssPlugin = []
113
71
 
114
72
  if (options.format.includes('twig')) {
73
+ const twig = (await import('@vituum/vite-plugin-twig')).default
74
+
115
75
  templatesPlugins.push(twig(options.twig))
116
76
  }
117
77
 
@@ -119,15 +79,24 @@ const plugin = (options = {}) => {
119
79
  templatesPlugins.push(latte(options.latte))
120
80
  }
121
81
 
82
+ if (options.css.transformer === 'postcss') {
83
+ const tailwindcss = (await import('@vituum/vite-plugin-tailwindcss')).default
84
+
85
+ tailwindcssPlugin.push(tailwindcss(options.tailwindcss))
86
+ }
87
+
88
+ if (options.css.transformer === 'lightningcss') {
89
+ const tailwindcss = (await import('@tailwindcss/vite')).default
90
+
91
+ tailwindcssPlugin.push(tailwindcss(options.tailwindcss))
92
+ }
93
+
122
94
  const plugins = [
123
95
  vituum(options.vituum),
124
- tailwindcss(options.tailwindcss),
125
- posthtml(options.posthtml),
96
+ ...tailwindcssPlugin,
126
97
  ...templatesPlugins,
127
98
  juice(options.juice),
128
- send(options.send),
129
- posthtmlPrism,
130
- postcssImportSupports
99
+ send(options.send)
131
100
  ]
132
101
 
133
102
  return [{
@@ -160,15 +129,6 @@ const plugin = (options = {}) => {
160
129
  userConfig.publicDir = userConfig.publicDir ?? false
161
130
  }
162
131
 
163
- if (options.mode === 'emails') {
164
- userEnv.mode = 'production'
165
-
166
- defaultInput = [
167
- './src/pages/email/**/*.{json,latte,twig,liquid,njk,hbs,pug,html}',
168
- '!./src/pages/email/**/*.{latte,twig,liquid,njk,hbs,pug,html}.json'
169
- ]
170
- }
171
-
172
132
  const outDir = resolve(userConfig.root ?? process.cwd(), 'public')
173
133
 
174
134
  if (userConfig.build && !userConfig.build.outDir) {
@@ -179,29 +139,58 @@ const plugin = (options = {}) => {
179
139
  entries: []
180
140
  }, userConfig.optimizeDeps ?? {})
181
141
 
142
+ userConfig.css = Object.assign({
143
+ transformer: options.css.transformer
144
+ }, userConfig.css ?? {})
145
+
146
+ userConfig.css.lightningcss = Object.assign({
147
+ targets: browserslistToTargets(browserslist()),
148
+ exclude: LightningCssFeatures.Nesting,
149
+ drafts: {
150
+ customMedia: true
151
+ }
152
+ }, userConfig.css.lightningcss ?? {})
153
+
182
154
  userConfig.build = Object.assign({
183
155
  target: browserslistToEsbuild(),
184
- manifest: 'manifest.json',
156
+ manifest: (options.mode === 'emails') ? false : 'manifest.json',
185
157
  emptyOutDir: false,
186
158
  modulePreload: false,
187
159
  assetsInlineLimit: 0,
188
160
  outDir
189
161
  }, userConfig.build ?? {})
190
162
 
191
- userConfig.build.rollupOptions = Object.assign({
192
- input: defaultInput,
193
- output: {
194
- manualChunks: {
195
- swup: ['swup'],
196
- stimulus: ['@hotwired/stimulus'],
197
- naja: ['naja'],
198
- ...options.manualChunks
163
+ if (options.mode === 'emails') {
164
+ userEnv.mode = 'production'
165
+
166
+ defaultInput = [
167
+ './src/pages/email/**/*.{json,latte,twig,liquid,njk,hbs,pug,html}',
168
+ './src/styles/emails/*.{css,pcss,scss,sass,less,styl,stylus}',
169
+ '!./src/pages/email/**/*.{latte,twig,liquid,njk,hbs,pug,html}.json'
170
+ ]
171
+
172
+ userConfig.build.rollupOptions = Object.assign({
173
+ input: defaultInput,
174
+ output: {
175
+ assetFileNames: 'assets/email/[name].[ext]'
199
176
  }
200
- }
201
- }, userConfig.build.rollupOptions ?? {})
177
+ }, userConfig.build.rollupOptions ?? {})
178
+ } else {
179
+ userConfig.build.rollupOptions = Object.assign({
180
+ input: defaultInput,
181
+ output: {
182
+ manualChunks: options.manualChunks ?? {
183
+ swup: ['swup'],
184
+ stimulus: ['@hotwired/stimulus'],
185
+ naja: ['naja']
186
+ }
187
+ }
188
+ }, userConfig.build.rollupOptions ?? {})
189
+ }
202
190
 
203
191
  userConfig.server = Object.assign({
204
192
  host: true,
193
+ cors: true,
205
194
  fsServe: {
206
195
  strict: false
207
196
  },
@@ -212,20 +201,6 @@ const plugin = (options = {}) => {
212
201
  }
213
202
  : false
214
203
  }, userConfig.server ?? {})
215
- },
216
- writeBundle: async () => {
217
- if (options.mode === 'emails') {
218
- const emails = FastGlob.sync(`${resolve(process.cwd(), options.emails.outputDir)}/**`).filter(entry => !entry.endsWith('test.html'))
219
- const emailsProd = emails.map((path) => {
220
- return path.replace(resolve(process.cwd(), options.emails.outputDir), resolve(process.cwd(), options.emails.appDir)).replace('.html', '.latte')
221
- })
222
-
223
- await Promise.all(emails.map((file, i) =>
224
- fse.move(file, emailsProd[i], { overwrite: true })
225
- ))
226
-
227
- console.info(`${pc.cyan('@newlogic-digital/core')} ${pc.green(`all email files were moved to ${relative(process.cwd(), options.emails.appDir)}`)}`)
228
- }
229
204
  }
230
205
  }, ...plugins]
231
206
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@newlogic-digital/core",
3
3
  "type": "module",
4
- "version": "3.0.0-next.3",
4
+ "version": "3.0.0-next.5",
5
5
  "main": "index.js",
6
6
  "author": "New Logic Studio s.r.o.",
7
7
  "description": "Set of tools that can be used to create modern web applications",
@@ -12,30 +12,34 @@
12
12
  "publish-next": "npm publish --tag next"
13
13
  },
14
14
  "dependencies": {
15
- "@vituum/vite-plugin-juice": "^1.2.0",
15
+ "@tailwindcss/vite": "^4.0.0",
16
+ "@vituum/vite-plugin-juice": "^1.3.0",
16
17
  "@vituum/vite-plugin-latte": "^1.2.1",
17
18
  "@vituum/vite-plugin-posthtml": "^1.1.0",
18
19
  "@vituum/vite-plugin-send": "^1.1.0",
19
- "@vituum/vite-plugin-tailwindcss": "^1.1.0",
20
- "@vituum/vite-plugin-twig": "^1.1.0",
20
+ "browserslist": "^4.24.0",
21
+ "browserslist-to-esbuild": "^2.1.1",
21
22
  "fast-glob": "^3.3.2",
22
23
  "fs-extra": "^11.2.0",
23
24
  "html-minifier-terser": "^7.2.0",
25
+ "lightningcss": "^1.29.1",
24
26
  "lodash": "^4.17.21",
25
- "picocolors": "^1.0.1",
27
+ "picocolors": "^1.1.0",
26
28
  "posthtml": "^0.16.6",
27
29
  "posthtml-prism": "^2.0.1",
28
30
  "prismjs": "^1.29.0",
29
- "vituum": "^1.1.1",
30
- "browserslist": "^4.23.3",
31
- "browserslist-to-esbuild": "^2.1.1"
31
+ "vituum": "^1.1.1"
32
+ },
33
+ "optionalDependencies": {
34
+ "@vituum/vite-plugin-tailwindcss": "^1.2.0",
35
+ "@vituum/vite-plugin-twig": "^1.1.0"
32
36
  },
33
37
  "devDependencies": {
34
- "@types/node": "^22.2.0",
35
- "eslint": "^9.9.0",
36
- "neostandard": "^0.11.2",
37
- "typescript": "^5.5.4",
38
- "vite": "^5.4.0"
38
+ "@types/node": "^22.7.5",
39
+ "eslint": "^9.12.0",
40
+ "neostandard": "^0.11.6",
41
+ "typescript": "^5.6.2",
42
+ "vite": "^5.4.8"
39
43
  },
40
44
  "files": [
41
45
  "latte",
package/types/index.d.ts CHANGED
@@ -4,12 +4,13 @@ interface Emails {
4
4
  }
5
5
 
6
6
  export interface PluginUserConfig {
7
- mode?: 'development' | 'production' | 'emails'
7
+ mode?: 'development' | 'production' | 'emails' | string
8
8
  format?: string[]
9
9
  cert?: string
10
10
  manualChunks?: import('rollup').ManualChunksOption
11
11
  emails?: Emails
12
12
  vituum?: import('vituum').UserConfig,
13
+ css?: import('vite').CSSOptions
13
14
  posthtml?: import('@vituum/vite-plugin-posthtml/types').PluginUserConfig
14
15
  juice?: import('@vituum/vite-plugin-juice/types').PluginUserConfig
15
16
  send?: import('@vituum/vite-plugin-send/types').PluginUserConfig