Skip to content

Commit

Permalink
ci: drop zx in favor of simple Node script
Browse files Browse the repository at this point in the history
  • Loading branch information
motss committed Feb 4, 2022
1 parent 518091c commit e932524
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 15 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@
"build": "npm run clean && npm run ts",
"check": "package-check",
"clean": "rm -rf .*cache *.log .swc/ coverage/ dist/ logs/",
"postinstall": "npm x -y --prefer-online -- zx@latest ./postinstall.mjs",
"postinstall": "node postinstall.mjs",
"lint": "eslint src --ext .js,.ts",
"lint:commit": "npm x -y --prefer-online -- commitlint@latest --edit",
"lint:build": "npm run lint -- --config .build.eslintrc.json",
"lint:commit": "npm x -y -- commitlint@latest --edit",
"pre-commit": "package-check && nano-staged && tsc --noEmit",
"prepublishOnly": "package-check && npm run lint:build && npm run build",
"test": "c8 --reporter=lcov --exclude=src/tests uvu -r @swc/register src/tests",
"ts": "tsc",
"watch": "tsc --watch"
},
"simple-git-hooks": {
"commit-msg": "npm run lint:commit",
"pre-commit": "npm run pre-commit"
"pre-commit": "npm run pre-commit",
"commit-msg": "npm run lint:commit"
},
"commitlint": {
"extends": [
Expand Down
48 changes: 37 additions & 11 deletions postinstall.mjs
Original file line number Diff line number Diff line change
@@ -1,18 +1,44 @@
#!/usr/bin/env zx
#!/usr/bin/env node

const {
CI,
INIT_CWD,
} = process.env;
import { spawn } from 'node:child_process'
import { readFile } from 'node:fs/promises';

const {
name: moduleName,
} = JSON.parse(await fs.readFile('./package.json', { encoding: 'utf-8' }));
CI = false,
INIT_CWD = '',
} = process.env;

if (
CI != 'true' &&
!INIT_CWD.endsWith(`node_modules/${moduleName}`) &&
INIT_CWD.endsWith(moduleName)
CI !== 'true'
) {
await $`simple-git-hooks && npm dedupe`;
const {
name: moduleName,
} = JSON.parse(await readFile('./package.json', { encoding: 'utf-8' }));

if (
!INIT_CWD.endsWith(`node_modules/${moduleName}`) &&
INIT_CWD.endsWith(moduleName)
) {
const cmd = 'simple-git-hooks && npm dedupe';

process.stdout.write(cmd);
process.stdout.write('\n\n');

const postinstall = spawn(
cmd,
[],
{
shell: true,
windowsHide: true,
}
);

postinstall.stdout.on('data', (data) => {
process.stdout.write(data);
});

postinstall.stderr.on('data', (data) => {
process.stderr.write(data);
});
}
}

0 comments on commit e932524

Please sign in to comment.