-
Notifications
You must be signed in to change notification settings - Fork 715
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
25 changed files
with
232 additions
and
21 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
}, | ||
{ | ||
"files": [ | ||
"tools/**/*.ts", | ||
"packages/**/*.ts" | ||
], | ||
"extends": [ | ||
|
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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 @@ | ||
{ | ||
"extends": [ | ||
"@trigen/eslint-config/typescript", | ||
"@trigen/eslint-config/typescript-requiring-type-checking" | ||
], | ||
"parserOptions": { | ||
"tsconfigRootDir": "./tools", | ||
"project": ["./tsconfig.json"] | ||
}, | ||
"rules": { | ||
"@typescript-eslint/no-magic-numbers": "off" | ||
} | ||
} |
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,191 @@ | ||
import { execSync, spawn } from 'child_process' | ||
import { Transform } from 'stream' | ||
import { pathToFileURL } from 'url' | ||
import path from 'path' | ||
import fs from 'fs' | ||
// @ts-expect-error 'tmp' has no types | ||
import tmp from 'tmp' | ||
|
||
export function delay(ms: number) { | ||
return new Promise(resolve => setTimeout(resolve, ms)) | ||
} | ||
|
||
function fixMessage(message?: string) { | ||
let msg = message | ||
|
||
if (!msg || typeof msg !== 'string') { | ||
msg = 'Test commit' | ||
} | ||
|
||
// we need to escape backtick for bash but not for windows | ||
// probably this should be done in git-dummy-commit or shelljs | ||
if (process.platform !== 'win32') { | ||
msg = msg.replace(/`/g, '\\`') | ||
} | ||
|
||
return `"${msg}"` | ||
} | ||
|
||
function prepareMessageArgs(msg: string | string[]) { | ||
const args = [] | ||
|
||
if (Array.isArray(msg)) { | ||
if (msg.length > 0) { | ||
for (const m of msg) { | ||
args.push('-m', fixMessage(m)) | ||
} | ||
} else { | ||
args.push('-m', fixMessage()) | ||
} | ||
} else { | ||
args.push('-m', fixMessage(msg)) | ||
} | ||
|
||
return args | ||
} | ||
|
||
export function through( | ||
transform = ( | ||
chunk: string | Buffer, | ||
_enc: string, | ||
cb: (err: Error | null, chunk: string | Buffer) => void | ||
) => cb(null, chunk), | ||
flush?: () => void | ||
) { | ||
return new Transform({ | ||
transform, | ||
flush | ||
}) | ||
} | ||
|
||
export function throughObj( | ||
transform = ( | ||
chunk: string | Buffer, | ||
_enc: string, | ||
cb: (err: Error | null, chunk: string | Buffer) => void | ||
) => cb(null, chunk), | ||
flush?: () => void | ||
) { | ||
return new Transform({ | ||
objectMode: true, | ||
highWaterMark: 16, | ||
transform, | ||
flush | ||
}) | ||
} | ||
|
||
export class TestTools { | ||
cwd: string | ||
|
||
constructor(cwd: string) { | ||
this.cwd = cwd | ||
|
||
if (!cwd) { | ||
/* eslint-disable */ | ||
this.cwd = fs.realpathSync(tmp.dirSync().name) | ||
tmp.setGracefulCleanup() | ||
/* eslint-enable */ | ||
} | ||
} | ||
|
||
cleanup() { | ||
try { | ||
this.rmSync(this.cwd, { | ||
recursive: true | ||
}) | ||
} catch (err) { | ||
// ignore | ||
} | ||
} | ||
|
||
mkdirSync(dir: string, options?: Parameters<typeof fs.mkdirSync>[1]) { | ||
return fs.mkdirSync(path.resolve(this.cwd, dir), options) | ||
} | ||
|
||
writeFileSync(file: string, content: string) { | ||
return fs.writeFileSync(path.resolve(this.cwd, file), content) | ||
} | ||
|
||
readFileSync(file: string, options: Parameters<typeof fs.readFileSync>[1]) { | ||
return fs.readFileSync(path.resolve(this.cwd, file), options) | ||
} | ||
|
||
rmSync(target: string, options?: Parameters<typeof fs.rmSync>[1]) { | ||
return fs.rmSync(path.resolve(this.cwd, target), options) | ||
} | ||
|
||
exec(command: string) { | ||
return execSync(command, { | ||
cwd: this.cwd, | ||
stdio: 'pipe', | ||
encoding: 'utf-8' | ||
}) | ||
} | ||
|
||
fork(script: string, args: string[] = [], options: Parameters<typeof spawn>[2] = {}) { | ||
return new Promise<{stdout: string, stderr: string, exitCode: number | null}>((resolve, reject) => { | ||
const finalOptions = { | ||
cwd: this.cwd, | ||
stdio: [ | ||
null, | ||
null, | ||
null | ||
], | ||
...options | ||
} | ||
const nodeArgs = [ | ||
'--no-warnings', | ||
'--loader', | ||
pathToFileURL(path.resolve(__dirname, '..', 'node_modules', 'tsm', 'loader.mjs')).toString() | ||
] | ||
const child = spawn(process.execPath, [ | ||
...nodeArgs, | ||
script, | ||
...args | ||
], finalOptions) | ||
let stdout = '' | ||
let stderr = '' | ||
let exitCode = null | ||
|
||
child.stdout?.on('data', (data: Buffer) => { | ||
stdout += data.toString() | ||
}) | ||
child.stderr?.on('data', (data: Buffer) => { | ||
stderr += data.toString() | ||
}) | ||
child.on('close', (code) => { | ||
exitCode = code | ||
resolve({ | ||
stdout, | ||
stderr, | ||
exitCode | ||
}) | ||
}) | ||
child.on('error', reject) | ||
}) | ||
} | ||
|
||
gitInit() { | ||
this.mkdirSync('git-templates') | ||
return this.exec('git init --template=./git-templates --initial-branch=master') | ||
} | ||
|
||
gitDummyCommit(msg: string | string[]) { | ||
const args = prepareMessageArgs(msg) | ||
|
||
args.push( | ||
'--allow-empty', | ||
'--no-gpg-sign' | ||
) | ||
|
||
return this.exec(`git commit ${args.join(' ')}`) | ||
} | ||
|
||
gitTails() { | ||
const data = execSync('git rev-list --parents HEAD', { | ||
cwd: this.cwd | ||
}) | ||
|
||
return data.toString().match(/^[a-f0-9]{40}$/gm) | ||
} | ||
} |
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,6 @@ | ||
{ | ||
"extends": "../tsconfig.json", | ||
"include": [ | ||
"." | ||
] | ||
} |