@lightningjs/blits 1.5.0 → 1.6.1

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 (35) hide show
  1. package/CHANGELOG.md +18 -2
  2. package/bin/index.js +6 -138
  3. package/docs/getting_started/getting_started.md +1 -1
  4. package/docs/plugins/language.md +1 -1
  5. package/package.json +4 -9
  6. package/src/component/setup/props.js +8 -5
  7. package/src/component/setup/state.js +15 -6
  8. package/src/component.js +20 -27
  9. package/src/lib/codegenerator/generator.js +8 -2
  10. package/src/plugin.js +1 -1
  11. package/src/plugins/log.js +1 -1
  12. package/src/plugins/theme.js +1 -1
  13. package/bin/helpers.js +0 -220
  14. package/boilerplate/common/eslint/.editorconfig +0 -7
  15. package/boilerplate/common/eslint/.eslintignore +0 -3
  16. package/boilerplate/common/eslint/.eslintrc.cjs +0 -38
  17. package/boilerplate/common/eslint/husky/pre-commit +0 -2
  18. package/boilerplate/common/eslint/package.json +0 -20
  19. package/boilerplate/common/git/gitignore +0 -8
  20. package/boilerplate/common/ide/.vscode/extensions.json +0 -8
  21. package/boilerplate/common/ide/.vscode/launch.json +0 -12
  22. package/boilerplate/common/ide/.vscode/settings.json +0 -10
  23. package/boilerplate/common/public/assets/logo.png +0 -0
  24. package/boilerplate/common/public/fonts/Lato-Regular.ttf +0 -0
  25. package/boilerplate/common/public/fonts/OpenSans-Medium.ttf +0 -0
  26. package/boilerplate/common/public/fonts/Raleway-ExtraBold.ttf +0 -0
  27. package/boilerplate/js/default/.env.example +0 -4
  28. package/boilerplate/js/default/.gitattributes +0 -3
  29. package/boilerplate/js/default/index.html +0 -11
  30. package/boilerplate/js/default/package.json +0 -36
  31. package/boilerplate/js/default/src/App.js +0 -12
  32. package/boilerplate/js/default/src/components/Loader.js +0 -23
  33. package/boilerplate/js/default/src/index.js +0 -27
  34. package/boilerplate/js/default/src/pages/Home.js +0 -15
  35. package/boilerplate/js/default/vite.config.js +0 -26
package/CHANGELOG.md CHANGED
@@ -1,11 +1,27 @@
1
1
  # Changelog
2
2
 
3
+ ## v1.6.0
4
+
5
+ _9 oct 2024_
6
+
7
+ - Abstracted app create functionality to separate package
8
+ - Cleaned up dependencies
9
+ - Fixed issue with item reference in for loop
10
+ - Fixed issue with looping directly over `<Text>` components
11
+
12
+ ## v1.5.1
13
+
14
+ _7 oct 2024_
15
+
16
+ - Added export of symbols
17
+ - Various small performance improvements related to component creation
18
+
3
19
  ## v1.5.0
4
20
 
5
21
  _1 oct 2024_
6
22
 
7
- - Fixed issue with interupting running / scheduled transitions with a new transition on the same prop
8
- - Fixed issue with (incompatible) SDF text renderer being loaded when `renderMode` is set to convas
23
+ - Fixed issue with interrupting running / scheduled transitions with a new transition on the same prop
24
+ - Fixed issue with (incompatible) SDF text renderer being loaded when `renderMode` is set to canvas
9
25
  - Added support for handling key release (i.e `keyup`) events
10
26
 
11
27
  ## v1.4.3
package/bin/index.js CHANGED
@@ -1,141 +1,9 @@
1
1
  #!/usr/bin/env node
2
- import path from 'path'
3
- import process from 'process'
4
- import { dirname } from 'path'
5
- import prompts from 'prompts'
6
- import { fileURLToPath } from 'url'
7
- import fs from 'fs'
8
- import { red, bold } from 'kolorist'
9
- import sequence from '../src/helpers/sequence.js'
10
- import validatePackage from 'validate-npm-package-name'
11
- import {
12
- addESlint,
13
- copyLightningFixtures,
14
- setAppData,
15
- setBlitsVersion,
16
- gitInit,
17
- done, spinnerMsg
18
- } from './helpers.js'
2
+ import { execSync } from 'child_process'
19
3
 
