-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpackager.js
137 lines (114 loc) · 3.08 KB
/
packager.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// # Copyright (c) 2022 Feudal Code Limitada #
// MIT License
"use strict"
/*
*
* This file is supposed to be run with Deno.
*
*
* WARNING: THIS WRITES IN YOUR CURRENT WORKING DIRECTORY
*
*
* It packages the source files of the GoodbyeHtml library into a
*
* single file called goodbye.js in your current working directory.
*
*
*/
var consolidation = ""
var title = "Goodbye Library packager"
var sourcePaths = [ ]
var pathForHtmlFile = "source.html"
var pathForPackaged = "goodbye.js"
// main ///////////////////////////////////////////////////////////////////////
function main() {
//
console.log("\u001Bc") // *clears console perfectly* //
//
console.log("running " + title)
console.log(" -- no available options\n")
//
fillSourcePaths()
//
applyHead()
applyBody()
applyFoot()
//
Deno.writeTextFileSync(pathForPackaged, consolidation)
}
///////////////////////////////////////////////////////////////////////////////
function fillSourcePaths() {
//
const html = loadFile(pathForHtmlFile)
const lines = html.split("\n")
//
for (const line of lines) {
//
const trim = line.trim()
if (! trim.startsWith("<script src=")) { continue }
//
const path = trim.replace("<script src=\"", "").replace("\"></script>", "")
sourcePaths.push(path)
}
}
///////////////////////////////////////////////////////////////////////////////
function applyHead() {
//
consolidation = Deno.readTextFileSync("source/README.js")
//
consolidation += "\n\n\"use strict\""
consolidation += "\n\nfunction createGoodbyeHtmlLibrary() {\n\n\n"
}
function applyBody() {
//
for (const path of sourcePaths) { consolidateSourceFile(path) }
}
function applyFoot() {
//
consolidation += "\n\n\n\nreturn __createTheLibraryObject()"
//
consolidation += "\n\n}\n"
}
///////////////////////////////////////////////////////////////////////////////
function consolidateSourceFile(path) {
//
let txt = "\n\n\n// [[" + path + "]] "
txt += "#".repeat(82 - txt.length) + "\n"
//
const jslines = loadTrimmedJsLines(path)
//
for (const line of jslines) {
//
if (line == "// # Copyright (c) 2022 Feudal Code Limitada #") { continue }
if (line == "// MIT License") { continue }
if (line == '"use strict"') { continue }
//
txt += "\n" + line
}
//
consolidation += txt
}
///////////////////////////////////////////////////////////////////////////////
function loadTrimmedJsLines(path) {
//
const text = loadFile(path).trimRight()
//
const lines = text.split("\n")
//
for (let n = 0; n < lines.length; n++) {
//
lines[n] = lines[n].trimRight()
}
return lines
}
function loadFile(path) {
try {
return Deno.readTextFileSync(path)
}
catch (e) {
console.log("ERROR: could not read: " + path)
Deno.exit(1)
}
}
// boot ///////////////////////////////////////////////////////////////////////
main()