Skip to content

Commit

Permalink
Better build tools. Easier tests
Browse files Browse the repository at this point in the history
  • Loading branch information
breck7 committed Dec 17, 2024
1 parent 55457a4 commit 2751800
Show file tree
Hide file tree
Showing 18 changed files with 79 additions and 57 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scroll-cli",
"version": "164.3.0",
"version": "164.4.0",
"description": "A language for scientists of all ages. A curated collection of tools for refining and sharing thoughts.",
"main": "scroll.js",
"engines": {
Expand Down
7 changes: 5 additions & 2 deletions parsers/assertions.parsers
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ abstractAssertionParser
description Test above particle's output.
extends abstractScrollParser
string bindTo previous
catchAllAtomType codeAtom
cueFromId
javascript
buildHtml() {
Expand All @@ -13,13 +14,15 @@ abstractAssertionParser
}
get actual() {return this.particleToTest.buildHtml()}
getErrors() {
const {actual} = this
const expected = this.subparticlesToString()
const {actual, expected} = this
const errors = super.getErrors()
if (this.areEqual(actual, expected))
return errors
return errors.concat(this.makeError(`'${actual}' did not ${this.kind} '${expected}'`))
}
get expected() {
return this.length ? this.subparticlesToString() : (this.content ? this.content : "")
}
catchAllParser htmlLineParser

assertIgnoreBelowErrorsParser
Expand Down
25 changes: 24 additions & 1 deletion parsers/build.parsers
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,27 @@ abstractBuildTwoCommandParser
javascript
async buildTwo() {
await this._buildFileType(this.extension)
}
}

scrollFileAddressParser
catchAllAtomType filePathAtom
catchAllParser scrollFileAddressParser

abstractInlineFileParser
extends abstractScrollParser
catchAllAtomType filePathAtom
catchAllParser scrollFileAddressParser
string joinChar ;\n\n
string htmlTag script
javascript
get files() {
const inline = this.atoms.slice(1)
const children = this.map(particle => particle.cue)
return inline.concat(children)
}
get contents() {
return this.files.map(filename => this.root.readFile(filename)).join(this.joinChar)
}
buildHtml() {
return `<${this.htmlTag}>/* ${this.files.join(" ")} */\n${this.contents}</${this.htmlTag}>`
}
21 changes: 8 additions & 13 deletions parsers/css.parsers
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,20 @@ cssParser
get css() {
return this.content ?? this.subparticlesToString()
}
buildCs() {
buildCss() {
return this.css
}

inlineCssParser
scrollInlineCssParser
description Inline CSS from files.
popularity 0.007211
extends abstractScrollParser
cueFromId
catchAllAtomType filePathAtom
extends abstractInlineFileParser
cue inlineCss
string joinChar \n\n
string htmlTag style
javascript
buildHtml() {
return `<style>/* ${this.content} */\n${this.css}</style>`
}
get css() {
return this.atoms.slice(1).map(filename => this.root.readFile(filename)).join("\n\n")
}
buildCs() {
return this.css
buildCss() {
return this.contents
}

scrollBackgroundColorParser
Expand Down
2 changes: 1 addition & 1 deletion parsers/hakon.parsers
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ hakonParser
const {hakonParser} = this.root
return new hakonParser(this.subparticlesToString()).compile()
}
buildCs() {
buildCss() {
return this.css
}
13 changes: 3 additions & 10 deletions parsers/javascript.parsers
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,12 @@ quickScriptParser
return `<script src="${this.filename}"></script>`
}

inlineJsParser
scrollInlineJsParser
description Inline JS from files.
popularity 0.007211
extends abstractScrollParser
cueFromId
catchAllAtomType filePathAtom
extends abstractInlineFileParser
cue inlineJs
javascript
buildHtml() {
return `<script>/* ${this.content} */\n${this.contents}</script>`
}
get contents() {
return this.atoms.slice(1).map(filename => this.root.readFile(filename)).join(";\n\n")
}
buildJs() {
return this.contents
}
Expand Down
8 changes: 7 additions & 1 deletion parsers/root.parsers
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,16 @@ scrollParser
const {path} = this
const fs = require("fs")
const fullPath = path.join(this.folderPath, filename.replace(this.folderPath, ""))
try {
if (fs.existsSync(fullPath))
return fs.readFileSync(fullPath, "utf8")
console.error(`File '${filename}' not found`)
return ""
} catch (err) {
console.error(`Error in '${this.filePath}' reading file: '${fullPath}'`)
console.error(err)
return ""
}
}
alreadyRequired = new Set()
buildHtmlSnippet(buildSettings) {
Expand Down Expand Up @@ -340,7 +346,7 @@ scrollParser
}
get scrollVersion() {
// currently manually updated
return "164.3.0"
return "164.4.0"
}
// Use the first paragraph for the description
// todo: add a particle method version of get that gets you the first particle. (actulaly make get return array?)
Expand Down
5 changes: 5 additions & 0 deletions releaseNotes.scroll
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ ciBadges.scroll
br
thinColumns