20
- const defaultBanner = `
21
- --------------------------------------------------------------------
22
- Welcome to Blits - The App development framework for Lightning 3 ⚡️
23
- --------------------------------------------------------------------
24
-
25
- Answer the questions below to set up a new Lightning 3 Blits App
26
- `
27
-
28
- console.log(defaultBanner)
29
-
30
- const __filename = fileURLToPath(import.meta.url)
31
- const __dirname = dirname(__filename)
32
-
33
- const fixturesBase = path.join(
34
- __dirname,
35
- '../boilerplate')
36
-
37
- const questions = [
38
- {
39
- type: 'text',
40
- name: 'appName',
41
- message: 'What is the name of your App?',
42
- format: val => {
43
- // Check if the provided application name is empty
44
- if (!val.trim()) {
45
- spinnerMsg.fail(red(bold("Please provide a name for the App")))
46
- return process.exit(1)
47
- } else {
48
- return val
49
- }
50
- },
51
- initial: 'My Blits App', // Default value for the application name
52
- },
53
- {
54
- type: 'text',
55
- name: 'appPackage',
56
- message: 'What is the package name of your App?',
57
- format: val => {
58
- // Validate the package name using validate-npm-package-name
59
- if (!validatePackage(val).validForNewPackages) {
60
- spinnerMsg.fail(red(bold("Please provide a valid package name")))
61
- return process.exit(1)
62
- } else {
63
- return val
64
- }
65
- },
66
- initial: prev => `${prev.replace(/[\sA-Z]/g, str => str === ' ' ? '-' : str.toLowerCase())}`,
67
- },
68
- {
69
- type: 'text',
70
- name: 'appFolder',
71
- message: 'In what folder (relative to the current location) should the App be generated?',
72
- format: (val, prev) => {
73
- // Regular expression to validate whether the path is Unix/Windows-based
74
- const pathRegex = /([A-Za-z]:)?([\\/]+\w+)+/
75
- // Check if the provided path matches the defined regex
76
- if (pathRegex.test(val)) {
77
- try {
78
- // Check if the path exists
79
- if (fs.statSync(val)) {
80
- // Return the resolved file path using path.join
81
- return `${path.join(val, prev.appPackage)}`
82
- }
83
- } catch (e) {
84
- // Handle case where an error occurred during file system interaction
85
- if (e.code === 'ENOENT') {
86
- spinnerMsg.fail(red(bold("Entered directory path is invalid, please enter a valid directory!")))
87
- process.exit()
88
- }
89
- }
90
- } else if (val === prev.appPackage) {
91
- return path.join(process.cwd(), prev.appPackage)
92
- }
93
- },
94
- initial: (prev, val) => val.appPackage,
95
- },
96
- {
97
- type: 'toggle',
98
- name: 'esLint',
99
- message: 'Do you want to enable eslint?',
100
- initial: 'true',
101
- active: 'Yes',
102
- inactive: 'No',
103
- },
104
- {
105
- type: 'toggle',
106
- name: 'gitInit',
107
- message: 'Do you want to generate an git repository?',
108
- initial: 'true',
109
- active: 'Yes',
110
- inactive: 'No',
111
- },
112
- ]
113
-
114
-
115
- const createApp = () => {
116
- return new Promise(resolve => {
117
- let config
118
- sequence([
119
- async () => {
120
- const onCancel = () => {
121
- process.exit()
122
- }
123
- config = await prompts(questions, { onCancel })
124
- config.fixturesBase = fixturesBase
125
- return config
126
- },
127
- () => {
128
- spinnerMsg.start(`Generating new App "${config.appName}" ...`)
129
- copyLightningFixtures(config).then(targetDir => (config.targetDir = targetDir))
130
- spinnerMsg.succeed()
131
- },
132
- () => setAppData(config),
133
- () => setBlitsVersion(config),
134
- () => config.esLint && addESlint(config),
135
- () => config.gitInit && gitInit(config.targetDir, config.fixturesBase),
136
- () => done(config)
137
- ])
138
- })
4
+ try {
5
+ execSync('npx --yes @lightningjs/create-blits@latest', { stdio: 'inherit' })
6
+ } catch (error) {
7
+ console.error('Error while creating new Lightning 3 Blits App', error)
8
+ process.exit(1)
139
9
  }
140
-
141
- createApp()
@@ -9,7 +9,7 @@ To get started with Blits, follow these simple steps to set up your development
9
9
  2. Run the following command to start a new Blits Lightning 3 App project:
10
10
 
11
11
  ```bash
12
- npx @lightningjs/blits@latest
12
+ npm create @lightningjs/app
13
13
  ```
14
14
 
15
15
  You will be guided through a short series of questions to generate a new project with all the boilerplate code you need to start building your own Lightning 3 App.
@@ -121,7 +121,7 @@ Blits.Component('MyComponent', {
121
121
 
122
122
  ## Getting the current language
123
123
 
124
- The current language can be retrieved via the `this.$language.get()` method. It will return the currently set language code.
124
+ The current language can be retrieved via the `this.$language.language` property. It will return the currently set language code.
125
125
 
126
126
  ## Translating
127
127
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightningjs/blits",
3
- "version": "1.5.0",
3
+ "version": "1.6.1",
4
4
  "description": "Blits: The Lightning 3 App Development Framework",
5
5
  "bin": "bin/index.js",
6
6
  "exports": {
@@ -8,7 +8,8 @@
8
8
  "./vite": "./vite/index.js",
9
9
  "./transitions": "./src/router/transitions/index.js",
10
10
  "./precompiler": "./src/lib/precompiler/precompiler.js",
11
- "./plugins": "./src/plugins/index.js"
11
+ "./plugins": "./src/plugins/index.js",
12
+ "./symbols": "./src/lib/symbols.js"
12
13
  },
13
14
  "scripts": {
14
15
  "test": "c8 npm run test:run",
@@ -47,13 +48,7 @@
47
48
  },
48
49
  "dependencies": {
49
50
  "@lightningjs/msdf-generator": "^1.0.2",
50
- "@lightningjs/renderer": "^2.3.0",
51
- "execa": "^8.0.1",
52
- "kolorist": "^1.8.0",
53
- "ora": "^7.0.1",
54
- "prompts": "^2.4.2",
55
- "replace-in-file": "^6.1.0",
56
- "validate-npm-package-name": "^5.0.0"
51
+ "@lightningjs/renderer": "^2.3.2"
57
52
  },
58
53
  "repository": {
59
54
  "type": "git",
@@ -29,20 +29,23 @@ export default (component, props = []) => {
29
29
  props.push('ref')
30
30
  }
31
31
  component[symbols.propKeys] = []
32
- props.forEach((prop) => {
33
- prop = { ...baseProp, ...(typeof prop === 'object' ? prop : { key: prop }) }
32
+
33
+ const propsLength = props.length
34
+
35
+ for (let i = 0; i < propsLength; i++) {
36
+ const prop = { ...baseProp, ...(typeof props[i] === 'object' ? props[i] : { key: props[i] }) }
34
37
  component[symbols.propKeys].push(prop.key)
35
38
  Object.defineProperty(component, prop.key, {
36
39
  get() {
37
40
  const value = prop.cast(
38
- this[symbols.props] && prop.key in this[symbols.props]
41
+ this[symbols.props] !== undefined && prop.key in this[symbols.props]
39
42
  ? this[symbols.props][prop.key]
40
43
  : 'default' in prop
41
44
  ? prop.default
42
45
  : undefined
43
46
  )
44
47
 
45
- if (prop.required && value === undefined) {
48
+ if (prop.required === true && value === undefined) {
46
49
  Log.warn(`${prop.key} is required`)
47
50
  }
48
51
 
@@ -53,5 +56,5 @@ export default (component, props = []) => {
53
56
  this[symbols.props][prop.key] = v
54
57
  },
55
58
  })
56
- })
59
+ }
57
60
  }
@@ -27,13 +27,23 @@ export default (component, state = () => {}) => {
27
27
  writable: false,
28
28
  })
29
29
 
30
- const stateKeys = Object.keys(state.apply(component) || {}).concat(['hasFocus'])
30
+ const stateKeys = Object.keys(state.apply(component) || {})
31
+ // add built-in hasFocus key
32
+ stateKeys.push(['hasFocus'])
33
+ const stateKeysLength = stateKeys.length
31
34
 
32
- stateKeys.forEach((key) => {
33
- if (component[symbols.propKeys] && component[symbols.propKeys].indexOf(key) > -1) {
35
+ for (let i = 0; i < stateKeysLength; i++) {
36
+ const key = stateKeys[i]
37
+ if (
38
+ component[symbols.propKeys] !== undefined &&
39
+ component[symbols.propKeys].indexOf(key) > -1
40
+ ) {
34
41
  Log.error(`State ${key} already exists as a prop`)
35
42
  }
36
- if (component[symbols.methodKeys] && component[symbols.methodKeys].indexOf(key) > -1) {
43
+ if (
44
+ component[symbols.methodKeys] !== undefined &&
45
+ component[symbols.methodKeys].indexOf(key) > -1
46
+ ) {
37
47
  Log.error(`State ${key} already exists as a method`)
38
48
  }
39
49
  component[symbols.stateKeys].push(key)
@@ -44,7 +54,6 @@ export default (component, state = () => {}) => {
44
54
  set(v) {
45
55
  this[symbols.state][key] = v
46
56
  },
47
- // enumerable: true,
48
57
  })
49
- })
58
+ }
50
59
  }
package/src/component.js CHANGED
@@ -51,7 +51,7 @@ const required = (name) => {
51
51
  *
52
52
  */
53
53
  const Component = (name = required('name'), config = required('config')) => {
54
- let base
54
+ let base = undefined
55
55
 
56
56
  const component = function (opts, parentEl, parentComponent, rootComponent) {
57
57
  // generate a human readable ID for the component instance (i.e. Blits::ComponentName1)
@@ -89,11 +89,10 @@ const Component = (name = required('name'), config = required('config')) => {
89
89
 
90
90
  // apply the state function (passing in the this reference to utilize configured props)
91
91
  // and store a reference to this original state
92
- // hasFocus key is sprinkled in
93
- this[symbols.originalState] = {
94
- ...((config.state && typeof config.state === 'function' && config.state.apply(this)) || {}),
95
- ...{ hasFocus: false },
96
- }
92
+ this[symbols.originalState] =
93
+ (config.state && typeof config.state === 'function' && config.state.apply(this)) || {}
94
+ // add hasFocus key in
95
+ this[symbols.originalState]['hasFocus'] = false
97
96
 
98
97
  // generate a reactive state (using the result of previously execute state function)
99
98
  // and store it
@@ -162,7 +161,6 @@ const Component = (name = required('name'), config = required('config')) => {
162
161
  // reactive bindings define in the template
163
162
  const effects = config.code.effects
164
163
  for (let i = 0; i < effects.length; i++) {
165
- // console.log(config.code.effects[i].toString())
166
164
  effect(() => {
167
165
  effects[i](this, this[symbols.children], config, globalComponents, rootComponent, effect)
168
166
  })
@@ -170,12 +168,14 @@ const Component = (name = required('name'), config = required('config')) => {
170
168
 
171
169
  // setup watchers if the components has watchers specified
172
170
  if (this[symbols.watchers]) {
173
- Object.keys(this[symbols.watchers]).forEach((watchKey) => {
171
+ const watcherkeys = Object.keys(this[symbols.watchers])
172
+ const watcherkeysLength = watcherkeys.length
173
+ for (let i = 0; i < watcherkeysLength; i++) {
174
174
  let target = this
175
- let key = watchKey
175
+ let key = watcherkeys[i]
176
176
  // when dot notation used, find the nested target
177
- if (watchKey.indexOf('.') > -1) {
178
- const keys = watchKey.split('.')
177
+ if (key.indexOf('.') > -1) {
178
+ const keys = key.split('.')
179
179
  key = keys.pop()
180
180
  for (let i = 0; i < keys.length; i++) {
181
181
  target = target[keys[i]]
@@ -187,23 +187,13 @@ const Component = (name = required('name'), config = required('config')) => {
187
187
  effect((force = false) => {
188
188
  const newValue = target[key]
189
189
  if (old !== newValue || force === true) {
190
- this[symbols.watchers][watchKey].apply(this, [newValue, old])
190
+ this[symbols.watchers][key].apply(this, [newValue, old])
191
191
  old = newValue
192
192
  }
193
193
  })
194
- })
194
+ }
195
195
  }
196
196
 
197
- // set all symbol based properties to non-enumerable and non-configurable
198
- Object.getOwnPropertySymbols(this).forEach((property) => {
199
- Object.defineProperties(this, {
200
- [property]: {
201
- enumerable: false,
202
- configurable: false,
203
- },
204
- })
205
- })
206
-
207
197
  // finaly set the lifecycle state to ready (in the next tick)
208
198
  setTimeout(() => (this.lifecycle.state = 'ready'))
209
199
 
@@ -214,7 +204,10 @@ const Component = (name = required('name'), config = required('config')) => {
214
204
  const factory = (options = {}, parentEl, parentComponent, rootComponent) => {
215
205
  if (Base[symbols['launched']] === false) {
216
206
  // Register user defined plugins once on the Base object (after launch)
217
- Object.keys(plugins).forEach((pluginName) => {
207
+ const pluginKeys = Object.keys(plugins)
208
+ const pluginKeysLength = pluginKeys.length
209
+ for (let i = 0; i < pluginKeysLength; i++) {
210
+ const pluginName = pluginKeys[i]
218
211
  const prefixedPluginName = `$${pluginName}`
219
212
  if (prefixedPluginName in Base) {
220
213
  Log.warn(
@@ -231,7 +224,7 @@ const Component = (name = required('name'), config = required('config')) => {
231
224
  enumerable: true,
232
225
  configurable: false,
233
226
  })
234
- })
227
+ }
235
228
 
236
229
  // register global components once
237
230
  globalComponents = components()
@@ -241,13 +234,13 @@ const Component = (name = required('name'), config = required('config')) => {
241
234
  }
242
235
 
243
236
  // setup the component once per component type, using Base as the prototype
244
- if (!base) {
237
+ if (base === undefined) {
245
238
  Log.debug(`Setting up ${name} component`)
246
239
  base = setupComponent(Object.create(Base), config)
247
240
  }
248
241
 
249
242
  // one time code generation (only if precompilation is turned off)
250
- if (!config.code) {
243
+ if (config.code === undefined) {
251
244
  Log.debug(`Generating code for ${name} component`)
252
245
  config.code = codegenerator.call(config, parser(config.template, name))
253
246
  }
@@ -356,6 +356,9 @@ const generateForLoopCode = function (templateObject, parent) {
356
356
  templateObject[Symbol.for('componentType')] === 'Slot' ||
357
357
  templateObject[Symbol.for('componentType')] === 'Text'
358
358
  ) {
359
+ if (templateObject[Symbol.for('componentType')] === 'Text') {
360
+ templateObject.__textnode = 'true'
361
+ }
359
362
  generateElementCode.call(ctx, templateObject, parent, {
360
363
  key: 'scope.key',
361
364
  component: 'scope.',
@@ -450,8 +453,11 @@ const generateForLoopCode = function (templateObject, parent) {
450
453
  const match = matches[l]
451
454
  const ref = `component.${match[2]}`
452
455
  refs.indexOf(ref) === -1 && refs.push(ref)
453
- effect =
454
- effect.substring(0, match.index) + ref + effect.substring(match.index + match[1].length)
456
+ // don't update the effect to point to component, if we're referring to a scope item
457
+ if (match[2] !== item) {
458
+ effect =
459
+ effect.substring(0, match.index) + ref + effect.substring(match.index + match[1].length)
460
+ }
455
461
  }
456
462
 
457
463
  ctx.renderCode.push(`
package/src/plugin.js CHANGED
@@ -1,4 +1,4 @@
1
- import log from './plugins/log'
1
+ import log from './plugins/log.js'
2
2
 
3
3
  export const plugins = {
4
4
  // log plugin added by default
@@ -15,7 +15,7 @@
15
15
  * SPDX-License-Identifier: Apache-2.0
16
16
  */
17
17
 
18
- import { default as log } from '../lib/log'
18
+ import { default as log } from '../lib/log.js'
19
19
 
20
20
  export default {
21
21
  name: 'log',
@@ -15,7 +15,7 @@
15
15
  * SPDX-License-Identifier: Apache-2.0
16
16
  */
17
17
 
18
- import { Log } from '../lib/log'
18
+ import { Log } from '../lib/log.js'
19
19
  import { reactive } from '../lib/reactivity/reactive.js'
20
20
 
21
21
  import Settings from '../settings.js'
package/bin/helpers.js DELETED
@@ -1,220 +0,0 @@
1
- import { green, bold, red } from 'kolorist'
2
- import path from 'path'
3
- import { execa } from 'execa'
4
- import fs from 'fs'
5
- import replaceInFile from 'replace-in-file'
6
- import ora from 'ora'
7
- const spinner = ora()
8
-
9
- /**
10
- * This function copies Lightning fixtures to the target directory for creating a L3 application.
11
- */
12
-
13
- export const copyLightningFixtures = (config) => {
14
- return new Promise((resolve) => {
15
- const targetDir = config.appFolder || ''
16
- if (config.appFolder && fs.existsSync(targetDir)) {
17
- exit(red(bold('The target directory ' + targetDir + ' already exists')))
18
- }
19
- //this will be removed once ts support is added
20
- fs.cpSync(path.join(path.join(config.fixturesBase, 'js'), 'default'), targetDir, {
21
- recursive: true,
22
- })
23
- fs.cpSync(path.join(config.fixturesBase, 'common/public'), path.join(targetDir, 'public'), {
24
- recursive: true,
25
- })
26
-
27
- resolve(targetDir)
28
- })
29
- }
30
-
31
- /**
32
- * This function adds eslint related configuration to the project folder to be created
33
- * @param config
34
- * @returns {boolean}
35
- */
36
- export const addESlint = (config) => {
37
- // Make husky dir
38
- fs.mkdirSync(path.join(config.targetDir, '.husky'), { recursive: true })
39
-
40
- // Copy husky hook
41
- fs.copyFileSync(
42
- path.join(config.fixturesBase, 'common/eslint/husky/pre-commit'),
43
- path.join(config.targetDir, '.husky/pre-commit')
44
- )
45
-
46
- // Copy editor config from common
47
- fs.copyFileSync(
48
- path.join(config.fixturesBase, 'common/eslint/.editorconfig'),
49
- path.join(config.targetDir, '.editorconfig')
50
- )
51
-
52
- // Copy eslintignore from common
53
- fs.copyFileSync(
54
- path.join(config.fixturesBase, 'common/eslint/.eslintignore'),
55
- path.join(config.targetDir, '.eslintignore')
56
- )
57
-
58
- // Copy eslintrc.js from fixtured specfic directory
59
- fs.copyFileSync(
60
- path.join(config.fixturesBase, 'common/eslint/.eslintrc.cjs'),
61
- path.join(config.targetDir, '.eslintrc.cjs')
62
- )
63
-
64
- // Copy IDE stuff from fixture base
65
- fs.cpSync(path.join(config.fixturesBase, 'common/ide'), path.join(config.targetDir), {
66
- recursive: true,
67
- })
68
-
69
- // Copy and merge fixture specific package.json
70
- const origPackageJson = JSON.parse(fs.readFileSync(path.join(config.targetDir, 'package.json')))
71
- const eslintPackageJson = JSON.parse(
72
- fs.readFileSync(path.join(config.fixturesBase, 'common/eslint/package.json'))
73
- )
74
- fs.writeFileSync(
75
- path.join(config.targetDir, 'package.json'),
76
- JSON.stringify(
77
- {
78
- ...origPackageJson,
79
- ...eslintPackageJson,
80
- devDependencies: {
81
- ...(origPackageJson.devDependencies || {}),
82
- ...(eslintPackageJson.devDependencies || {}),
83
- },
84
- },
85
- null,
86
- 2
87
- )
88
- )
89
-
90
- return true
91
- }
92
-
93
- /**
94
- * This function sets the version by fetching the latest blits version
95
- * @param config
96
- * @returns {Promise<unknown>}
97
- */
98
- export const setBlitsVersion = (config) => {
99
- return new Promise((resolve, reject) => {
100
- execa('npm', ['view', '@lightningjs/blits', 'version'])
101
- .then(({ stdout }) => {
102
- replaceInFile.sync({
103
- files: config.targetDir + '/*',
104
- from: /\{\$blitsVersion\}/g,
105
- to: '^' + stdout,
106
- })
107
- resolve()
108
- })
109
- .catch((e) => {
110
- spinnerMsg.fail(`Error occurred while setting blits version\n\n${e}`)
111
- reject()
112
- })
113
- })
114
- }
115
-
116
- /**
117
- * Display a message and start a spinner with the specified message.
118
- *
119
- * @param {string} msg - The message to display while starting the spinner.
120
- */
121
- export const spinnerMsg = {
122
- start(msg) {
123
- console.log(' ')
124
- spinner.start(msg)
125
- },
126
- stop() {
127
- spinner.stop()
128
- },
129
- succeed(msg) {
130
- spinner.succeed(msg)
131
- },
132
- fail(msg) {
133
- spinner.fail(msg)
134
- console.log(' ')
135
- },
136
- warn(msg) {
137
- spinner.warn(msg)
138
- },
139
- }
140
-
141
- /**
142
- * This function replaces placeholders like '{$appName}' and '{$appPackage}' in files within the target directory
143
- * with the actual values from the configuration object.
144
- *
145
- * @param {Object} config - The configuration object containing application data.
146
- */
147
- export const setAppData = (config) => {
148
- replaceInFile.sync({
149
- files: config.targetDir + '/*',
150
- from: /\{\$appPackage\}/g,
151
- to: config.appPackage,
152
- })
153
-
154
- replaceInFile.sync({
155
- files: config.targetDir + '/*',
156
- from: /\{\$appName\}/g,
157
- to: config.appName,
158
- })
159
- }
160
-
161
- /**
162
- * Display an error message and exit the program with an error status.
163
- *
164
- * @param {string} msg - The error message to display before exiting the program.
165
- */
166
- export const exit = (msg) => {
167
- spinnerMsg.fail(msg)
168
- process.exit()
169
- }
170
-
171
- /**
172
- * Initialize an empty Git repository in the specified directory and copy a .gitignore file.
173
- *
174
- * @param {string} cwd - The current working directory where the Git repository will be created.
175
- * @param {string} fixturesBase - The base directory for fixtures.
176
- * @returns {Promise} A Promise that resolves when the Git initialization and file copying are completed successfully
177
- */
178
- export const gitInit = (cwd, fixturesBase) => {
179
- spinnerMsg.start('Initializing empty GIT repository')
180
- let msg
181
- return execa('git', ['init'], { cwd })
182
- .then(({ stdout }) => (msg = stdout))
183
- .then(() => {
184
- return fs.copyFileSync(
185
- path.join(fixturesBase, 'common/git/gitignore'),
186
- path.join(cwd, '.gitignore')
187
- )
188
- })
189
- .then(() => spinnerMsg.succeed(msg))
190
- .catch((e) => spinnerMsg.fail(`Error occurred while creating git repository\n\n${e}`))
191
- }
192
-
193
- /**
194
- * Checks whether the give path is valid
195
- * @param path
196
- * @returns {boolean}
197
- */
198
- export const isValidPath = (path) => {
199
- try {
200
- // Check if the path exists
201
- fs.accessSync(path, fs.constants.F_OK)
202
- return true
203
- } catch (err) {
204
- // The path does not exist or is not accessible
205
- return false
206
- }
207
- }
208
-
209
- export const done = (config) => {
210
- console.log('')
211
- console.log('--------------------------------------------------------------------')
212
- console.log(' Your new boilerplate Lightning 3 App has been created! ⚡️')
213
- console.log('--------------------------------------------------------------------')
214
- console.log('')
215
- console.log('Follow the steps below to get started:')
216
- console.log('')
217
- console.log(` ${green(bold(`cd ${config.appFolder}`))}`)
218
- console.log(` ${green(bold('npm install'))}`)
219
- console.log(` ${green(bold('npm run dev'))}`)
220
- }
@@ -1,7 +0,0 @@
1
- [*]
2
- charset = utf-8
3
- indent_size = 2
4
- indent_style = space
5
- end_of_line = lf
6
- insert_final_newline = true
7
- trim_trailing_whitespace = true
@@ -1,3 +0,0 @@
1
- **/node_modules
2
- build
3
- dist
@@ -1,38 +0,0 @@
1
- module.exports = {
2
- root: true,
3
- env: {
4
- browser: true,
5
- es6: true,
6
- node: true,
7
- },
8
- plugins: ['prettier'],
9
- extends: ['eslint:recommended', 'plugin:prettier/recommended', 'prettier'],
10
- rules: {
11
- 'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
12
- 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
13
- quotes: [2, 'single', 'avoid-escape'],
14
- semi: [2, 'never'],
15
- 'no-extra-boolean-cast': 'off',
16
- 'no-unused-vars': [
17
- 1,
18
- {
19
- argsIgnorePattern: 'res|next|^err',
20
- },
21
- ],
22
- 'prettier/prettier': [
23
- 'error',
24
- {
25
- trailingComma: 'es5',
26
- singleQuote: true,
27
- tabWidth: 2,
28
- semi: false,
29
- printWidth: 100,
30
- },
31
- ],
32
- },
33
- parserOptions: {
34
- parser: 'babel-eslint',
35
- ecmaVersion: 2020,
36
- sourceType: 'module',
37
- },
38
- }
@@ -1,2 +0,0 @@
1
- #!/bin/bash
2
- npx lint-staged
@@ -1,20 +0,0 @@
1
- {
2
- "lint-staged": {
3
- "*.js": [
4
- "eslint --fix"
5
- ]
6
- },
7
- "husky": {
8
- "hooks": {
9
- "pre-commit": "lint-staged"
10
- }
11
- },
12
- "devDependencies": {
13
- "eslint": "^8.8.0",
14
- "eslint-config-prettier": "^8.3.0",
15
- "eslint-plugin-prettier": "^4.0.0",
16
- "husky": "^7.0.4",
17
- "lint-staged": "^12.3.3",
18
- "prettier": "^2.5.1"
19
- }
20
- }
@@ -1,8 +0,0 @@
1
- .DS_Store
2
- .env
3
- .env.*
4
- !.env.example
5
-
6
- node_modules
7
- build
8
- dist
@@ -1,8 +0,0 @@
1
- {
2
- "recommendations": [
3
- "editorconfig.editorconfig",
4
- "dbaeumer.vscode-eslint",
5
- "naumovs.color-highlight",
6
- "LightningJS.lightning-blits"
7
- ]
8
- }
@@ -1,12 +0,0 @@
1
- {
2
- "version": "0.2.0",
3
- "configurations": [
4
- {
5
- "name": "Launch Chrome",
6
- "request": "launch",
7
- "type": "chrome",
8
- "url": "http://localhost:8000",
9
- "webRoot": "${workspaceFolder}"
10
- }
11
- ]
12
- }
@@ -1,10 +0,0 @@
1
- {
2
- "editor.formatOnSave": false,
3
- "eslint.validate": [
4
- "javascript"
5
- ],
6
- "editor.codeActionsOnSave": {
7
- "source.fixAll.eslint": true
8
- },
9
- "js/ts.implicitProjectConfig.checkJs": true
10
- }
@@ -1,4 +0,0 @@
1
- # all environment variables need to prefixed with VITE_*
2
- # to read, use import.meta.env.VITE_FOO
3
-
4
- # VITE_FOO=bar
@@ -1,3 +0,0 @@
1
- *.js text eol=lf
2
- *.cjs text eol=lf
3
- *.jsx text eol=lf
@@ -1,11 +0,0 @@
1
- <html>
2
- <head>
3
- <style>
4
- html, body, * { padding: 0; margin: 0}
5
- </style>
6
- </head>
7
- <body>
8
- <div id="app"></div>
9
- <script type="module" src="src/index.js"></script>
10
- </body>
11
- </html>
@@ -1,36 +0,0 @@
1
- {
2
- "name": "{$appPackage}",
3
- "version": "0.1.0",
4
- "description": "{$appName}",
5
- "main": "index.js",
6
- "type": "module",
7
- "scripts": {
8
- "start": "npm run dev",
9
- "lint": "eslint '**/*.js'",
10
- "lint:fix": "eslint '**/*.js' --fix",
11
- "build": "vite build",
12
- "dev": "vite dev --host"
13
- },
14
- "lint-staged": {
15
- "*.js": [
16
- "eslint --fix"
17
- ]
18
- },
19
- "husky": {
20
- "hooks": {
21
- "pre-commit": "lint-staged"
22
- }
23
- },
24
- "devDependencies": {
25
- "eslint": "^8.8.0",
26
- "eslint-config-prettier": "^8.3.0",
27
- "eslint-plugin-prettier": "^4.0.0",
28
- "husky": "^7.0.4",
29
- "lint-staged": "^12.3.3",
30
- "prettier": "^2.5.1",
31
- "vite": "^4.0.4"
32
- },
33
- "dependencies": {
34
- "@lightningjs/blits": "{$blitsVersion}"
35
- }
36
- }
@@ -1,12 +0,0 @@
1
- import Blits from '@lightningjs/blits'
2
-
3
- import Home from './pages/Home.js'
4
-
5
- export default Blits.Application({
6
- template: `
7
- <Element>
8
- <RouterView />
9
- </Element>
10
- `,
11
- routes: [{ path: '/', component: Home }],
12
- })
@@ -1,23 +0,0 @@
1
- import Blits from '@lightningjs/blits'
2
-
3
- export default Blits.Component('Loading', {
4
- template: `
5
- <Element>
6
- <Circle size="40" color="#94a3b8" :alpha.transition="{value: $alpha, delay: 200}" />
7
- <Circle size="40" color="#94a3b8" x="60" :alpha.transition="{value: $alpha, delay: 300}" />
8
- <Circle size="40" color="#94a3b8" x="120" :alpha.transition="{value: $alpha, delay: 400}" />
9
- </Element>
10
- `,
11
- state() {
12
- return {
13
- alpha: 0,
14
- }
15
- },
16
- hooks: {
17
- ready() {
18
- this.$setInterval(() => {
19
- this.alpha = this.alpha === 1 ? 0 : 1
20
- }, 800)
21
- },
22
- },
23
- })
@@ -1,27 +0,0 @@
1
- import Blits from '@lightningjs/blits'
2
- import App from './App.js'
3
-
4
- Blits.Launch(App, 'app', {
5
- w: 1920,
6
- h: 1080,
7
- multithreaded: false,
8
- debugLevel: 1,
9
- defaultFont: 'lato',
10
- fonts: [
11
- {
12
- family: 'lato',
13
- type: 'msdf',
14
- file: 'fonts/Lato-Regular.ttf',
15
- },
16
- {
17
- family: 'raleway',
18
- type: 'msdf',
19
- file: 'fonts/Raleway-ExtraBold.ttf',
20
- },
21
- {
22
- family: 'opensans',
23
- type: 'web',
24
- file: 'fonts/OpenSans-Medium.ttf',
25
- },
26
- ],
27
- })
@@ -1,15 +0,0 @@
1
- import Blits from '@lightningjs/blits'
2
-
3
- import Loader from '../components/Loader.js'
4
-
5
- export default Blits.Component('Home', {
6
- components: {
7
- Loader,
8
- },
9
- template: `
10
- <Element w="1920" h="1080" color="#1e293b">
11
- <Element src="assets/logo.png" w="200" h="200" x="860" y="320" :effects="[$shader('radius', {radius: 12})]" />
12
- <Loader x="880" y="600" />
13
- </Element>
14
- `,
15
- })
@@ -1,26 +0,0 @@
1
- /// <reference types="vite/client" />
2
-
3
- import { defineConfig } from 'vite'
4
- import blitsVitePlugins from '@lightningjs/blits/vite'
5
-
6
- export default defineConfig(({ command, mode, ssrBuild }) => {
7
- return {
8
- base: '/', // Set to your base path if you are deploying to a subdirectory (example: /myApp/)
9
- plugins: [...blitsVitePlugins],
10
- resolve: {
11
- mainFields: ['browser', 'module', 'jsnext:main', 'jsnext'],
12
- },
13
- server: {
14
- headers: {
15
- 'Cross-Origin-Opener-Policy': 'same-origin',
16
- 'Cross-Origin-Embedder-Policy': 'require-corp',
17
- },
18
- fs: {
19
- allow: ['..'],
20
- },
21
- },
22
- worker: {
23
- format: 'es',
24
- },
25
- }
26
- })