als-document 1.4.1 → 1.4.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/build.js +14 -14
- package/document.js +42 -727
- package/index.js +41 -726
- package/index.mjs +42 -726
- package/lib/node/single-node.js +4 -4
- package/package.json +1 -1
package/build.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const { readFileSync, writeFileSync, watchFile, watch } = require('fs')
|
|
2
|
-
const { join,basename } = require('path')
|
|
2
|
+
const { join, basename } = require('path')
|
|
3
3
|
|
|
4
4
|
function optimizeCode(content) {
|
|
5
5
|
// content = content.replace(/(?<!\\)\/\/.*$/gm, '') // remove comments
|
|
@@ -19,18 +19,18 @@ function optimizeCode(content) {
|
|
|
19
19
|
|
|
20
20
|
const root = __dirname
|
|
21
21
|
const files = {
|
|
22
|
-
'query': ['query','check-element'],
|
|
23
|
-
'node':[
|
|
24
|
-
'dataset','find','text-node',
|
|
25
|
-
'style','class-list','node','single-node','root','document'
|
|
22
|
+
'query': ['query', 'check-element'],
|
|
23
|
+
'node': [
|
|
24
|
+
'dataset', 'find', 'text-node',
|
|
25
|
+
'style', 'class-list', 'node', 'single-node', 'root', 'document'
|
|
26
26
|
],
|
|
27
|
-
'parse':['parse-atts','void-tags','parser','cache'],
|
|
27
|
+
'parse': ['parse-atts', 'void-tags', 'parser', 'cache'],
|
|
28
28
|
}
|
|
29
29
|
const fileList = []
|
|
30
30
|
function buildFileList() {
|
|
31
|
-
Object.entries(files).forEach(([dir,filenames]) => {
|
|
31
|
+
Object.entries(files).forEach(([dir, filenames]) => {
|
|
32
32
|
filenames.forEach(filename => {
|
|
33
|
-
fileList.push(join(root,'lib',dir,filename+'.js'))
|
|
33
|
+
fileList.push(join(root, 'lib', dir, filename + '.js'))
|
|
34
34
|
});
|
|
35
35
|
});
|
|
36
36
|
}
|
|
@@ -39,12 +39,12 @@ buildFileList()
|
|
|
39
39
|
|
|
40
40
|
function build() {
|
|
41
41
|
let content = fileList.map(filePath => readFileSync(filePath, 'utf-8')).join('\n');
|
|
42
|
-
|
|
43
|
-
const toReturn =
|
|
42
|
+
const arr = ['parseHTML', 'Node', 'Query', 'TextNode', 'SingleNode', 'buildFromCache', 'cacheDoc', 'Root', 'Document']
|
|
43
|
+
const toReturn = `{ ${arr.join(',')} }`
|
|
44
44
|
content = optimizeCode(content)
|
|
45
45
|
writeFileSync(join(root, 'document.js'), `const alsDocument = (function(){\n${content}\nreturn ${toReturn}\n})()`)
|
|
46
|
-
writeFileSync(join(root, 'index.js'), content
|
|
47
|
-
writeFileSync(join(root, 'index.mjs'), content
|
|
46
|
+
writeFileSync(join(root, 'index.js'), [content,`module.exports = ${toReturn}`].join('\n'))
|
|
47
|
+
writeFileSync(join(root, 'index.mjs'), [content,`export ${toReturn}`,`export default ${toReturn}`].join('\n'))
|
|
48
48
|
console.log('Files are builded')
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -54,10 +54,10 @@ if (process.argv[2] === '--watch') {
|
|
|
54
54
|
console.log('Waching...')
|
|
55
55
|
let lastChangeTime = Date.now()
|
|
56
56
|
Object.keys(files).forEach(dirName => {
|
|
57
|
-
const dirPath = join(__dirname,dirName)
|
|
57
|
+
const dirPath = join(__dirname, dirName)
|
|
58
58
|
watch(dirPath, (eventType, filename) => {
|
|
59
59
|
let newChangeTime = Date.now()
|
|
60
|
-
if(newChangeTime - lastChangeTime < 1000) return
|
|
60
|
+
if (newChangeTime - lastChangeTime < 1000) return
|
|
61
61
|
build()
|
|
62
62
|
lastChangeTime = newChangeTime
|
|
63
63
|
console.log(`${filename} has changed (${count++})`)
|