Compare commits

..

No commits in common. "master" and "db68faf338fe977469a5326aedfc1487f52fc0db" have entirely different histories.

11 changed files with 118 additions and 149 deletions

View file

@ -1,9 +1,10 @@
root = true
[*.{ts,json}]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
[*.{ts,json}]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true

7
.gitignore vendored
View file

@ -1,5 +1,4 @@
deno.d.ts
.vscode
.local
.output
web/*.js
.vscode
.local

22
.vscode/launch.json vendored Normal file
View file

@ -0,0 +1,22 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Deno",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}",
"program": "cli.ts",
"console": "externalTerminal",
"attachSimplePort": 9229,
"runtimeExecutable": "deno",
"runtimeArgs": [
"run",
"--inspect",
"--allow-run=./run",
"--allow-read=.",
"--allow-write=."
]
}
]
}

1
.vscode/settings.json vendored Normal file
View file

@ -0,0 +1 @@
{ "deno.enable": true }

11
.vscode/tasks.json vendored Normal file
View file

@ -0,0 +1,11 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "test",
"type": "shell",
"group": { "kind": "test", "isDefault": true },
"command": "./run test"
}
]
}

View file

@ -1,10 +1,3 @@
# typescript/scaffold
[![Build Status](https://thunderk.visualstudio.com/typescript/_apis/build/status/scaffold?branchName=master)](https://dev.azure.com/thunderk/typescript/_build?pipelineNameFilter=scaffold)
## About
Scaffolding for other typescript projects.
**Be aware that running this tool will modify your project to use tools specific
to _code.thunderk.net_**

View file

@ -1,6 +0,0 @@
export {
describe,
expect,
it,
mockfn,
} from "https://js.thunderk.net/testing@1.0.0/mod.ts";

View file

@ -1 +0,0 @@
about

33
run
View file

@ -1,19 +1,20 @@
#!/bin/sh
# Simplified run tool for deno commands
# Simplified run tool for deno commands
if test $# -eq 0
then
echo "Usage: $0 [file or command]"
exit 1
elif echo $1 | grep -q '.*.ts'
then
denocmd=run
denoargs=$1
shift
else
denocmd=$1
shift
fi
if test $# -eq 0
then
echo "Usage: $0 [file or command]"
exit 1
elif echo $1 | grep -q '.*.ts'
then
denocmd=run
denoargs=$1
shift
else
denocmd=$1
shift
fi
denoargs="$(cat config/$denocmd.flags 2> /dev/null) $denoargs $@"
exec deno $denocmd $denoargs
denoargs="$(cat config/$denocmd.flags 2> /dev/null) $denoargs $@"
exec deno $denocmd $denoargs

View file

@ -1,28 +0,0 @@
import { ProjectNormalizer } from "./normalize.ts";
import { describe, expect, it, mockfn } from "../deps.testing.ts";
describe(ProjectNormalizer, () => {
it("uses 'deno fmt' to format path", async () => {
const sys = {
run: mockfn(() => ({
async status() {
return { success: true };
},
async output() {
return new TextEncoder().encode("");
},
async stderrOutput() {
return new TextEncoder().encode("");
},
})),
} as typeof Deno;
const normalizer = new ProjectNormalizer(sys);
await normalizer.formatPath("dist/test.js");
expect(sys.run).toHaveBeenCalledTimes(1);
expect(sys.run).toHaveBeenCalledWith({
cmd: ["./run", "fmt", "-q", "dist/test.js"],
stdout: "piped",
stderr: "piped",
});
});
});

View file

@ -42,79 +42,61 @@ export class ProjectNormalizer {
await this.formatPath(path);
}
async writeLines(path: string, lines: string[]) {
await this.sys.writeTextFile(
path,
lines.concat("").join("\n"),
);
}
async run(...cmd: string[]): Promise<string> {
const p = this.sys.run({ cmd, stdout: "piped", stderr: "piped" });
const [status, stdout, stderr] = await Promise.all([
p.status(),
p.output(),
p.stderrOutput(),
]);
if (status.success) {
return new TextDecoder().decode(stdout);
} else {
console.error(new TextDecoder().decode(stderr));
throw new Error(`Command failed: ${cmd.join(" ")}`);
}
}
async formatPath(path: string) {
await this.run("./run", "fmt", "-q", path);
await this.sys.run({
cmd: ["./run", "fmt", "-q", path],
}).status();
}
async updateRunScript() {
await this.writeLines(
await this.sys.writeTextFile(
"run",
[
`#!/bin/sh`,
`# Simplified run tool for deno commands`,
``,
`if test $# -eq 0`,
`then`,
` echo "Usage: $0 [file or command]"`,
` exit 1`,
`elif echo $1 | grep -q '.*\.ts'`,
`then`,
` denocmd=run`,
` denoargs=$1`,
` shift`,
`else`,
` denocmd=$1`,
` shift`,
`fi`,
``,
`denoargs="$(cat config/$denocmd.flags 2> /dev/null) $denoargs $@"`,
`exec deno $denocmd $denoargs`,
],
`#!/bin/sh
# Simplified run tool for deno commands
if test $# -eq 0
then
echo "Usage: $0 [file or command]"
exit 1
elif echo $1 | grep -q '.*\.ts'
then
denocmd=run
denoargs=$1
shift
else
denocmd=$1
shift
fi
denoargs="$(cat config/$denocmd.flags 2> /dev/null) $denoargs $@"
exec deno $denocmd $denoargs
`,
);
await this.sys.chmod("run", 0o755);
}
async updateDenoDefs() {
const defs = await this.run("./run", "types");
const process = this.sys.run({
cmd: ["./run", "types"],
stdout: "piped",
});
const defs = new TextDecoder("utf-8").decode(await process.output());
await this.sys.writeTextFile("deno.d.ts", defs);
}
async updateEditorConfig() {
await this.writeLines(
await this.sys.writeTextFile(
".editorconfig",
[
`root = true`,
``,
`[*.{ts,json}]`,
`charset = utf-8`,
`end_of_line = lf`,
`insert_final_newline = true`,
`indent_style = space`,
`indent_size = 2`,
`trim_trailing_whitespace = true`,
],
`root = true
[*.{ts,json}]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
`,
);
}
@ -174,7 +156,6 @@ export class ProjectNormalizer {
"--inspect",
].concat(
(await this.readContent("config/run.flags"))
.trim()
.split(" ")
.filter((part) => !!part),
),
@ -185,27 +166,23 @@ export class ProjectNormalizer {
}
async updateGitIgnore() {
await this.writeLines(
await this.sys.writeTextFile(
".gitignore",
[
`deno.d.ts`,
`.vscode`,
`.local`,
`.output`,
`web/*.js`,
],
`deno.d.ts
.vscode
.local
`,
);
}
async updateGitHooks() {
await this.writeLines(
await this.sys.writeTextFile(
".git/hooks/pre-commit",
[
`#!/bin/sh`,
`set -e`,
`./run fmt --check`,
`./run test`,
],
`#!/bin/sh
set -e
./run fmt --check
./run test
`,
);
await this.sys.chmod(".git/hooks/pre-commit", 0o755);
}
@ -222,13 +199,12 @@ export class ProjectNormalizer {
}
}
}
await this.writeLines(
await this.sys.writeTextFile(
"README.md",
[
`# typescript/${project}`,
`[![Build Status](https://thunderk.visualstudio.com/typescript/_apis/build/status/${project}?branchName=master)](https://dev.azure.com/thunderk/typescript/_build?pipelineNameFilter=${project})`,
sections,
],
`# typescript/${project}
[![Build Status](https://thunderk.visualstudio.com/typescript/_apis/build/status/${project}?branchName=master)](https://dev.azure.com/thunderk/typescript/_build?pipelineNameFilter=${project})
${sections}`,
);
await this.formatPath("README.md");
}