Browse Source

Add doc sections and run tool for deno permission flags

set_equality 1.3.0
Michaël Lemaire 3 months ago
parent
commit
1c43b03740
  1. 32
      README.md
  2. 2
      cli.ts
  3. 1
      config/run.flags
  4. 7
      doc/about.md
  5. 2
      doc/index
  6. 23
      doc/usage.md
  7. 59
      normalize.ts
  8. 19
      run

32
README.md

@ -1,3 +1,35 @@
# typescript/devtools
[![Build Status](https://thunderk.visualstudio.com/typescript/_apis/build/status/devtools?branchName=master)](https://dev.azure.com/thunderk/typescript/_build?pipelineNameFilter=devtools)
## About
Normalizing dev tools for other projects in
https://code.thunderk.net/typescript/
**Be aware that running this tool will modify your project to use tools specific
to _code.thunderk.net_**
## Usage
### Normalize the project
```shell
deno run --allow-run --allow-read --allow-write https://code.thunderk.net/typescript/devtools/raw/master/normalize.ts
```
### Use test tools
```typescript
import {
describe,
expect,
it,
} from "https://code.thunderk.net/typescript/devtools/raw/master/testing.ts";
describe("test", () => {
it("checks something", () => {
expect(2 + 3).toEqual(5);
});
});
```

2
cli.ts

@ -1,4 +1,4 @@
#!/usr/bin/env -S deno run --allow-run --allow-read --allow-write
#!./run
import { normalize } from "./normalize.ts";
import { Sys } from "./system.ts";

1
config/run.flags

@ -0,0 +1 @@
--allow-run --allow-read --allow-write

7
doc/about.md

@ -0,0 +1,7 @@
## About
Normalizing dev tools for other projects in
https://code.thunderk.net/typescript/
**Be aware that running this tool will modify your project to use tools specific
to _code.thunderk.net_**

2
doc/index

@ -0,0 +1,2 @@
about
usage

23
doc/usage.md

@ -0,0 +1,23 @@
## Usage
### Normalize the project
```shell
deno run --allow-run --allow-read --allow-write https://code.thunderk.net/typescript/devtools/raw/master/normalize.ts
```
### Use test tools
```typescript
import {
describe,
expect,
it,
} from "https://code.thunderk.net/typescript/devtools/raw/master/testing.ts";
describe("test", () => {
it("checks something", () => {
expect(2 + 3).toEqual(5);
});
});
```

59
normalize.ts

@ -1,4 +1,4 @@
#!/usr/bin/env -S deno run --allow-run --allow-read --allow-write
#!./run
import { Sys } from "./system.ts";
/**
@ -27,9 +27,36 @@ async function ensureDirectory(path: string) {
}
}
async function updateRunScript() {
await 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
`,
);
await Sys.chmod("run", 0o755);
}
async function updateDenoDefs() {
const process = await Sys.run({
cmd: ["deno", "types"],
const process = Sys.run({
cmd: ["./run", "types"],
stdout: "piped",
});
const defs = new TextDecoder("utf-8").decode(await process.output());
@ -78,9 +105,8 @@ async function updateVscodeConf() {
config["deno.enable"] = true;
await Sys.writeTextFile(path, JSON.stringify(config));
await Sys.run({
cmd: ["deno", "fmt", path],
stdout: "piped",
});
cmd: ["./run", "fmt", "-q", path],
}).status();
}
await Sys.writeTextFile(
@ -95,7 +121,7 @@ async function updateVscodeConf() {
"kind": "test",
"isDefault": true
},
"command": "deno test"
"command": "./run test"
}
]
}
@ -118,8 +144,8 @@ async function updateGitHooks() {
".git/hooks/pre-commit",
`#!/bin/sh
set -e
deno fmt --check
deno test
./run fmt --check
./run test
`,
);
await Sys.chmod(".git/hooks/pre-commit", 0o755);
@ -127,13 +153,25 @@ deno test
async function updateReadme() {
const project = Sys.cwd().split("/").pop();
let sections = "";
if (await isDirectory("doc")) {
const index = await readContent("doc/index");
for (let section of index.split("\n")) {
if (section?.trim()) {
sections += "\n" + (await readContent(`doc/${section.trim()}.md`));
}
}
}
await 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}`,
);
await Sys.run({
cmd: ["./run", "fmt", "-q", "README.md"],
}).status();
}
export async function normalize() {
@ -141,6 +179,7 @@ export async function normalize() {
throw new Error("Not in a git repository");
}
await updateRunScript();
await updateDenoDefs();
await updateVscodeConf();
await updateTsConfig();

19
run

@ -0,0 +1,19 @@
#!/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
Loading…
Cancel
Save