@newlogic-digital/core 2.0.0-alpha.7 → 2.0.0-alpha.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/index.js +50 -10
  2. package/package.json +5 -2
  3. package/src/twig.js +1 -1
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import fs from 'fs'
2
- import os from 'os'
3
- import { dirname, resolve, join } from 'path'
1
+ import fs from 'node:fs'
2
+ import os from 'node:os'
3
+ import { dirname, resolve, join, relative } from 'node:path'
4
4
  import postHtml from 'posthtml'
5
5
  import vituum from 'vituum'
6
6
  import posthtml from '@vituum/vite-plugin-posthtml'
@@ -13,6 +13,9 @@ import { getPackageInfo, merge } from 'vituum/utils/common.js'
13
13
  import parseMinifyHtml from './src/minify.js'
14
14
  import highlight from './src/prism.js'
15
15
  import twigOptions from './src/twig.js'
16
+ import FastGlob from 'fast-glob'
17
+ import fse from 'fs-extra'
18
+ import pc from 'picocolors'
16
19
 
17
20
  const { name } = getPackageInfo(import.meta.url)
18
21
 
@@ -41,6 +44,7 @@ const posthtmlPrism = {
41
44
  * @type {import('@newlogic-digital/core/types').PluginUserConfig}
42
45
  */
43
46
  const defaultOptions = {
47
+ mode: null,
44
48
  cert: 'localhost',
45
49
  emails: {
46
50
  outputDir: resolve(process.cwd(), 'public/email'),
@@ -106,11 +110,38 @@ const plugin = (options = {}) => {
106
110
  return [{
107
111
  name,
108
112
  enforce: 'pre',
109
- config (userConfig) {
113
+ config (userConfig, userEnv) {
110
114
  const isHttps = userConfig?.server?.https !== false &&
111
115
  fs.existsSync(join(os.homedir(), `.ssh/${options.cert}.pem`)) &&
112
116
  fs.existsSync(join(os.homedir(), `.ssh/${options.cert}-key.pem`))
113
117
 
118
+ let defaultInput = [
119
+ './src/styles/*.{css,pcss,scss,sass,less,styl,stylus}',
120
+ './src/scripts/*.{js,ts,mjs}',
121
+ './src/views/**/*.{json,latte,twig,liquid,njk,hbs,pug,html}',
122
+ '!./src/views/**/*.{latte,twig,liquid,njk,hbs,pug,html}.json'
123
+ ]
124
+
125
+ if (!options.mode) {
126
+ options.mode = userEnv.mode
127
+ }
128
+
129
+ if (userEnv.mode === 'headless') {
130
+ userEnv.mode = 'production'
131
+
132
+ defaultInput = [
133
+ './src/styles/*.{css,pcss,scss,sass,less,styl,stylus}',
134
+ './src/scripts/*.{js,ts,mjs}'
135
+ ]
136
+ } else if (userEnv.mode === 'emails') {
137
+ userEnv.mode = 'production'
138
+
139
+ defaultInput = [
140
+ './src/views/email/**/*.{json,latte,twig,liquid,njk,hbs,pug,html}',
141
+ '!./src/views/email/**/*.{latte,twig,liquid,njk,hbs,pug,html}.json'
142
+ ]
143
+ }
144
+
114
145
  userConfig.build = Object.assign({
115
146
  manifest: true,
116
147
  emptyOutDir: false,
@@ -118,12 +149,7 @@ const plugin = (options = {}) => {
118
149
  assetsInlineLimit: 0,
119
150
  outDir: resolve(userConfig.root ?? process.cwd(), 'public'),
120
151
  rollupOptions: {
121
- input: [
122
- './src/styles/*.{css,pcss,scss,sass,less,styl,stylus}',
123
- './src/scripts/*.{js,ts,mjs}',
124
- './src/views/**/*.{json,latte,twig,liquid,njk,hbs,pug,html}',
125
- '!./src/views/**/*.{latte,twig,liquid,njk,hbs,pug,html}.json'
126
- ]
152
+ input: defaultInput
127
153
  }
128
154
  }, userConfig.build ?? {})
129
155
 
@@ -139,6 +165,20 @@ const plugin = (options = {}) => {
139
165
  }
140
166
  : false
141
167
  }, userConfig.server ?? {})
168
+ },
169
+ writeBundle: async () => {
170
+ if (options.mode === 'emails') {
171
+ const emails = FastGlob.sync(`${resolve(process.cwd(), options.emails.outputDir)}/**`).filter(entry => !entry.endsWith('test.html'))
172
+ const emailsProd = emails.map(path => {
173
+ return path.replace(resolve(process.cwd(), options.emails.outputDir), resolve(process.cwd(), options.emails.appDir)).replace('.html', '.latte')
174
+ })
175
+
176
+ await Promise.all(emails.map((file, i) =>
177
+ fse.move(file, emailsProd[i], { overwrite: true })
178
+ ))
179
+
180
+ console.info(`${pc.cyan('@newlogic-digital/core')} ${pc.green(`all email files were moved to ${relative(process.cwd(), options.emails.appDir)}`)}`)
181
+ }
142
182
  }
143
183
  }, ...plugins]
144
184
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@newlogic-digital/core",
3
3
  "type": "module",
4
- "version": "2.0.0-alpha.7",
4
+ "version": "2.0.0-alpha.8",
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",
@@ -22,7 +22,10 @@
22
22
  "posthtml-prism": "^2.0.0",
23
23
  "prismjs": "^1.29.0",
24
24
  "html-minifier-terser": "^7.2.0",
25
- "lodash": "^4.17.21"
25
+ "lodash": "^4.17.21",
26
+ "fast-glob": "^3.2.12",
27
+ "fs-extra": "^11.1.1",
28
+ "picocolors": "^1.0.0"
26
29
  },
27
30
  "devDependencies": {
28
31
  "@types/node": "^20.3.1",
package/src/twig.js CHANGED
@@ -67,7 +67,7 @@ export default {
67
67
  },
68
68
  filters: {
69
69
  asset: (url) => {
70
- return url.replace('/src/', '/')
70
+ return url
71
71
  },
72
72
  rem: (value) => {
73
73
  return `${value / 16}rem`