-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Static site generator. Initial commit
- Loading branch information
Joey Guerra
committed
Oct 14, 2023
1 parent
82aff35
commit a87e340
Showing
9 changed files
with
1,515 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
name: Build and release pipeline | ||
on: | ||
push: | ||
branches: | ||
- main | ||
- next | ||
pull_request: | ||
branches: | ||
- main | ||
- next | ||
permissions: | ||
contents: write | ||
issues: write | ||
pull-requests: write | ||
id-token: write | ||
jobs: | ||
build: | ||
name: Build and Verify | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: | ||
- latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: Setup Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: 'npm' | ||
- name: Install dependencies | ||
run: npm ci | ||
- name: Verify the integrity of provenance attestations and registry signatures for installed dependencies | ||
run: npm audit signatures | ||
test: | ||
name: Fast Tests | ||
runs-on: ubuntu-latest | ||
needs: build | ||
strategy: | ||
matrix: | ||
node-version: | ||
- latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
cache: 'npm' | ||
- run: npm ci | ||
- run: npm test | ||
release: | ||
name: Release | ||
if: github.ref == 'refs/heads/main' && success() | ||
needs: [build, test] | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: | ||
- latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Semantic Release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
run: npx semantic-release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
.DS_Store | ||
node_modules | ||
.hubot_history | ||
.node-version | ||
npm-debug.log | ||
assets | ||
dist | ||
scripts | ||
templates | ||
www |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const map = (args) => { | ||
const options = {} | ||
return args.reduce((acc, arg, i) => { | ||
if(arg == null) return acc | ||
if(arg.toString().length == 0) return acc | ||
if (arg.toString().startsWith('--')) { | ||
const optionName = arg.slice(2) | ||
if (acc[optionName]) { | ||
if (!Array.isArray(acc[optionName])) { | ||
acc[optionName] = [acc[optionName]] | ||
} | ||
acc[optionName].push(args[i+1]) | ||
return acc | ||
} | ||
|
||
if (!args[i+1]) { | ||
acc[optionName] = true | ||
return acc | ||
} | ||
|
||
acc[optionName] = args[i+1]?.toString().indexOf('--') > -1 ? true : args[i+1] | ||
} | ||
return acc | ||
}, options) | ||
} | ||
module.exports = map |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { describe, it } from 'node:test' | ||
import assert from 'node:assert/strict' | ||
import map from './CliArgsParser.js' | ||
|
||
describe('ArgsParser', () => { | ||
it('Should parse an array of key value arguments separated by a space into an object', () => { | ||
const args = ['--help', '--folder', 'public', '--enable', '--port', 3000, '--templates', './templates', '--templates', './templates2', '--serve'] | ||
const options = map(args) | ||
assert.equal(options.help, true) | ||
assert.equal(options.folder, 'public') | ||
assert.equal(options.enable, true) | ||
assert.equal(options.port, 3000) | ||
assert.equal(options.templates.length, 2) | ||
assert.equal(options.serve, true) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
class EventStream { | ||
constructor() { | ||
this.stream = new Map() | ||
this.groups = new Map() | ||
} | ||
async addMessage(id, message) { | ||
if (!this.stream.has(id)) { | ||
this.stream.set(id, []) | ||
} | ||
this.stream.get(id).push(message) | ||
for await (const groupId of this.groups.keys()) { | ||
await this.notifyConsumers(groupId) | ||
} | ||
} | ||
async createGroup(groupName, streamKey, callback) { | ||
if (!this.groups.has(groupName)) { | ||
this.groups.set(groupName, new Map()) | ||
} | ||
this.groups.get(groupName).set(streamKey, { position: 0, callback }) | ||
await this.notifyConsumers(groupName) | ||
} | ||
deleteGroup(groupName, streamKey) { | ||
const group = this.groups.get(groupName) | ||
if (group) { | ||
group.delete(streamKey) | ||
} | ||
} | ||
async notifyConsumers(groupName) { | ||
const group = this.groups.get(groupName) | ||
if (!group) { | ||
return | ||
} | ||
|
||
for await (const [streamId, { position, callback }] of group) { | ||
const messages = this.stream.get(streamId) || [] | ||
if (position >= messages.length) { | ||
group.set(streamId, { position: 0, callback }) | ||
continue | ||
} | ||
const newMessages = messages.slice(position); | ||
// console.log(`Consumer in group ${groupName} received messages: `, newMessages) | ||
!(callback instanceof Function) || await callback(newMessages) | ||
!(callback?.update) || await callback.update(newMessages) | ||
|
||
group.set(streamId, { position: position + newMessages.length, callback }) | ||
} | ||
} | ||
} | ||
|
||
class KeyValueEvent { | ||
constructor(key, value) { | ||
this.key = key; | ||
this.value = value; | ||
this.kind = 'KeyValueEvent' | ||
this.version = '2023-05-06' | ||
this.occurredAt = new Date().toISOString() | ||
this.recordedAt = new Date().toISOString() | ||
} | ||
} | ||
|
||
export { EventStream, KeyValueEvent } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env node | ||
|
||
const spawn = require('child_process').spawn | ||
const resolve = require('path').resolve | ||
const map = require('../CliArgsParser.js') | ||
|
||
const args = process.argv.slice(2) | ||
const nodePath = process.argv[0] | ||
const sfabPath = resolve(__dirname, '../sfab.mjs') | ||
const sfabArgs = map(process.argv.slice(2)) | ||
let nodeArgs = [sfabPath, ...args] | ||
if(sfabArgs['watch-path']) { | ||
nodeArgs.unshift('--watch-path', sfabArgs['watch-path']) | ||
} | ||
const sfab = spawn(nodePath, nodeArgs, { stdio: 'inherit' }) |
Oops, something went wrong.