-
Notifications
You must be signed in to change notification settings - Fork 32
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
0 parents
commit 5bea130
Showing
12 changed files
with
8,204 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module.exports = { | ||
parser: "@typescript-eslint/parser", // Specifies the ESLint parser | ||
extends: [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/eslint-recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
"plugin:@typescript-eslint/recommended-requiring-type-checking", | ||
"plugin:jest/recommended", | ||
"plugin:jest/style", | ||
"plugin:import/errors", | ||
"plugin:import/warnings", | ||
"plugin:import/typescript", | ||
"prettier", | ||
"prettier/@typescript-eslint", | ||
], | ||
env: { | ||
node: true, | ||
browser: false, | ||
jest: true, | ||
}, | ||
plugins: ["@typescript-eslint", "prettier", "jest", "import"], | ||
parserOptions: { | ||
ecmaVersion: 2019, // Allows for the parsing of modern ECMAScript features | ||
sourceType: "module", // Allows for the use of imports | ||
project: "./tsconfig.json", | ||
impliedStrict: true, | ||
}, | ||
rules: { | ||
"prettier/prettier": "warn", | ||
"lines-between-class-members": [ | ||
"error", | ||
"always", | ||
{ exceptAfterSingleLine: true }, | ||
], | ||
"@typescript-eslint/explicit-function-return-type": "off", | ||
"jest/expect-expect": [ | ||
"error", | ||
{ | ||
assertFunctionNames: ["expect", "request.get.expect"], | ||
}, | ||
], | ||
}, | ||
} |
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 @@ | ||
node_modules | ||
coverage | ||
lib | ||
*.log | ||
.DS_Store | ||
.env |
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,9 @@ | ||
{ | ||
"semi": false, | ||
"singleQuote": false, | ||
"tabWidth": 2, | ||
"useTabs": false, | ||
"printWidth": 80, | ||
"trailingComma": "es5", | ||
"proseWrap": "always" | ||
} |
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,3 @@ | ||
# TODO | ||
|
||
- [ ] add https://github.com/klaussinani/signale |
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 @@ | ||
module.exports = { | ||
preset: "ts-jest", | ||
testEnvironment: "node", | ||
testPathIgnorePatterns: ["/lib/", "/node_modules/", "ignore.*"], | ||
coverageThreshold: { | ||
global: { | ||
branches: 100, | ||
functions: 100, | ||
lines: 100, | ||
statements: 100, | ||
}, | ||
}, | ||
} |
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,65 @@ | ||
{ | ||
"name": "ultra-runner", | ||
"version": "1.0.0", | ||
"main": "lib/runner.js", | ||
"repository": "http://github.com/folke/ultra-runner", | ||
"author": "Folke Lemaitre <[email protected]>", | ||
"license": "MIT", | ||
"scripts": { | ||
"generate:emoji": "npx ts-node --transpile-only src/scripts/updater.ts", | ||
"generate:config": "npx ts-interface-builder src/config-options.ts", | ||
"prebuild": "npx concurrently -c grey.dim,blue.dim yarn:clean yarn:generate* yarn:build:docs && yarn lint && npx jest", | ||
"build:docs": "npx copyfiles *.md ../../", | ||
"build:rollup": "npx rollup -c", | ||
"build": "yarn build:rollup", | ||
"clean": "npx rimraf lib coverage *.log", | ||
"test": "npx jest", | ||
"test:cov": "npx jest --coverage", | ||
"lint": "npx concurrently -c grey.dim,blue.dim yarn:lint:eslint yarn:lint:ts", | ||
"lint:eslint": "npx eslint bin/*.js src/*.ts", | ||
"lint:ts": "npx tsc -p tsconfig.build.json --noEmit", | ||
"lint:fix": "yarn lint:eslint --fix", | ||
"prepublishOnly": "yarn build", | ||
"release": "source .env && CI=true npx semantic-release" | ||
}, | ||
"devDependencies": { | ||
"@rollup/plugin-commonjs": "^11.0.1", | ||
"@rollup/plugin-json": "^4.0.1", | ||
"@rollup/plugin-node-resolve": "^7.0.0", | ||
"@rollup/plugin-typescript": "^2.1.0", | ||
"@semantic-release/changelog": "^3.0.6", | ||
"@semantic-release/git": "^8.0.0", | ||
"@types/jest": "^24.0.25", | ||
"@types/node": "^13.1.6", | ||
"@types/node-fetch": "^2.5.4", | ||
"@types/shell-quote": "^1.6.1", | ||
"@typescript-eslint/eslint-plugin": "^2.13.0", | ||
"@typescript-eslint/parser": "^2.13.0", | ||
"concurrently": "^5.0.2", | ||
"conventional-changelog-conventionalcommits": "^4.2.3", | ||
"copyfiles": "^2.1.1", | ||
"eslint": "^6.8.0", | ||
"eslint-config-prettier": "^6.9.0", | ||
"eslint-plugin-import": "^2.20.0", | ||
"eslint-plugin-jest": "^23.4.0", | ||
"eslint-plugin-prettier": "^3.1.2", | ||
"jest": "^24.9.0", | ||
"node-fetch": "^2.6.0", | ||
"prettier": "^1.19.1", | ||
"rimraf": "^3.0.0", | ||
"rollup": "^1.29.0", | ||
"rollup-plugin-progress": "^1.1.1", | ||
"rollup-plugin-sizes": "^1.0.1", | ||
"rollup-plugin-terser": "^5.2.0", | ||
"semantic-release": "^16.0.1", | ||
"ts-interface-builder": "^0.2.1", | ||
"ts-jest": "^24.3.0", | ||
"ts-node": "^8.6.1", | ||
"typescript": "^3.7.4" | ||
}, | ||
"dependencies": { | ||
"execa": "^4.0.0", | ||
"package-json": "^6.5.0", | ||
"shell-quote": "^1.7.2" | ||
} | ||
} |
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,41 @@ | ||
module.exports = { | ||
plugins: [ | ||
[ | ||
"@semantic-release/commit-analyzer", | ||
{ | ||
preset: "conventionalcommits", | ||
releaseRules: [ | ||
{ type: "docs", release: "patch" }, | ||
{ type: "perf", release: "patch" }, | ||
{ type: "style", release: "patch" }, | ||
], | ||
parserOpts: { | ||
noteKeywords: ["BREAKING CHANGE", "BREAKING CHANGES"], | ||
}, | ||
presetConfig: { | ||
types: [ | ||
{ type: "feat", section: "Features" }, | ||
{ type: "fix", section: "Bug Fixes" }, | ||
{ type: "chore", section: "Other" }, | ||
{ type: "docs", section: "Other" }, | ||
{ type: "style", section: "Other" }, | ||
{ type: "refactor", section: "Other" }, | ||
{ type: "perf", section: "Other" }, | ||
{ type: "test", section: "Other" }, | ||
{ type: "build", section: "Other" }, | ||
{ type: "ci", section: "Other" }, | ||
], | ||
}, | ||
}, | ||
], | ||
"@semantic-release/release-notes-generator", | ||
"@semantic-release/changelog", | ||
"@semantic-release/npm", | ||
[ | ||
"@semantic-release/git", | ||
{ | ||
assets: [["CHANGELOG.md", "package.json", "../../CHANGELOG.md"]], | ||
}, | ||
], | ||
], | ||
} |
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,40 @@ | ||
import typescript from "@rollup/plugin-typescript" | ||
import pkg from "./package.json" | ||
import resolve from "@rollup/plugin-node-resolve" | ||
import { terser } from "rollup-plugin-terser" | ||
import json from "@rollup/plugin-json" | ||
import commonjs from "@rollup/plugin-commonjs" | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore | ||
// @ts-ignore | ||
import progress from "rollup-plugin-progress" | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore | ||
// @ts-ignore | ||
import sizes from "rollup-plugin-sizes" | ||
// eslint-disable-next-line import/default | ||
import builtins from "builtin-modules" | ||
|
||
export default { | ||
input: "src/runner.ts", // our source file | ||
output: [ | ||
{ | ||
file: pkg.main, | ||
format: "cjs", | ||
}, | ||
], | ||
external: [...Object.keys(pkg.dependencies || {}), ...builtins], | ||
plugins: [ | ||
progress(), | ||
json(), | ||
resolve({ | ||
preferBuiltins: true, | ||
}), | ||
commonjs(), | ||
typescript({ | ||
tsconfig: "./tsconfig.build.json", | ||
module: "esnext", | ||
typescript: require("typescript"), | ||
}), | ||
terser(), | ||
sizes(), | ||
], | ||
} |
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,149 @@ | ||
import pkg from "../package.json" | ||
import { FullVersion } from "package-json" | ||
import { parse, ParseEntry, quote } from "shell-quote" | ||
import { existsSync } from "fs" | ||
import { resolve } from "path" | ||
|
||
import execa from "execa" | ||
|
||
class Runner { | ||
ops = [";", "||", "&&"] | ||
|
||
constructor(public pkg: FullVersion) { | ||
console.log(pkg.author) | ||
} | ||
|
||
isScript(name: string) { | ||
return this.pkg.scripts && name in this.pkg.scripts | ||
} | ||
|
||
isBin(name: string) { | ||
return existsSync(resolve("./node_modules/.bin/", name)) | ||
} | ||
|
||
getScript(name: string) { | ||
return this.pkg.scripts?.[name] | ||
} | ||
|
||
eat(args: ParseEntry[]) { | ||
for (let i = 0; i < args.length; i++) { | ||
const op = (args[i] as { op: string })?.op | ||
|
||
if (this.ops.includes(op)) { | ||
return [args.slice(0, i), args.slice(i)] | ||
} | ||
} | ||
return [args, []] | ||
} | ||
|
||
parse(cmd: ParseEntry[]) { | ||
const op = (cmd[0] as { op: string })?.op | ||
|
||
if (this.ops.includes(op)) { | ||
this.runOp(op) | ||
this.parse(cmd.slice(1)) | ||
} else if (cmd[0] == "yarn") { | ||
cmd = cmd.slice(1) | ||
if (cmd[0] == "run") cmd = cmd.slice(1) | ||
const [args, other] = this.eat(cmd) | ||
this.runYarn(args) | ||
if (other.length) this.parse(other) | ||
} else if (cmd[0] == "npx") { | ||
cmd = cmd.slice(1) | ||
const [args, other] = this.eat(cmd) | ||
this.runNpx(args) | ||
if (other.length) this.parse(other) | ||
} else if (cmd[0] == "npm" && cmd[1] == "run") { | ||
cmd = cmd.slice(2) | ||
const [args, other] = this.eat(cmd) | ||
this.runNpm(args) | ||
if (other.length) this.parse(other) | ||
} else if (this.isBin(cmd[0] as string)) { | ||
const [args, other] = this.eat(cmd) | ||
this.runBin(args) | ||
if (other.length) this.parse(other) | ||
} else { | ||
const [args, other] = this.eat(cmd) | ||
this.runSystem(args) | ||
if (other.length) this.parse(other) | ||
} | ||
} | ||
|
||
runOp(op: string) { | ||
console.log(`[${op}]`) | ||
} | ||
|
||
runNpm(args: ParseEntry[]) { | ||
console.log(`[npm-script] ${args[0]}`, args) | ||
this.run(args[0] as string, args.slice(1)) | ||
} | ||
|
||
runNpx(args: ParseEntry[]) { | ||
console.log(`[npx] `, args) | ||
if (this.isBin(args[0] as string)) { | ||
this.runBin(args) | ||
} | ||
} | ||
|
||
runYarn(args: ParseEntry[]) { | ||
console.log(`[yarn] ${args[0]}`, args) | ||
this.run(args[0] as string, args.slice(1)) | ||
} | ||
|
||
async runSystem(args: ParseEntry[]) { | ||
console.log(`[system] `, this.quote(args).join(" ")) | ||
const cmd = this.quote(args) | ||
await this.exec(cmd) | ||
} | ||
|
||
async runBin(args: ParseEntry[]) { | ||
console.log(`[bin] `, this.quote(args).join(" ")) | ||
const cmd = this.quote(args) | ||
await this.exec(cmd) | ||
} | ||
|
||
async exec(args: string[]) { | ||
const e = execa(args[0], args.slice(1)) | ||
e.stdout?.pipe(process.stdout) | ||
return e | ||
} | ||
|
||
quote(args: ParseEntry[]) { | ||
const ret = [] | ||
for (const arg of args) { | ||
const op = (arg as any)?.op | ||
if (op) { | ||
if (op == "glob") { | ||
ret.push((arg as any).pattern) | ||
} | ||
} else { | ||
const a = arg as string | ||
ret.push(a.includes(" ") ? quote([a]) : a) | ||
} | ||
} | ||
return ret | ||
} | ||
|
||
run(name: string, args: ParseEntry[] = []) { | ||
console.log(`[run] ${name}`, args) | ||
if (this.isScript(name)) { | ||
if (this.isScript(`pre${name}`)) { | ||
this.run(`pre${name}`) | ||
} | ||
const script = this.getScript(name) as string | ||
this.parse(parse(script).concat(args)) | ||
} else { | ||
this.parse([name, ...args]) | ||
} | ||
} | ||
} | ||
|
||
const runner = new Runner(pkg as any) | ||
|
||
// console.log(runner.run("build")) | ||
// console.log(runner.run("lint:fix")) | ||
console.log(runner.run("lint")) | ||
// console.log(runner.isBin("ts-node")) | ||
// console.log(data) | ||
|
||
console.log("122") |
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,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"noEmit": false, | ||
"outDir": "lib", | ||
"rootDir": "src", | ||
"skipLibCheck": false | ||
}, | ||
"extends": "./tsconfig.json", | ||
"include": ["src/**/*.ts"], | ||
"exclude": ["node_modules", "lib"] | ||
} |
Oops, something went wrong.