📦 164.4.0 12/17/2024
🎉 assertions now can also be one liners
🎉 `inlineJs` and `inlineCss` can now take filenames as subparticles
🏥 bug fixes in buildCss methods

📦 164.3.0 12/16/2024
🎉 update ScrollSDK

Expand Down
3 changes: 1 addition & 2 deletions tests/buildDelimited.scroll
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
buildCsv
assertBuildIncludes
virginica
assertBuildIncludes virginica
buildTsv
buildJson
buildTxt
Expand Down
11 changes: 11 additions & 0 deletions tests/bundling.scroll
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
buildCss
assertBuildIncludes --scrollFontPrimary
buildJs

// Bundle any random files:
inlineCss ../animation.css
../style.css

// Just bundle a couple of random files:
inlineJs ../scroll.js
../importParsers.js
3 changes: 1 addition & 2 deletions tests/defs.scroll
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
buildParsers
assertBuildIncludes
URL to the creation
assertBuildIncludes URL to the creation

urlDef URL to the creation being tried?

Expand Down
15 changes: 5 additions & 10 deletions tests/dependencies.scroll
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,11 @@ container

dependencies
printTable
assertHtmlIncludes
header.scroll
assertHtmlIncludes
changes.parsers
assertHtmlIncludes
contacts.csv
assertHtmlIncludes
style.css
assertHtmlIncludes
particles.png
assertHtmlIncludes header.scroll
assertHtmlIncludes changes.parsers
assertHtmlIncludes contacts.csv
assertHtmlIncludes style.css
assertHtmlIncludes particles.png

../particles.png

Expand Down
3 changes: 1 addition & 2 deletions tests/feed.scroll
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
buildRss
assertBuildIncludes
<?xml
assertBuildIncludes <?xml

settings.scroll

Expand Down
3 changes: 1 addition & 2 deletions tests/html.scroll
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
buildHtml

<b></b>
assertHtmlEquals
<b></b>
assertHtmlEquals <b></b>

The background should be green
htmlInclude.html
3 changes: 1 addition & 2 deletions tests/iris.scroll
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ buildHtml
iris
shuffle
printTable
assertHtmlIncludes
virginica
assertHtmlIncludes virginica
3 changes: 1 addition & 2 deletions tests/keyboardNav.scroll
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
buildHtml
keyboardNav
assertHtmlExcludes
undefined
assertHtmlExcludes undefined
6 changes: 2 additions & 4 deletions tests/meta.scroll
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
buildCsv
assertBuildIncludes
date,year,title,permalink
assertBuildIncludes
Breck
assertBuildIncludes date,year,title,permalink
assertBuildIncludes Breck
postsMeta ../blog/All
printTable
3 changes: 1 addition & 2 deletions tests/posts.scroll
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ header.scroll
posts index subfolder/index
printColumn title
join ·
assertHtmlIncludes
sink
assertHtmlIncludes sink

---

Expand Down

0 comments on commit 2751800

Please sign in to comment.