Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

Commit

Permalink
add fetch lates script
Browse files Browse the repository at this point in the history
  • Loading branch information
kamiazya committed May 30, 2020
1 parent 805346a commit 73bc0b5
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 10 deletions.
20 changes: 10 additions & 10 deletions .auto_generated → .denolized
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
attribute.ts
mod.ts
model/abstract.ts
model/attributes_base.ts
model/clusters.ts
model/edges.ts
model/nodes.ts
model/root_clusters.ts
render/renderer.ts
usecase.ts
render/to_dot.ts
render/utils.ts
render/renderer.ts
types.ts
usecase.ts
model/nodes.ts
model/edges.ts
model/root_clusters.ts
model/clusters.ts
model/attributes_base.ts
model/abstract.ts
mod.ts
attribute.ts
4 changes: 4 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true


[Makefile]
indent_style = tab
15 changes: 15 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.PHONY: fmt test doc fetch_latest

fmt:
@deno fmt

test:
@deno test --unstable

doc:
@deno doc ./mod.ts

fetch_latest:
@deno run --unstable --allow-run --allow-read --allow-write scripts/fetch_latest.ts
@deno fmt
@deno fmt
61 changes: 61 additions & 0 deletions scripts/fetch_latest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import * as path from "https://deno.land/std/path/mod.ts";
import { denolize } from "https://raw.githubusercontent.com/kamiazya/denolize/master/mod.ts";

const encoder = new TextEncoder();
const decoder = new TextDecoder();

const repository = "[email protected]:ts-graphviz/ts-graphviz.git";
const repositorySrcDir = "src";
const outDir = ".";
const denolizedFilePath = `${outDir}/.denolized`;

const workDir = await Deno.makeTempDir({
prefix: "tsgraphviz",
});
const rootDir = path.join(workDir, repositorySrcDir);

async function readDenolizedFiles() {
const files = await Deno.readFile(denolizedFilePath).then((buf) =>
decoder.decode(buf).split("\n")
);
return files;
}

async function writeDenolizedFiles(files: string[]) {
await Deno.writeFile(denolizedFilePath, encoder.encode(files.join("\n")));
}

try {
const denolizedFiles = await readDenolizedFiles();
for (const denolizedFile of denolizedFiles) {
const info = await Deno.stat(denolizedFile);
if (info.isFile) {
await Deno.remove(denolizedFile);
}
}

console.log("Clone start ts-graphviz/ts-graphviz");
const ps = Deno.run({
cmd: ["git", "clone", repository, workDir],
});
const status = await ps.status();
if (status.success) {
console.log("Clone Succeeded!");
const files = [];
for await (const source of denolize(rootDir)) {
const outputPath = path.join(
outDir,
path.relative(rootDir, source.fileName),
);
await Deno.mkdir(path.dirname(outputPath), { recursive: true });
await Deno.writeFile(outputPath, encoder.encode(source.text));

const resolvedOutputPath = path.relative(outDir, outputPath);
files.push(resolvedOutputPath);
console.log(`WRITE ${resolvedOutputPath}`);
}
await writeDenolizedFiles(files);
}
} finally {
await Deno.remove(workDir, { recursive: true });
}

0 comments on commit 73bc0b5

Please sign in to comment.