@newlogic-digital/core 1.0.0-beta.2 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. package/README.md +10 -7
  2. package/index.js +104 -59
  3. package/package.json +9 -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
@@ -33,7 +33,74 @@ const stripIndent = (string) => {
33
33
  return string.replace(regex, '')
34
34
  }
35
35
 
36
+ const parsePrism = (type, input) => {
37
+ const Normalize = new NormalizeWhitespace({
38
+ 'remove-trailing': true,
39
+ 'remove-indent': true,
40
+ 'left-trim': true,
41
+ 'right-trim': true,
42
+ });
43
+
44
+ const wrap = (code, lang) => {
45
+ return `<pre class="language-${lang}"><code>${code}</code></pre>`
46
+ }
47
+
48
+ const highlight = (str, lang) => {
49
+ if (!lang) {
50
+ return wrap(str, 'text')
51
+ }
52
+ lang = lang.toLowerCase()
53
+ const rawLang = lang
54
+ if (lang === 'vue' || lang === 'html') {
55
+ lang = 'markup'
56
+ }
57
+ if (lang === 'md') {
58
+ lang = 'markdown'
59
+ }
60
+ if (lang === 'ts') {
61
+ lang = 'typescript'
62
+ }
63
+ if (lang === 'py') {
64
+ lang = 'python'
65
+ }
66
+ if (!Prism.languages[lang]) {
67
+ try {
68
+ loadLanguages([lang])
69
+ } catch (e) {
70
+ console.warn(`Syntax highlight for language "${lang}" is not supported.`)
71
+ }
72
+ }
73
+ if (Prism.languages[lang]) {
74
+ const code = Prism.highlight(Normalize.normalize(str), Prism.languages[lang], lang)
75
+ return wrap(code, rawLang)
76
+ }
77
+ return wrap(str, 'text')
78
+ }
79
+
80
+ return highlight(input, type);
81
+ }
82
+
83
+ const parseMinifyHtml = async (input, name) => {
84
+ const minify = await minifier.minify(input, {
85
+ collapseWhitespace: true,
86
+ collapseInlineTagWhitespace: false,
87
+ minifyCSS: true,
88
+ removeAttributeQuotes: true,
89
+ quoteCharacter: '\'',
90
+ minifyJS: true
91
+ })
92
+
93
+ if (name) {
94
+ return JSON.stringify({
95
+ [name]: minify
96
+ })
97
+ } else {
98
+ return JSON.stringify(minify)
99
+ }
100
+ }
101
+
36
102
  const defaultConfig = {
103
+ format: 'twig',
37
104
  posthtml: {},
38
105
  juice: {},
39
106
  tailwind: {},
@@ -121,26 +188,15 @@ const defaultConfig = {
121
188
  const name = Reflect.apply(Twig.expression.parse, this, [token.stack, context])
122
189
  const output = this.parse(token.output, context)
123
190
 
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
191
  if (name === '_null') {
134
192
  return {
135
193
  chain,
136
- output: JSON.stringify(minify)
194
+ output: await parseMinifyHtml(output)
137
195
  }
138
196
  } else {
139
197
  return {
140
198
  chain,
141
- output: JSON.stringify({
142
- [name]: minify
143
- })
199
+ output: await parseMinifyHtml(output, name)
144
200
  }
145
201
  }
146
202
  }
@@ -179,52 +235,9 @@ const defaultConfig = {
179
235
  type = type.replace(":mirror", "")
180
236
  }
181
237
 
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
238
  return {
226
239
  chain: chain,
227
- output: `${mirror ? output : ""}${highlight(output, type)}`
240
+ output: `${mirror ? output : ""}${parsePrism(type, output)}`
228
241
  };
229
242
  }
230
243
  });
@@ -238,7 +251,31 @@ const defaultConfig = {
238
251
  ]
239
252
  },
240
253
  latte: {
241
- isStringFilter: (filename) => dirname(filename).endsWith('emails')
254
+ isStringFilter: (filename) => dirname(filename).endsWith('emails'),
255
+ globals: {
256
+ srcPath: resolve(process.cwd(), 'src'),
257
+ templatesPath: resolve(process.cwd(), 'src/templates')
258
+ },
259
+ functions: {
260
+ pages: () => {
261
+ return fs.readdirSync(resolve(process.cwd(), 'src/views')).filter(file => fs.statSync(resolve(process.cwd(), 'src/views/' + file)).isFile())
262
+ },
263
+ // code: (input, type = '') => {
264
+ // let mirror = false;
265
+ //
266
+ // if (type.includes(":mirror")) {
267
+ // mirror = true;
268
+ // type = type.replace(":mirror", "")
269
+ // }
270
+ //
271
+ // return `${mirror ? input : ""}${parsePrism(type, input)}`
272
+ // }
273
+ },
274
+ filters: {
275
+ json: async (input, name) => {
276
+ return await parseMinifyHtml(input, name)
277
+ }
278
+ }
242
279
  }
243
280
  }
244
281
 
@@ -254,7 +291,15 @@ const integration = (userConfig = {}) => {
254
291
  reload: file => (file.endsWith('.tpl') || file.endsWith('.latte')) && !file.includes('temp/')
255
292
  },
256
293
  templates: {
257
- format: 'twig'
294
+ format: userConfig.format
295
+ },
296
+ imports: {
297
+ paths: ['./src/styles/**', './src/scripts/**', '!./src/styles/Utils/**']
298
+ },
299
+ vite: {
300
+ server: {
301
+ 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
302
+ }
258
303
  }
259
304
  }
260
305
  }
package/package.json CHANGED
@@ -1,20 +1,24 @@
1
1
  {
2
2
  "name": "@newlogic-digital/core",
3
3
  "type": "module",
4
- "version": "1.0.0-beta.2",
4
+ "version": "1.0.1",
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
- "lodash": "^4.17.21"
20
+ "lodash": "^4.17.21",
21
+ "vituum": "^0.0.27"
18
22
  },
19
23
  "files": [
20
24
  "index.js"