2023-02-10 16:30:37 +00:00
|
|
|
import { assert } from "https://deno.land/std@0.144.0/_util/assert.ts";
|
2023-02-11 11:13:48 +00:00
|
|
|
import { join } from "../deps.ts";
|
2023-02-10 16:30:37 +00:00
|
|
|
import * as mod from "../mod.ts";
|
2023-02-11 11:13:48 +00:00
|
|
|
import type { FileMeta, PickConfig } from "../mod.d.ts";
|
2023-02-10 08:17:05 +00:00
|
|
|
const { test } = Deno;
|
2023-02-10 16:30:37 +00:00
|
|
|
|
|
|
|
test("mod", async (t) => {
|
|
|
|
const repo = "saadeghi/daisyui";
|
|
|
|
const version = "v2.47.0";
|
2023-02-11 11:13:48 +00:00
|
|
|
|
|
|
|
await t.step("mod.githubPick", async () => {
|
2023-02-10 16:30:37 +00:00
|
|
|
const pick = [
|
|
|
|
/^.*\/base\/.*\.css$/,
|
|
|
|
/src\/index\.js/,
|
|
|
|
];
|
2023-02-11 11:13:48 +00:00
|
|
|
const files: FileMeta[] = [];
|
2023-02-10 16:30:37 +00:00
|
|
|
for await (const file of mod.githubPick({ repo, version, pick })) {
|
|
|
|
files.push(file);
|
|
|
|
}
|
|
|
|
assert(files.length > 0);
|
2023-02-11 11:13:48 +00:00
|
|
|
assert(files.filter((f) => f.fileName?.endsWith(".js")).length == 1);
|
|
|
|
assert(files.filter((f) => f.fileName?.endsWith(".css")).length == 2);
|
2023-02-10 16:30:37 +00:00
|
|
|
});
|
2023-02-11 11:13:48 +00:00
|
|
|
|
|
|
|
await t.step("mod.getFetchCache", async () => {
|
2023-02-10 16:30:37 +00:00
|
|
|
const name = `${repo}@${version}`;
|
|
|
|
const cached = await mod.getFetchCache(name);
|
|
|
|
assert(cached?.endsWith(version));
|
|
|
|
assert(cached == join(mod.CACHE_DIR, name));
|
|
|
|
});
|
2023-02-11 11:13:48 +00:00
|
|
|
|
|
|
|
await t.step("mod.write: autoStrategy", async () => {
|
|
|
|
const output = ".daisyui";
|
|
|
|
const config: PickConfig = [
|
|
|
|
{
|
|
|
|
source: `${repo}@${version}`,
|
|
|
|
output,
|
|
|
|
pick: [
|
|
|
|
/^.*\/base\/.*\.css$/,
|
|
|
|
/src\/index\.js/,
|
|
|
|
],
|
|
|
|
},
|
|
|
|
];
|
|
|
|
await mod.write(config);
|
|
|
|
const files = await Deno.readDir(output);
|
|
|
|
for await (const file of files) {
|
|
|
|
assert(file.isFile);
|
|
|
|
assert(file.name.endsWith(".js") || file.name.endsWith(".css"));
|
|
|
|
await Deno.remove(join(output, file.name));
|
|
|
|
}
|
|
|
|
await Deno.remove(output);
|
|
|
|
});
|
|
|
|
|
|
|
|
await t.step("mod.write: use glob", async () => {
|
|
|
|
const output = ".daisyui";
|
|
|
|
const config: PickConfig = [
|
|
|
|
{
|
|
|
|
source: `${repo}@${version}`,
|
|
|
|
output,
|
|
|
|
pick: [
|
|
|
|
"**/base/*.css",
|
|
|
|
"src/index.js",
|
|
|
|
],
|
|
|
|
},
|
|
|
|
];
|
|
|
|
await mod.write(config);
|
|
|
|
const files = await Deno.readDir(output);
|
|
|
|
for await (const file of files) {
|
|
|
|
assert(file.isFile);
|
|
|
|
assert(file.name.endsWith(".js") || file.name.endsWith(".css"));
|
|
|
|
await Deno.remove(join(output, file.name));
|
|
|
|
}
|
|
|
|
await Deno.remove(output);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-02-11 11:19:00 +00:00
|
|
|
test("cmd line interface", async () => {
|
2023-02-11 11:13:48 +00:00
|
|
|
const p = await Deno.run({
|
|
|
|
cmd: [
|
|
|
|
"deno",
|
|
|
|
"run",
|
|
|
|
"-A",
|
|
|
|
"pickit.ts",
|
|
|
|
"saadeghi/daisyui@v2.47.0",
|
|
|
|
"daisyui",
|
|
|
|
"**/src/index.js",
|
|
|
|
"**/base/*.css",
|
|
|
|
],
|
|
|
|
});
|
|
|
|
const status = await p.status();
|
|
|
|
assert(status.success);
|
|
|
|
await Deno.remove("daisyui", { recursive: true });
|
2023-02-11 11:19:00 +00:00
|
|
|
await p.close();
|
2023-02-10 16:30:37 +00:00
|
|
|
});
|