ether-code 0.1.9 → 0.2.3

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.
package/cli/watcher.js ADDED
@@ -0,0 +1,106 @@
1
+ const fs = require('fs')
2
+ const path = require('path')
3
+ const EventEmitter = require('events')
4
+
5
+ class Watcher extends EventEmitter {
6
+ constructor(dir, options = {}) {
7
+ super()
8
+ this.dir = dir
9
+ this.options = {
10
+ ignored: ['node_modules', '.git', 'dist'],
11
+ debounce: 100,
12
+ ...options
13
+ }
14
+ this.watchers = new Map()
15
+ this.debounceTimers = new Map()
16
+ }
17
+
18
+ start() {
19
+ this.watchDir(this.dir)
20
+ }
21
+
22
+ stop() {
23
+ for (const watcher of this.watchers.values()) {
24
+ watcher.close()
25
+ }
26
+ this.watchers.clear()
27
+
28
+ for (const timer of this.debounceTimers.values()) {
29
+ clearTimeout(timer)
30
+ }
31
+ this.debounceTimers.clear()
32
+ }
33
+
34
+ watchDir(dir) {
35
+ if (this.isIgnored(dir)) return
36
+
37
+ try {
38
+ const watcher = fs.watch(dir, { persistent: true }, (eventType, filename) => {
39
+ if (!filename) return
40
+
41
+ const fullPath = path.join(dir, filename)
42
+ this.handleEvent(eventType, fullPath)
43
+ })
44
+
45
+ watcher.on('error', (err) => {
46
+ this.emit('error', err)
47
+ })
48
+
49
+ this.watchers.set(dir, watcher)
50
+
51
+ const entries = fs.readdirSync(dir, { withFileTypes: true })
52
+ for (const entry of entries) {
53
+ if (entry.isDirectory() && !this.isIgnored(entry.name)) {
54
+ this.watchDir(path.join(dir, entry.name))
55
+ }
56
+ }
57
+ } catch (err) {
58
+ this.emit('error', err)
59
+ }
60
+ }
61
+
62
+ handleEvent(eventType, filePath) {
63
+ const existing = this.debounceTimers.get(filePath)
64
+ if (existing) {
65
+ clearTimeout(existing)
66
+ }
67
+
68
+ const timer = setTimeout(() => {
69
+ this.debounceTimers.delete(filePath)
70
+ this.processEvent(filePath)
71
+ }, this.options.debounce)
72
+
73
+ this.debounceTimers.set(filePath, timer)
74
+ }
75
+
76
+ processEvent(filePath) {
77
+ try {
78
+ const exists = fs.existsSync(filePath)
79
+
80
+ if (!exists) {
81
+ this.emit('unlink', filePath)
82
+ return
83
+ }
84
+
85
+ const stat = fs.statSync(filePath)
86
+
87
+ if (stat.isDirectory()) {
88
+ if (!this.watchers.has(filePath)) {
89
+ this.watchDir(filePath)
90
+ this.emit('addDir', filePath)
91
+ }
92
+ } else {
93
+ this.emit('change', filePath)
94
+ }
95
+ } catch (err) {
96
+ this.emit('error', err)
97
+ }
98
+ }
99
+
100
+ isIgnored(name) {
101
+ const baseName = path.basename(name)
102
+ return this.options.ignored.includes(baseName) || baseName.startsWith('.')
103
+ }
104
+ }
105
+
106
+ module.exports = { Watcher }
package/ether-compiler.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const fs = require('fs')
2
2
  const path = require('path')
3
- const { EtherLexer, TokenType } = require('./ether-lexer')
3
+ const { EtherLexer, TokenType } = require('./lexer/ether-lexer')
4
4
  const { EtherParser } = require('./ether-parser')
5
5
  const { CSSGenerator } = require('./generators/css-generator')
6
6
  const { HTMLGenerator } = require('./generators/html-generator')
package/ether-parser.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const fs = require('fs')
2
- const { EtherLexer, Token, TokenType } = require('./ether-lexer')
2
+ const { EtherLexer, Token, TokenType } = require('./lexer/ether-lexer')
3
3
 
4
4
  class EtherParser {
5
5
  constructor(options = {}) {
@@ -349,7 +349,13 @@ class EtherParser {
349
349
  'html': 'html',
350
350
  'document': 'html',
351
351
  'tete': 'head',
352
- 'titre': 'h1',
352
+ 'titre': 'title',
353
+ 'titre1': 'h1',
354
+ 'titre2': 'h2',
355
+ 'titre3': 'h3',
356
+ 'titre4': 'h4',
357
+ 'titre5': 'h5',
358
+ 'titre6': 'h6',
353
359
  'paragraphe': 'p',
354
360
  'lien': 'a',
355
361
  'image': 'img',
@@ -871,7 +877,7 @@ class EtherParser {
871
877
  'section': 'section',
872
878
  'article': 'article',
873
879
  'cote': 'aside',
874
- 'titre': 'h1',
880
+ 'titre': 'title',
875
881
  'titre1': 'h1',
876
882
  'titre2': 'h2',
877
883
  'titre3': 'h3',
@@ -374,6 +374,7 @@ class HTMLGenerator {
374
374
  switch (node.type) {
375
375
  case 'Document':
376
376
  case 'document':
377
+ this.output += '<!DOCTYPE html>\n'
377
378
  if (node.children) {
378
379
  for (const child of node.children) {
379
380
  this.generateNode(child)