@newlogic-digital/core 1.0.0-beta.3 → 1.0.2

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/README.md +10 -7
  2. package/index.js +76 -63
  3. package/package.json +8 -5
package/README.md CHANGED
@@ -10,16 +10,18 @@
10
10
 
11
11
  # ⚙️ Newlogic Core
12
12
 
13
- Modern principles for creating web applications. Powered by Vite and Vituum
13
+ Starter for creating web applications. Powered by Vite and Vituum.
14
14
 
15
+ - ⚡️ Powered by Vite
15
16
  - 💡 Modern principles
16
17
  - 🚀️ Fast development
17
18
  - 🛠️ Integrated tools
18
19
  - 📦 Modular structure
19
20
  - ✉️ Email templates
20
- - ⚡ Vite as webserver
21
21
 
22
- Newlogic Core is an integration for [Vituum](https://vituum.dev), and contains set of tools that can be used to create modern web applications. Use of modern Javascript, CSS, ES modules, dynamic imports, etc.
22
+ Newlogic Core is an integration for [Vituum](https://vituum.dev), and contains set of tools that can be used to create modern web applications.
23
+
24
+ We use it as our main front-end tool at [Newlogic Digital](https://www.newlogic.cz/) to create wonders.
23
25
 
24
26
  ## 🛠️ Integrated tools
25
27
  * **[Vite](https://vitejs.dev)** next-generation frontend tooling
@@ -36,15 +38,15 @@ PHP programmers often **don't want to configure anything**, basic idea is to add
36
38
 
37
39
  It doesn't matter if you use Nette, Symfony or Laravel - the structure can be freely adjusted as needed - `resources` and` public`, `src` and` dist` or `app/assets` and` www`
38
40
 
39
- It's up to you - all paths are freely configurable in `vite.config.js` config
41
+ It's up to you - all paths are freely configurable via `vite.config.js` config
40
42
 
41
43
  ### 📦 Modularity
42
44
 
43
45
  Newlogic Core uses [Vituum](https://vituum.dev) and [Vite](https://vitejs.dev) for frontend tooling.
44
46
 
45
- Source files are divided by modules inside `src` directory - styles, scripts, templates, emails, assets. It is optional which modules you want to use for the project, simple delete the directory. You really only use what you want to use.
47
+ Source files are divided by modules inside `src` directory - styles, scripts, templates, data, emails, assets. It is optional which modules you want to use for the project, simple delete the directory. You really only use what you want to use.
46
48
 
47
- ## 🪄 Instalation
49
+ ## 🪄 Get started
48
50
 
49
51
  ```sh
50
52
  npm i @newlogic-digital/core --save-dev
@@ -53,10 +55,11 @@ npm i @newlogic-digital/core --save-dev
53
55
  ### Requirements
54
56
 
55
57
  - [Node.js LTS (16.x)](https://nodejs.org/en/download/)
58
+ - [Vituum](https://vituum.dev/)
56
59
 
57
60
  ### Config
58
61
 
59
- Each Newlogic Core project has to have config via `vite.config.js`
62
+ Each **Newlogic Core** project needs to have config via `vite.config.js`
60
63
 
61
64
  ```js
62
65
  import { defineConfig } from 'vituum'
package/index.js CHANGED
@@ -7,11 +7,34 @@ import lodash from 'lodash'
7
7
  import minifier from 'html-minifier-terser'
8
8
  import fs from 'fs'
9
9
  import { dirname, resolve } from 'path'
10
- import Prism from 'prismjs'
11
- import loadLanguages from 'prismjs/components/index.js'
12
- import NormalizeWhitespace from 'prismjs/plugins/normalize-whitespace/prism-normalize-whitespace.js'
10
+ import postHtml from 'posthtml'
11
+ import highlight from './prism.js'
13
12
 
14
- loadLanguages(['markup', 'css', 'javascript'])
13
+ const posthtmlPrism = {
14
+ name: '@vituum/vite-plugin-posthtml-prism',
15
+ enforce: 'post',
16
+ transformIndexHtml: {
17
+ enforce: 'post',
18
+ transform: async(html, { filename }) => {
19
+ filename = filename.replace('?raw', '')
20
+
21
+ if (!filename.endsWith('ui.json')) {
22
+ console.log(filename)
23
+ return
24
+ }
25
+
26
+ const plugins = [highlight({ inline: false })]
27
+
28
+ const result = await postHtml(plugins).process(html)
29
+
30
+ return result.html
31
+ }
32
+ }
33
+ }
34
+
35
+ const wrapPreCode = (code, lang) => {
36
+ return `<pre class="language-${lang}"><code class="language-${lang}">${code}</code></pre>`
37
+ }
15
38
 
16
39
  const stripIndent = (string) => {
17
40
  const indent = () => {
@@ -33,7 +56,27 @@ const stripIndent = (string) => {
33
56
  return string.replace(regex, '')
34
57
  }
35
58
 
59
+ const parseMinifyHtml = async (input, name) => {
60
+ const minify = await minifier.minify(input, {
61
+ collapseWhitespace: true,
62
+ collapseInlineTagWhitespace: false,
63
+ minifyCSS: true,
64
+ removeAttributeQuotes: true,
65
+ quoteCharacter: '\'',
66
+ minifyJS: true
67
+ })
68
+
69
+ if (name) {
70
+ return JSON.stringify({
71
+ [name]: minify
72
+ })
73
+ } else {
74
+ return JSON.stringify(minify)
75
+ }
76
+ }
77
+
36
78
  const defaultConfig = {
79
+ format: 'twig',
37
80
  posthtml: {},
38
81
  juice: {},
39
82
  tailwind: {},
@@ -121,26 +164,15 @@ const defaultConfig = {
121
164
  const name = Reflect.apply(Twig.expression.parse, this, [token.stack, context])
122
165
  const output = this.parse(token.output, context)
123
166
 
124
- const minify = await minifier.minify(output, {
125
- collapseWhitespace: true,
126
- collapseInlineTagWhitespace: false,
127
- minifyCSS: true,
128
- removeAttributeQuotes: true,
129
- quoteCharacter: '\'',
130
- minifyJS: true
131
- })
132
-
133
167
  if (name === '_null') {
134
168
  return {
135
169
  chain,
136
- output: JSON.stringify(minify)
170
+ output: await parseMinifyHtml(output)
137
171
  }
138
172
  } else {
139
173
  return {
140
174
  chain,
141
- output: JSON.stringify({
142
- [name]: minify
143
- })
175
+ output: await parseMinifyHtml(output, name)
144
176
  }
145
177
  }
146
178
  }
@@ -179,52 +211,9 @@ const defaultConfig = {
179
211
  type = type.replace(":mirror", "")
180
212
  }
181
213
 
182
- const Normalize = new NormalizeWhitespace({
183
- 'remove-trailing': true,
184
- 'remove-indent': true,
185
- 'left-trim': true,
186
- 'right-trim': true,
187
- });
188
-
189
- const wrap = (code, lang) => {
190
- return `<pre class="language-${lang}"><code>${code}</code></pre>`
191
- }
192
-
193
- const highlight = (str, lang) => {
194
- if (!lang) {
195
- return wrap(str, 'text')
196
- }
197
- lang = lang.toLowerCase()
198
- const rawLang = lang
199
- if (lang === 'vue' || lang === 'html') {
200
- lang = 'markup'
201
- }
202
- if (lang === 'md') {
203
- lang = 'markdown'
204
- }
205
- if (lang === 'ts') {
206
- lang = 'typescript'
207
- }
208
- if (lang === 'py') {
209
- lang = 'python'
210
- }
211
- if (!Prism.languages[lang]) {
212
- try {
213
- loadLanguages([lang])
214
- } catch (e) {
215
- console.warn(`Syntax highlight for language "${lang}" is not supported.`)
216
- }
217
- }
218
- if (Prism.languages[lang]) {
219
- const code = Prism.highlight(Normalize.normalize(str), Prism.languages[lang], lang)
220
- return wrap(code, rawLang)
221
- }
222
- return wrap(str, 'text')
223
- }
224
-
225
214
  return {
226
215
  chain: chain,
227
- output: `${mirror ? output : ""}${highlight(output, type)}`
216
+ output: `${mirror ? output : ""}${wrapPreCode(output, type)}`
228
217
  };
229
218
  }
230
219
  });
@@ -238,7 +227,22 @@ const defaultConfig = {
238
227
  ]
239
228
  },
240
229
  latte: {
241
- isStringFilter: (filename) => dirname(filename).endsWith('emails')
230
+ isStringFilter: (filename) => dirname(filename).endsWith('emails'),
231
+ globals: {
232
+ srcPath: resolve(process.cwd(), 'src'),
233
+ templatesPath: resolve(process.cwd(), 'src/templates')
234
+ },
235
+ functions: {
236
+ pages: () => {
237
+ return fs.readdirSync(resolve(process.cwd(), 'src/views')).filter(file => fs.statSync(resolve(process.cwd(), 'src/views/' + file)).isFile())
238
+ }
239
+ },
240
+ filters: {
241
+ json: async (input, name) => {
242
+ return await parseMinifyHtml(input, name)
243
+ },
244
+ code: 'node_modules/@newlogic-digital/core/latte/CodeFilter.php'
245
+ }
242
246
  }
243
247
  }
244
248
 
@@ -248,13 +252,22 @@ const integration = (userConfig = {}) => {
248
252
  return {
249
253
  config: {
250
254
  integrations: [posthtml(userConfig.posthtml), juice(userConfig.juice), tailwind(userConfig.tailwind), twig(userConfig.twig), latte(userConfig.latte)],
255
+ plugins: [posthtmlPrism],
251
256
  server: {
252
257
  open: true,
253
258
  https: true,
254
259
  reload: file => (file.endsWith('.tpl') || file.endsWith('.latte')) && !file.includes('temp/')
255
260
  },
256
261
  templates: {
257
- format: 'twig'
262
+ format: userConfig.format
263
+ },
264
+ imports: {
265
+ paths: ['./src/styles/**', './src/scripts/**', '!./src/styles/Utils/**']
266
+ },
267
+ vite: {
268
+ server: {
269
+ origin: fs.existsSync(resolve(process.cwd(), 'app/settings.php')) ? (fs.readFileSync(resolve(process.cwd(), 'app/settings.php')).toString().match(/VITE_URL = '(.+)';/) || [null, null])[1] : null
270
+ }
258
271
  }
259
272
  }
260
273
  }
package/package.json CHANGED
@@ -1,21 +1,24 @@
1
1
  {
2
2
  "name": "@newlogic-digital/core",
3
3
  "type": "module",
4
- "version": "1.0.0-beta.3",
4
+ "version": "1.0.2",
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",
8
8
  "license": "MIT",
9
+ "scripts": {
10
+ "npm-publish": "npm publish --tag next"
11
+ },
9
12
  "dependencies": {
10
13
  "@vituum/tailwind": "^0.1.2",
11
14
  "@vituum/posthtml": "^0.1.0",
12
15
  "@vituum/juice": "^0.1.3",
13
- "@vituum/twig": "^0.1.0",
14
- "@vituum/latte": "^0.1.0",
15
- "prismjs": "~1.28.0",
16
+ "@vituum/twig": "^0.1.1",
17
+ "@vituum/latte": "^0.1.1",
18
+ "prismjs": "~1.29.0",
16
19
  "html-minifier-terser": "^7.0.0",
17
20
  "lodash": "^4.17.21",
18
- "vituum": "^0.0.21"
21
+ "vituum": "^0.0.27"
19
22
  },
20
23
  "files": [
21
24
  "index.js"