votive 0.0.9 → 0.2.0
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/README.md +1 -0
- package/lib/bundle.js +1 -0
- package/lib/createDatabase.js +19 -3
- package/lib/readSources.js +41 -19
- package/package.json +1 -1
- package/tests/index.js +1 -1
package/README.md
CHANGED
package/lib/bundle.js
CHANGED
|
@@ -227,6 +227,7 @@ async function bundle(config, cache) {
|
|
|
227
227
|
// Read folders and source files
|
|
228
228
|
const { folders, sources } = await readSources(config, database, processors)
|
|
229
229
|
|
|
230
|
+
console.log(123)
|
|
230
231
|
sourceTime()
|
|
231
232
|
|
|
232
233
|
if(config.verbose) console.info(`${styleText("dim", "build:")} ${styleText("magenta", `found ${sources.length} stale files`)}`)
|
package/lib/createDatabase.js
CHANGED
|
@@ -366,7 +366,7 @@ function prepareStatements(database) {
|
|
|
366
366
|
* @returns {SQLiteDependency[]}
|
|
367
367
|
*/
|
|
368
368
|
|
|
369
|
-
|
|
369
|
+
getAllByTarget: /** @type {{all: SQLiteDependencyGetByTarget}} */ (/** @type {unknown} */ (database.prepare(`
|
|
370
370
|
SELECT * FROM dependencies WHERE destination = ?
|
|
371
371
|
`))),
|
|
372
372
|
|
|
@@ -572,10 +572,11 @@ function createDatabase(databasePath = ".votive.db") {
|
|
|
572
572
|
prepared.settings.delete.all(filePath)
|
|
573
573
|
prepared.dependency.deleteByTarget.all(deletedSource.destination)
|
|
574
574
|
.forEach(({ dependent }) => {
|
|
575
|
-
prepared.
|
|
575
|
+
prepared.target.markStale.get(dependent)
|
|
576
576
|
})
|
|
577
577
|
prepared.metadata.deleteByTarget.all(deletedSource.destination)
|
|
578
578
|
prepared.target.delete.get(deletedSource.destination)
|
|
579
|
+
return deletedSource
|
|
579
580
|
},
|
|
580
581
|
|
|
581
582
|
getAll() {
|
|
@@ -666,6 +667,13 @@ function createDatabase(databasePath = ".votive.db") {
|
|
|
666
667
|
return prepared.dependency.getAll.all()
|
|
667
668
|
},
|
|
668
669
|
|
|
670
|
+
/**
|
|
671
|
+
* @param {string} target
|
|
672
|
+
*/
|
|
673
|
+
getAllByTarget(target) {
|
|
674
|
+
return prepared.dependency.getAllByTarget.all(target)
|
|
675
|
+
},
|
|
676
|
+
|
|
669
677
|
/**
|
|
670
678
|
* @param {object} dependencyFile
|
|
671
679
|
* @param {string} dependencyKey
|
|
@@ -688,7 +696,7 @@ function createDatabase(databasePath = ".votive.db") {
|
|
|
688
696
|
|
|
689
697
|
/**
|
|
690
698
|
* @param {string} filePath
|
|
691
|
-
* @returns {TargetOutput}
|
|
699
|
+
* @returns {TargetOutput | undefined}
|
|
692
700
|
*/
|
|
693
701
|
get(filePath) {
|
|
694
702
|
const target = prepared.target.get.get(filePath)
|
|
@@ -747,6 +755,8 @@ function createDatabase(databasePath = ".votive.db") {
|
|
|
747
755
|
getWithTrackers(filePath, dependent) {
|
|
748
756
|
const target = queries.target.get(filePath)
|
|
749
757
|
|
|
758
|
+
if(!target) return
|
|
759
|
+
|
|
750
760
|
const trackedTarget = { metadata: {} }
|
|
751
761
|
|
|
752
762
|
queries.dependency.track(
|
|
@@ -906,7 +916,13 @@ function createDatabase(databasePath = ".votive.db") {
|
|
|
906
916
|
/** @param {string} filePath */
|
|
907
917
|
markFresh(filePath) {
|
|
908
918
|
return prepared.target.markFresh.get(filePath)
|
|
919
|
+
},
|
|
920
|
+
|
|
921
|
+
/** @param {string} filePath */
|
|
922
|
+
markStale(filePath) {
|
|
923
|
+
return prepared.target.markStale.get(filePath)
|
|
909
924
|
}
|
|
925
|
+
|
|
910
926
|
},
|
|
911
927
|
|
|
912
928
|
url: {
|
package/lib/readSources.js
CHANGED
|
@@ -3,7 +3,7 @@ import fs from "node:fs/promises"
|
|
|
3
3
|
import path from "node:path"
|
|
4
4
|
import pLimit from "p-limit"
|
|
5
5
|
|
|
6
|
-
/** @import {VotiveConfig, VotivePlugin, VotiveProcessor, FlatProcessors, Abstracts, Abstract, Jobs, ProcessorSyntax} from "./bundle.js" */
|
|
6
|
+
/** @import {VotiveConfig, VotivePlugin, VotiveProcessor, FlatProcessors, Abstracts, Abstract, Jobs, ProcessorSyntax, Router} from "./bundle.js" */
|
|
7
7
|
/** @import {Dirent} from "node:fs" */
|
|
8
8
|
/** @import {Database} from "./createDatabase.js" */
|
|
9
9
|
|
|
@@ -31,28 +31,50 @@ async function readSources(config, database, processors) {
|
|
|
31
31
|
const loadingFiles = files.map(a => path.normalize(path.format({ name: a.name, dir: a.parentPath })))
|
|
32
32
|
if (!files) return { folders, sources: [] }
|
|
33
33
|
const limit = pLimit(5)
|
|
34
|
-
const readingSourceFiles = files.flatMap(readSourceFile(processors, database, config
|
|
35
|
-
// const sources = readingSourceFiles && readingSourceFiles.map(async file => {
|
|
36
|
-
// try {
|
|
37
|
-
// const loaded = await file
|
|
38
|
-
// // console.log(loaded)
|
|
39
|
-
// // const i = loadingFiles.find(a => a === loaded.sourceFilePath)
|
|
40
|
-
// // loadingFiles.splice(i,1)
|
|
41
|
-
// // console.log(loadingFiles)
|
|
42
|
-
// return loaded
|
|
43
|
-
// } catch (e) {
|
|
44
|
-
// console.error(e)
|
|
45
|
-
// }
|
|
46
|
-
// })
|
|
47
|
-
const sources = readingSourceFiles && (await Promise.all(readingSourceFiles)).filter(a => a)
|
|
34
|
+
const readingSourceFiles = files.flatMap(readSourceFile(processors, database, config))
|
|
48
35
|
|
|
36
|
+
const reading = [
|
|
37
|
+
(await Promise.all(readingSourceFiles)).filter(a => a),
|
|
38
|
+
pruneDeletions(config, database, filteredDirents)
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
const [sources, deletedSources] = await Promise.all(reading)
|
|
42
|
+
|
|
43
|
+
// const sources = readingSourceFiles && (await Promise.all(readingSourceFiles)).filter(a => a)
|
|
44
|
+
|
|
45
|
+
console.log({ sources })
|
|
46
|
+
|
|
47
|
+
// const deletedSources = await pruneDeletions(config, database, filteredDirents)
|
|
48
|
+
|
|
49
|
+
console.log({ deletedSources })
|
|
49
50
|
|
|
50
51
|
return {
|
|
51
52
|
folders,
|
|
52
|
-
sources
|
|
53
|
+
sources: [...sources, ...deletedSources]
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
|
|
57
|
+
/**
|
|
58
|
+
* @param {VotiveConfig} config
|
|
59
|
+
* @param {Database} database
|
|
60
|
+
* @param {Dirent[]} dirents
|
|
61
|
+
*/
|
|
62
|
+
async function pruneDeletions(config, database, dirents) {
|
|
63
|
+
const sourceFilePaths = new Set(dirents.map(d => d.isFile() && path.join(d.parentPath, d.name)))
|
|
64
|
+
const sourceRecords = database.source.getAll()
|
|
65
|
+
const sourceRecordPaths = new Set(sourceRecords.map(r => r.path))
|
|
66
|
+
|
|
67
|
+
const deletions = sourceRecordPaths.difference(sourceFilePaths)
|
|
68
|
+
|
|
69
|
+
let deletedSources = []
|
|
70
|
+
|
|
71
|
+
deletions.forEach(deletion => {
|
|
72
|
+
deletedSources.push(database.source.delete(deletion))
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
return deletedSources.filter(a => a)
|
|
76
|
+
}
|
|
77
|
+
|
|
56
78
|
/**
|
|
57
79
|
* @param {VotiveConfig} config
|
|
58
80
|
*/
|
|
@@ -98,7 +120,7 @@ function fileFilter(config) {
|
|
|
98
120
|
* @param {Database} database
|
|
99
121
|
* @param {VotiveConfig} config
|
|
100
122
|
*/
|
|
101
|
-
function readSourceFile(processors, database, config
|
|
123
|
+
function readSourceFile(processors, database, config) {
|
|
102
124
|
/**
|
|
103
125
|
* @param {import("node:fs").Dirent} dirent
|
|
104
126
|
* @returns {Promise<ReadSourceFileResult>[]}
|
|
@@ -108,14 +130,14 @@ function readSourceFile(processors, database, config, limit) {
|
|
|
108
130
|
const sourceFilePath = path.join(parentPath, name)
|
|
109
131
|
const sourceFileInfo = path.parse(sourceFilePath)
|
|
110
132
|
|
|
111
|
-
const processing = processors.flatMap(({ plugin, processor }) => process(plugin, processor, config
|
|
133
|
+
const processing = processors.flatMap(({ plugin, processor }) => process(plugin, processor, config))
|
|
112
134
|
|
|
113
135
|
/**
|
|
114
136
|
* @param {VotivePlugin} plugin
|
|
115
137
|
* @param {VotiveProcessor} processor
|
|
116
138
|
* @param {VotiveConfig} config
|
|
117
139
|
*/
|
|
118
|
-
async function process(plugin, processor, config
|
|
140
|
+
async function process(plugin, processor, config) {
|
|
119
141
|
const { readFile: read, extensions: filter, format } = processor
|
|
120
142
|
if (filter.includes(sourceFileInfo.ext) && read) {
|
|
121
143
|
|
package/package.json
CHANGED
package/tests/index.js
CHANGED
|
@@ -93,9 +93,9 @@ test("bundle", async () => {
|
|
|
93
93
|
const dir = fs.readdirSync(tempDest.path, { recursive: true })
|
|
94
94
|
assert(dir.length === 0, "Destination directory is not empty.")
|
|
95
95
|
} catch (error) {
|
|
96
|
-
console.error(error)
|
|
97
96
|
tempDest.remove()
|
|
98
97
|
tempSource.remove()
|
|
98
|
+
console.error(error)
|
|
99
99
|
|
|
100
100
|
}
|
|
101
101
|
|