Skip to content

Commit

Permalink
ci: check conversion check and moderate package.json npm scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
LumaKernel committed Mar 6, 2021
1 parent 36fe5e1 commit 8c60002
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
restore-keys: |
${{ runner.os }}-yarn-
- run: yarn install --frozen-lockfile
- run: yarn ts-node-run ./scripts/md-to-package-json.ts --exit-code
- run: yarn lint
- run: yarn typecheck
- run: yarn coverage
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
"author": "Luma",
"main": "./out/coc.js",
"scripts": {
"build": "ts-node -r tsconfig-paths/register -T ./scripts/build.ts",
"build": "yarn ts-node-run ./scripts/build.ts",
"coverage": "jest --coverage",
"dev": "onchange -i \"**/*.ts\" \"tsconfig*.json\" -- yarn build",
"fix": "yarn lint --fix",
"lint": "eslint --ext .js,.ts,.json .",
"test": "jest",
"typecheck": "tsc --noEmit",
"dev": "onchange -i \"**/*.ts\" \"tsconfig*.json\" -- yarn build"
"ts-node-run": "ts-node -r tsconfig-paths/register -T",
"typecheck": "tsc --noEmit"
},
"activationEvents": [
"onLanguage:typescript",
Expand Down
27 changes: 21 additions & 6 deletions scripts/md-to-package-json.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import path from "path";
import fs from "fs";
import { execFileSync } from "child_process";
import equal from "deep-equal";
import { parseReadmeMd } from "../src/utils/readme";
import { applyOptionDeclarations } from "../src/utils/package-json";

const exitCode = process.argv.slice(1).includes("--exit-code");
if (exitCode) {
console.info("Exit code mode is on.");
}

const readmeMdPath = path.resolve(__dirname, "../README.md");
const packageJsonPath = path.resolve(__dirname, "../package.json");

Expand All @@ -17,9 +23,18 @@ const appliedJson = applyOptionDeclarations(
packageJsonContent as any,
parseReadme,
);
fs.writeFileSync(
packageJsonPath,
JSON.stringify(appliedJson as any, null, " "),
);

execFileSync("yarn", ["fix", "./package.json"]);
//
if (exitCode) {
if (!equal(appliedJson, packageJsonContent)) {
console.error("md-to-package-json.ts is not applied.");
process.exit(1);
}
} else {
fs.writeFileSync(
packageJsonPath,
JSON.stringify(appliedJson as any, null, " "),
);
execFileSync("yarn", ["eslint", "--fix", packageJsonPath], {
stdio: "inherit",
});
}

0 comments on commit 8c60002

Please sign in to comment.