Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support cjs and esm both by tshy #63

Merged
merged 10 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "eslint-config-egg"
"extends": [
"eslint-config-egg/typescript",
"eslint-config-egg/lib/rules/enforce-node-prefix"
]
}
24 changes: 0 additions & 24 deletions .github/PULL_REQUEST_TEMPLATE.md

This file was deleted.

4 changes: 3 additions & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ jobs:
name: Node.js
uses: node-modules/github-actions/.github/workflows/node-test.yml@master
with:
version: '16, 18, 20, 22'
version: '18.19.0, 18, 20, 22'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
23 changes: 23 additions & 0 deletions .github/workflows/pkg.pr.new.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Publish Any Commit
on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- run: corepack enable
- uses: actions/setup-node@v4
with:
node-version: 20

- name: Install dependencies
run: npm install

- name: Build
run: npm run prepublishOnly --if-present

- run: npx pkg-pr-new publish
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ test/fixtures/ts-pkg/app/controller/home.js
!test/fixtures/**/node_modules
package-lock.json
.package-lock.json
.tshy*
.eslintcache
dist
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
# egg-scripts
# @eggjs/scripts

[![NPM version][npm-image]][npm-url]
[![Node.js CI](https://github.com/eggjs/scripts/actions/workflows/nodejs.yml/badge.svg)](https://github.com/eggjs/scripts/actions/workflows/nodejs.yml)
[![Test coverage][codecov-image]][codecov-url]
[![npm download][download-image]][download-url]
[![Node.js Version](https://img.shields.io/node/v/@eggjs/scripts.svg?style=flat)](https://nodejs.org/en/download/)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://makeapullrequest.com)

[npm-image]: https://img.shields.io/npm/v/@eggjs/scripts.svg?style=flat-square
[npm-url]: https://npmjs.org/package/@eggjs/scripts
[codecov-image]: https://codecov.io/github/eggjs/scripts/coverage.svg?branch=master
[codecov-url]: https://codecov.io/github/eggjs/scripts?branch=master
[download-image]: https://img.shields.io/npm/dm/@eggjs/scripts.svg?style=flat-square
[download-url]: https://npmjs.org/package/@eggjs/scripts

deploy tool for egg project.

Expand All @@ -7,7 +21,7 @@ deploy tool for egg project.
## Install

```bash
$ npm i egg-scripts --save
npm i @eggjs/scripts --save
```

## Usage
Expand Down Expand Up @@ -38,6 +52,7 @@ Start egg at prod mode.

```bash
$ eggctl start [options] [baseDir]

# Usage
# eggctl start --port=7001
# eggctl start ./server
Expand Down Expand Up @@ -67,6 +82,7 @@ Stop egg gracefull.

```bash
$ eggctl stop [options]

# Usage
# eggctl stop --title=example
```
Expand All @@ -85,12 +101,13 @@ In addition to the command line specification, options can also be specified in
"port": 1234,
"ignore-stderr": true,
// will pass as `node --max-http-header-size=20000`
"node-options--max-http-header-size": "20000"
"node-options--max-http-header-size": "20000",
// will pass as `node --allow-wasi`
"node-options--allow-wasi": true
}
}
```


## Questions & Suggestions

Please open an issue [here](https://github.com/eggjs/egg/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc).
Expand All @@ -101,6 +118,6 @@ Please open an issue [here](https://github.com/eggjs/egg/issues?q=is%3Aissue+is%

## Contributors

[![Contributors](https://contrib.rocks/image?repo=eggjs/egg-scripts)](https://github.com/eggjs/egg-scripts/graphs/contributors)
[![Contributors](https://contrib.rocks/image?repo=eggjs/scripts)](https://github.com/eggjs/scripts/graphs/contributors)

Made with [contributors-img](https://contrib.rocks).
3 changes: 3 additions & 0 deletions bin/dev.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node --loader ts-node/esm --no-warnings=ExperimentalWarning "%~dp0\dev" %*
5 changes: 5 additions & 0 deletions bin/dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env -S node --loader ts-node/esm --disable-warning=ExperimentalWarning

import { execute } from '@oclif/core';

await execute({ development: true, dir: import.meta.url });
Comment on lines +3 to +5
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add error handling for the top-level await.

Currently, if an error occurs inside await execute(...), the process might terminate with an unhandled promise rejection, potentially obscuring error details. Consider wrapping the call in a try...catch block to handle errors gracefully or log them for troubleshooting:

 try {
   await execute({ development: true, dir: import.meta.url });
+} catch (err) {
+  console.error('Failed to execute dev script:', err);
+  process.exit(1);
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import { execute } from '@oclif/core';
await execute({ development: true, dir: import.meta.url });
import { execute } from '@oclif/core';
try {
await execute({ development: true, dir: import.meta.url });
} catch (err) {
console.error('Failed to execute dev script:', err);
process.exit(1);
}

7 changes: 0 additions & 7 deletions bin/egg-scripts.js

This file was deleted.

3 changes: 3 additions & 0 deletions bin/run.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\run" %*
5 changes: 5 additions & 0 deletions bin/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node

import { execute } from '@oclif/core';

await execute({ dir: import.meta.url });
19 changes: 0 additions & 19 deletions index.js

This file was deleted.

Loading
Loading