@tenjuu99/blog 0.2.16 → 0.2.18
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/bin/dev-server +2 -2
- package/index.js +4 -0
- package/lib/config.js +1 -1
- package/lib/dir.js +35 -6
- package/lib/watcher.js +11 -4
- package/package.json +1 -1
- package/src-sample/helper/index.js +1 -37
package/bin/dev-server
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { spawn } from 'child_process'
|
|
4
|
-
import { srcDir, watch as watchDir } from '../lib/dir.js'
|
|
4
|
+
import { srcDir, watch as watchDir, packageDir, packageDirCore } from '../lib/dir.js'
|
|
5
5
|
import { watchers, watch } from '../lib/watcher.js'
|
|
6
6
|
import generate from '../lib/generate.js'
|
|
7
7
|
import path from 'path'
|
|
@@ -27,7 +27,7 @@ watchers.push({
|
|
|
27
27
|
event: ['change', 'unlink', 'add']
|
|
28
28
|
})
|
|
29
29
|
watchers.push({
|
|
30
|
-
paths: [watchDir.serverDir, watchDir.helperDir, libDir],
|
|
30
|
+
paths: [watchDir.serverDir, watchDir.helperDir, libDir, packageDir, packageDirCore],
|
|
31
31
|
callback: () => {
|
|
32
32
|
childProcess.kill('SIGINT')
|
|
33
33
|
childProcess = proceed()
|
package/index.js
ADDED
package/lib/config.js
CHANGED
package/lib/dir.js
CHANGED
|
@@ -58,11 +58,37 @@ const cache = () => {
|
|
|
58
58
|
// generate の中でもコールしているが、同一プロセスであれば alreadyCached 変数で制御される
|
|
59
59
|
cache()
|
|
60
60
|
|
|
61
|
+
let packageDirectoriesLoaded = []
|
|
62
|
+
const packageDirectories = () => {
|
|
63
|
+
if (packageDirectoriesLoaded.length > 0) {
|
|
64
|
+
return packageDirectoriesLoaded
|
|
65
|
+
}
|
|
66
|
+
const watchTargetDir = ['pages', 'template', 'css', 'helper', 'server', 'js']
|
|
67
|
+
const packages = config.packages.split(',').reduce((prev, packageName) => {
|
|
68
|
+
if (fs.existsSync(`${packageDir}/${packageName}`)) {
|
|
69
|
+
prev.push(fs.realpathSync(`${packageDir}/${packageName}`))
|
|
70
|
+
}
|
|
71
|
+
prev.push(fs.realpathSync(`${packageDirCore}/${packageName}`))
|
|
72
|
+
return prev
|
|
73
|
+
}, [srcDir])
|
|
74
|
+
|
|
75
|
+
for (const baseDir of packages) {
|
|
76
|
+
for (const target of watchTargetDir) {
|
|
77
|
+
if (!fs.existsSync(`${baseDir}/${target}`)) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const targetDir = `${baseDir}/${target}`
|
|
81
|
+
packageDirectoriesLoaded.push(targetDir)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return packageDirectoriesLoaded
|
|
85
|
+
}
|
|
86
|
+
|
|
61
87
|
const resolveDestinationPath = (path) => {
|
|
62
|
-
for (const
|
|
63
|
-
if (path.startsWith(
|
|
64
|
-
const dir =
|
|
65
|
-
const srcFile = `${dir}${path.replace(
|
|
88
|
+
for (const targetDir of packageDirectories()) {
|
|
89
|
+
if (path.startsWith(targetDir)) {
|
|
90
|
+
const dir = targetDir.split('/').pop()
|
|
91
|
+
const srcFile = `${dir}${path.replace(targetDir, '')}`
|
|
66
92
|
return `${cacheDir}/${srcFile}`
|
|
67
93
|
}
|
|
68
94
|
}
|
|
@@ -88,7 +114,8 @@ watchers.push({
|
|
|
88
114
|
},
|
|
89
115
|
watchOptions: {
|
|
90
116
|
ignoreInitial: true
|
|
91
|
-
}
|
|
117
|
+
},
|
|
118
|
+
prior: true,
|
|
92
119
|
})
|
|
93
120
|
export {
|
|
94
121
|
rootDir,
|
|
@@ -101,5 +128,7 @@ export {
|
|
|
101
128
|
serverDir,
|
|
102
129
|
helperDir,
|
|
103
130
|
watch,
|
|
104
|
-
cache
|
|
131
|
+
cache,
|
|
132
|
+
packageDir,
|
|
133
|
+
packageDirCore
|
|
105
134
|
}
|
package/lib/watcher.js
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
import chokidar from 'chokidar'
|
|
2
2
|
|
|
3
3
|
const container = []
|
|
4
|
+
const containerPrior = []
|
|
4
5
|
|
|
5
6
|
const watchers = {
|
|
6
|
-
push({ paths, event = 'change', callback, watchOptions }) {
|
|
7
|
+
push({ paths, event = 'change', callback, watchOptions, prior = false }) {
|
|
7
8
|
if (!paths || !callback || typeof callback !== 'function') {
|
|
8
9
|
throw new Error('Invalid object type for watcher.')
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
+
if (prior) {
|
|
12
|
+
containerPrior.push({ paths, event, callback, watchOptions })
|
|
13
|
+
} else {
|
|
14
|
+
container.push({ paths, event, callback, watchOptions })
|
|
15
|
+
}
|
|
11
16
|
}
|
|
12
17
|
}
|
|
13
18
|
|
|
14
19
|
const watch = () => {
|
|
15
|
-
|
|
20
|
+
const callback = (watcher) => {
|
|
16
21
|
const { paths, event, callback, watchOptions } = watcher
|
|
17
22
|
const cwatcher = chokidar.watch(paths, watchOptions)
|
|
18
23
|
if (Array.isArray(event)) {
|
|
@@ -22,7 +27,9 @@ const watch = () => {
|
|
|
22
27
|
} else {
|
|
23
28
|
throw new Error('Invalid event for watcher.')
|
|
24
29
|
}
|
|
25
|
-
}
|
|
30
|
+
}
|
|
31
|
+
containerPrior.forEach(callback)
|
|
32
|
+
container.forEach(callback)
|
|
26
33
|
}
|
|
27
34
|
|
|
28
35
|
export { watchers , watch }
|
package/package.json
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { allData } from '@tenjuu99/blog
|
|
2
|
-
import replaceVariablesFilter from '@tenjuu99/blog/lib/replaceVariablesFilter.js'
|
|
3
|
-
import config from '@tenjuu99/blog/lib/config.js'
|
|
1
|
+
import { allData, config } from '@tenjuu99/blog'
|
|
4
2
|
|
|
5
3
|
export function readIndex (filter = null) {
|
|
6
4
|
const data = Object.entries(allData)
|
|
@@ -15,44 +13,10 @@ export function dateFormat(dateString) {
|
|
|
15
13
|
return `${date.getFullYear()}年${date.getMonth() + 1}月${date.getDate()}日`
|
|
16
14
|
}
|
|
17
15
|
|
|
18
|
-
export function render(text, variables) {
|
|
19
|
-
return replaceVariablesFilter(text, variables)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
16
|
export function getPageData(name) {
|
|
23
17
|
return allData[name]
|
|
24
18
|
}
|
|
25
19
|
|
|
26
|
-
let indexedItemsSorted = null
|
|
27
|
-
export function indexedItems() {
|
|
28
|
-
if (indexedItemsSorted) {
|
|
29
|
-
return indexedItemsSorted
|
|
30
|
-
}
|
|
31
|
-
const sorted = readIndex()
|
|
32
|
-
.filter(v => v.index && v.published != '1970-01-01')
|
|
33
|
-
.sort((a, b) => new Date(a.published) - new Date(b.published))
|
|
34
|
-
let prev, next
|
|
35
|
-
for (const item of sorted) {
|
|
36
|
-
if (prev) {
|
|
37
|
-
prev.next = {
|
|
38
|
-
name: item.name,
|
|
39
|
-
published: item.published,
|
|
40
|
-
url: item.url,
|
|
41
|
-
title: item.title,
|
|
42
|
-
}
|
|
43
|
-
item.prev = {
|
|
44
|
-
name: prev.name,
|
|
45
|
-
published: prev.published,
|
|
46
|
-
url: prev.url,
|
|
47
|
-
title: prev.title,
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
prev = item
|
|
51
|
-
}
|
|
52
|
-
indexedItemsSorted = sorted
|
|
53
|
-
return indexedItemsSorted
|
|
54
|
-
}
|
|
55
|
-
|
|
56
20
|
/**
|
|
57
21
|
* 配列を再帰的に順不同リストに変換する
|
|
58
22
|
* @param {Array|string} arrayOrText
|