-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
621 additions
and
1 deletion.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,7 @@ | ||
import { useKv } from "./use-kv.ts"; | ||
|
||
export function* useCacheDirectory({ path }) { | ||
const kv = yield* useKv(); | ||
|
||
|
||
} |
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,8 @@ | ||
import { createContext, Operation } from 'effection'; | ||
|
||
export const CwdContext = createContext("Deno.cwd", Deno.cwd()); | ||
|
||
export function* useCwd(): Operation<string> { | ||
const cwd = yield* CwdContext; | ||
return cwd; | ||
} |
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,72 @@ | ||
import { Octokit } from "npm:[email protected]"; | ||
import { createTokenAuth } from "npm:@octokit/auth-token"; | ||
import { assert } from "../../lib/deps.js"; | ||
import { call, createContext, resource, Operation } from "../../mod.js"; | ||
|
||
const GithubContext = createContext<Octokit>("octokit"); | ||
|
||
export function* setupGithub() { | ||
const octokit = yield* resource<Octokit>(function* (provide) { | ||
const token = Deno.env.get("GITHUB_TOKEN"); | ||
|
||
assert(token, "GITHUB_TOKEN environment variable is missing"); | ||
|
||
provide( | ||
new Octokit({ | ||
auth: createTokenAuth(token), | ||
}), | ||
); | ||
}); | ||
|
||
yield* GithubContext.set(octokit); | ||
} | ||
|
||
export function* useGithub() { | ||
return yield* GithubContext; | ||
} | ||
|
||
export function* getEffectionReleaseTags(): Operation<string[]> { | ||
const octokit = yield* useGithub(); | ||
|
||
return yield* call(() => | ||
octokit.paginate( | ||
"GET /repos/{owner}/{repo}/tags", | ||
{ | ||
owner: "thefrontside", | ||
repo: "effection", | ||
}, | ||
(response) => | ||
response.data | ||
.filter(({ name }) => | ||
/^effection-v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/.test(name), | ||
) | ||
.map(({ name }) => name), | ||
), | ||
); | ||
} | ||
|
||
export function* createEffectionRelease({ | ||
name, | ||
tag_name, | ||
body, | ||
}: { | ||
tag_name: string; | ||
name?: string | undefined; | ||
body?: string | undefined; | ||
}) { | ||
const octokit = yield* useGithub(); | ||
|
||
return yield* call(() => | ||
octokit.request("POST /repos/{owner}/{repo}/releases", { | ||
owner: "thefrontside", | ||
repo: "effection", | ||
target_commitish: "master", | ||
name, | ||
tag_name, | ||
body, | ||
headers: { | ||
"X-GitHub-Api-Version": "2022-11-28", | ||
}, | ||
}), | ||
); | ||
} |
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,23 @@ | ||
import { call, createContext, resource } from 'effection'; | ||
|
||
const KV_URL = "https://api.deno.com/databases/2b605a51-5827-4718-bcc5-5adca69f87a5/connect"; | ||
|
||
const KvContext = createContext<Deno.Kv>("Deno.Kv") | ||
|
||
export function* openKv() { | ||
return ( | ||
yield * | ||
resource<Deno.Kv>(function* (provide) { | ||
const kv = yield* call(() => Deno.openKv(KV_URL)); | ||
try { | ||
yield* provide(kv); | ||
} finally { | ||
kv.close(); | ||
} | ||
}) | ||
); | ||
} | ||
|
||
export function* useKv() { | ||
yield* KvContext; | ||
} |
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,14 @@ | ||
import { isAbsolute } from "https://deno.land/[email protected]/path/is_absolute.ts"; | ||
import { Operation, call } from "effection"; | ||
import { useCwd } from "./use-cwd.ts"; | ||
import { join } from "https://deno.land/[email protected]/path/join.ts"; | ||
|
||
export function* useMkdir(path: string, options?: Deno.MkdirOptions): Operation<void> { | ||
if (isAbsolute(path)) { | ||
return yield* call(() => Deno.mkdir(path, options)); | ||
} else { | ||
const cwd = yield* useCwd(); | ||
console.log({ cwd }) | ||
return yield* call(() => Deno.mkdir(join(cwd, path), options)); | ||
} | ||
} |
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,69 @@ | ||
import { Operation, Scope, Stream, each, resource, useScope } from "effection"; | ||
import { expect } from "https://deno.land/x/expect/mod.ts"; | ||
import { writeSync } from "https://deno.land/x/[email protected]/mod.ts"; | ||
import { beforeEach, describe, it } from "../test/deno.bdd.ts"; | ||
import { CwdContext, useCwd } from "./use-cwd.ts"; | ||
import { useMkdir } from "./use-mkdir.ts"; | ||
import { useReadDir } from "./use-read-dir.ts"; | ||
|
||
function* useTmpCwd(scope: Scope): Operation<string> { | ||
return yield* resource<string>(function* (provide) { | ||
const cwd = yield* useCwd(); | ||
const tmp = Deno.makeTempFileSync(); | ||
|
||
try { | ||
console.log({ tmp }); | ||
scope.set(CwdContext, tmp); | ||
provide(tmp); | ||
} finally { | ||
scope.set(CwdContext, cwd); | ||
} | ||
}); | ||
} | ||
|
||
function* capture<T, TReturn>(stream: Stream<T, TReturn>): Operation<T[]> { | ||
const result: T[] = []; | ||
for (let value of yield* each(stream)) { | ||
result.push(value); | ||
yield* each.next(); | ||
} | ||
return result; | ||
} | ||
|
||
describe("use-read-dir", () => { | ||
beforeEach(function* () { | ||
const scope = yield* useScope(); | ||
yield* useTmpCwd(scope); | ||
yield* useMkdir("testdir"); | ||
|
||
writeSync("testdir", { | ||
"index.html": "<html><body><h1>Effection Docs</h1></body></html>", | ||
"fuse.js": `console.log("hello world")`, | ||
"page.css": "body { background: black; }", | ||
"~": { | ||
"main.html": "<html><body><h1>main()</h1></body></html>", | ||
}, | ||
}); | ||
}); | ||
|
||
it("reads files from tmp testdir", function* () { | ||
expect(yield* capture(yield* useReadDir("testdir"))).toEqual([ | ||
{ | ||
name: "index.html", | ||
isFile: true, | ||
}, | ||
{ | ||
name: "page.css", | ||
isFile: true, | ||
}, | ||
{ | ||
name: 'fuse.js', | ||
isFile: true, | ||
}, | ||
{ | ||
name: '~', | ||
isDirectory: 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,13 @@ | ||
import { Operation, stream, Stream } from "effection"; | ||
import { isAbsolute } from "https://deno.land/[email protected]/path/is_absolute.ts"; | ||
import { join } from "https://deno.land/[email protected]/path/join.ts"; | ||
import { useCwd } from "./use-cwd.ts"; | ||
|
||
export function* useReadDir(path: string): Operation<Stream<Deno.DirEntry, unknown>> { | ||
if (isAbsolute(path)) { | ||
return stream(Deno.readDir(path)); | ||
} else { | ||
const cwd = yield* useCwd(); | ||
return stream(Deno.readDir(join(cwd, path))); | ||
} | ||
} |
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,13 @@ | ||
import { isAbsolute } from "https://deno.land/[email protected]/path/is_absolute.ts"; | ||
import { join } from "https://deno.land/[email protected]/path/join.ts"; | ||
import { useCwd } from "./use-cwd.ts"; | ||
import { Operation, call } from "effection"; | ||
|
||
export function* useReadFile(path: string): Operation<Uint8Array> { | ||
if (isAbsolute(path)) { | ||
return yield* call(() => Deno.readFile(path)); | ||
} else { | ||
const cwd = yield* useCwd(); | ||
return yield* call(() => Deno.readFile(join(cwd, path))); | ||
} | ||
} |
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,27 @@ | ||
import { main } from '../../lib/main.ts'; | ||
import { setupGithub } from '../lib/use-github.ts'; | ||
import { useCommand } from "../lib/use-command.ts"; | ||
import { assert } from "../../lib/deps.ts"; | ||
|
||
function* createRelease({ ref_name }: { ref_name: string }) { | ||
|
||
const version = ref_name.replace('effection-v', ''); | ||
|
||
yield* useCommand(`deno doc --html --name=effection@${version} mod.ts`); | ||
|
||
yield* useCommand(`tar cfvz api-docs.tgz -C docs .`); | ||
|
||
|
||
} | ||
|
||
await main(function*() { | ||
yield* setupGithub(); | ||
|
||
const ref_name = Deno.env.get('GITHUB_REF_NAME'); | ||
assert(ref_name, `Missing GITHUB_REF_NAME environment variable`) | ||
|
||
yield* createRelease({ | ||
ref_name, | ||
}); | ||
}) | ||
|
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,12 @@ | ||
import { main } from "../lib/main.ts"; | ||
import { setupGithub, getEffectionReleaseTags } from "../www/lib/use-github.ts"; | ||
|
||
function* recreateReleases() { | ||
const tags = yield* getEffectionReleaseTags(); | ||
|
||
} | ||
|
||
await main(function* () { | ||
yield* setupGithub(); | ||
yield* recreateReleases(); | ||
}); |
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,46 @@ | ||
import * as bdd from "https://deno.land/[email protected]/testing/bdd.ts"; | ||
import { TestScope, createTestScope } from "./test-scope.ts"; | ||
import type { Operation } from "effection"; | ||
|
||
let scope: TestScope | void = void 0; | ||
|
||
// Integrate test scope with the Deno test runner by wrapping the `describe()`, `it()` and `beforeEach()` methods. | ||
function describeWithScope<T>(...args: bdd.DescribeArgs<T>): bdd.TestSuite<T> { | ||
let [name, def] = args; | ||
return bdd.describe(name as string, () => { | ||
bdd.beforeEach(() => { | ||
if (!scope) { | ||
scope = createTestScope(); | ||
} | ||
}); | ||
|
||
if (def && typeof def === "function") { | ||
def(); | ||
} | ||
}); | ||
} | ||
|
||
describeWithScope.only = bdd.describe.only; | ||
describeWithScope.ignore = bdd.describe.ignore; | ||
|
||
export const describe: typeof bdd.describe = describeWithScope; | ||
|
||
export function beforeEach(op: () => Operation<void>): void { | ||
bdd.beforeEach(() => scope!.addSetup(op)); | ||
} | ||
|
||
export function it(desc: string, op?: () => Operation<void>): void { | ||
if (op) { | ||
return bdd.it(desc, () => scope!.runTest(op)); | ||
} else { | ||
return bdd.it.ignore(desc, () => {}); | ||
} | ||
} | ||
|
||
it.only = function only(desc: string, op?: () => Operation<void>): void { | ||
if (op) { | ||
return bdd.it.only(desc, () => scope!.runTest(op)); | ||
} else { | ||
return bdd.it.ignore(desc, () => {}); | ||
} | ||
}; |
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,34 @@ | ||
import { run, type Operation } from "effection"; | ||
/** | ||
* Source https://gist.github.com/cowboyd/70e4596e61aadafd852f403dc6d8ec6f#file-01-test-scope-ts | ||
*/ | ||
export interface TestScope { | ||
/** | ||
* Call from your runner's "beforeEach" or equivalent | ||
*/ | ||
addSetup(op: () => Operation<void>): void; | ||
|
||
/** | ||
* Call from runner's `it()` or equivalent; | ||
*/ | ||
runTest(op: () => Operation<void>): Promise<void>; | ||
} | ||
|
||
export function createTestScope(): TestScope { | ||
let setup = [] as Array<() => Operation<void>>; | ||
|
||
return { | ||
addSetup(op) { | ||
setup.push(op); | ||
}, | ||
|
||
runTest(op) { | ||
return run(function* () { | ||
for (let step of setup) { | ||
yield* step(); | ||
} | ||
yield* op(); | ||
}); | ||
}, | ||
}; | ||
} |
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 @@ | ||
console.log("hello world") |
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 @@ | ||
<html><body><h1>Effection Docs</h1></body></html> |
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 @@ | ||
body { background: black; } |
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 @@ | ||
<html><body><h1>main()</h1></body></html> |