mirror of
https://github.com/sern-handler/cli
synced 2026-06-06 09:26:52 +00:00
Compare commits
32 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
70886c28f0 | ||
|
|
53ca446a38 | ||
|
|
dac05ab7ce | ||
|
|
2bb169f600 | ||
|
|
89302d62c4 | ||
|
|
a63192ab10 | ||
|
|
20364fa20d | ||
|
|
d581142f08 | ||
|
|
fe2e8ff0c0 | ||
|
|
41046ebd37 | ||
|
|
fc5e974f9b | ||
|
|
5fbb15f385 | ||
|
|
c90003e411 | ||
|
|
d94d5de520 | ||
|
|
44e5dd3845 | ||
|
|
9f9a2aaca7 | ||
|
|
d1832e44ce | ||
|
|
e55ceedadd | ||
|
|
6bb212a3be | ||
|
|
2d6e65a1e6 | ||
|
|
eb53ecb638 | ||
|
|
303ac0280c | ||
|
|
3f994d6948 | ||
|
|
a5cb66828e | ||
|
|
667d0c1b89 | ||
|
|
5dbf2a87dc | ||
| a309c085e9 | |||
| f1d7d6c911 | |||
|
|
4ec96dbe17 | ||
|
|
3970cc6911 | ||
|
|
9045e1a03f | ||
|
|
d9ca5ff3ff |
2
.github/workflows/auto-deprecate.yml
vendored
2
.github/workflows/auto-deprecate.yml
vendored
@@ -15,7 +15,7 @@ jobs:
|
||||
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3
|
||||
|
||||
- name: Use Node.js
|
||||
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3
|
||||
uses: actions/setup-node@1a4442cacd436585916779262731d5b162bc6ec7 # v3
|
||||
with:
|
||||
node-version: 17
|
||||
registry-url: 'https://registry.npmjs.org/'
|
||||
|
||||
2
.github/workflows/continuous-delivery.yml
vendored
2
.github/workflows/continuous-delivery.yml
vendored
@@ -18,7 +18,7 @@ jobs:
|
||||
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3
|
||||
uses: actions/setup-node@1a4442cacd436585916779262731d5b162bc6ec7 # v3
|
||||
with:
|
||||
node-version: 17
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
|
||||
30
.github/workflows/continuous-integration.yml
vendored
30
.github/workflows/continuous-integration.yml
vendored
@@ -11,25 +11,25 @@ on:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
Lint:
|
||||
name: Linting
|
||||
runs-on: ubuntu-latest
|
||||
# Lint:
|
||||
# name: Linting
|
||||
# runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Check out Git repository
|
||||
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3
|
||||
# steps:
|
||||
# - name: Check out Git repository
|
||||
# uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3
|
||||
with:
|
||||
node-version: 17
|
||||
# - name: Set up Node.js
|
||||
# uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3
|
||||
# with:
|
||||
# node-version: 17
|
||||
|
||||
# Prettier must be in `package.json`
|
||||
- name: Install Node.js dependencies
|
||||
run: npm i
|
||||
# - name: Install Node.js dependencies
|
||||
# run: npm i
|
||||
|
||||
- name: Run Prettier
|
||||
run: npm run format
|
||||
# - name: Run Prettier
|
||||
# run: npm run format
|
||||
|
||||
Test:
|
||||
name: Testing
|
||||
@@ -40,7 +40,7 @@ jobs:
|
||||
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3
|
||||
uses: actions/setup-node@1a4442cacd436585916779262731d5b162bc6ec7 # v3
|
||||
with:
|
||||
node-version: 17
|
||||
|
||||
|
||||
2
.github/workflows/publish.yml
vendored
2
.github/workflows/publish.yml
vendored
@@ -17,7 +17,7 @@ jobs:
|
||||
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3
|
||||
|
||||
- name: Set up Node.js
|
||||
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3
|
||||
uses: actions/setup-node@1a4442cacd436585916779262731d5b162bc6ec7 # v3
|
||||
with:
|
||||
node-version: 17
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
|
||||
2
.github/workflows/release-please.yml
vendored
2
.github/workflows/release-please.yml
vendored
@@ -14,7 +14,7 @@ jobs:
|
||||
bump-patch-for-minor-pre-major: true
|
||||
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3
|
||||
if: ${{ steps.release.outputs.release_created }}
|
||||
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3
|
||||
- uses: actions/setup-node@1a4442cacd436585916779262731d5b162bc6ec7 # v3
|
||||
with:
|
||||
node-version: 17
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
|
||||
69
CHANGELOG.md
69
CHANGELOG.md
@@ -2,6 +2,75 @@
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [1.3.2](https://github.com/sern-handler/cli/compare/v1.3.1...v1.3.2) (2024-07-31)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* make tsconfig work with comments/trailing commas ([#142](https://github.com/sern-handler/cli/issues/142)) ([53ca446](https://github.com/sern-handler/cli/commit/53ca446a38076ed7b165dbbb41f346f028b7e394))
|
||||
|
||||
## [1.3.1](https://github.com/sern-handler/cli/compare/v1.3.0...v1.3.1) (2024-07-27)
|
||||
|
||||
|
||||
### Miscellaneous Chores
|
||||
|
||||
* release 1.3.1 ([2bb169f](https://github.com/sern-handler/cli/commit/2bb169f600172af8c8316b6c9420684a4de34e0d))
|
||||
|
||||
## [1.3.0](https://github.com/sern-handler/cli/compare/v1.2.1...v1.3.0) (2024-07-27)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* plugin, no prompt, bug fixes ([#139](https://github.com/sern-handler/cli/issues/139)) ([20364fa](https://github.com/sern-handler/cli/commit/20364fa20d1f3bf70a1c0cfefbc1d6c9365a4925))
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* fix publish command for bun & pnpm ([#137](https://github.com/sern-handler/cli/issues/137)) ([d581142](https://github.com/sern-handler/cli/commit/d581142f082ed888036e58aa33e9d88d84d34c2f))
|
||||
|
||||
## [1.2.1](https://github.com/sern-handler/cli/compare/v1.2.0...v1.2.1) (2024-02-08)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* better error messages for publish ([d1832e4](https://github.com/sern-handler/cli/commit/d1832e44ce1b10aeb5b9dc902b7d35ab51c41ff3))
|
||||
|
||||
## [1.2.0](https://github.com/sern-handler/cli/compare/v1.1.0...v1.2.0) (2024-01-29)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* make application id optional, thanks [@trueharuu](https://github.com/trueharuu) ([#130](https://github.com/sern-handler/cli/issues/130)) ([2d6e65a](https://github.com/sern-handler/cli/commit/2d6e65a1e6073f605aab192b8cea33037a04af2c))
|
||||
|
||||
## [1.1.0](https://github.com/sern-handler/cli/compare/v1.0.3...v1.1.0) (2024-01-28)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* command clear ([#128](https://github.com/sern-handler/cli/issues/128)) ([303ac02](https://github.com/sern-handler/cli/commit/303ac0280c7c7c55f2670d49c9685b911670bc05))
|
||||
|
||||
## [1.0.3](https://github.com/sern-handler/cli/compare/v1.0.2...v1.0.3) (2023-12-25)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* intellisense for esm build ts ([#126](https://github.com/sern-handler/cli/issues/126)) ([a5cb668](https://github.com/sern-handler/cli/commit/a5cb66828eae47d3eac5b86c7e67c01dbed500d5))
|
||||
|
||||
## [1.0.2](https://github.com/sern-handler/cli/compare/v1.0.1...v1.0.2) (2023-11-04)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* better error handling ([5dbf2a8](https://github.com/sern-handler/cli/commit/5dbf2a87dcb0001993fe126d9002bc82c8108e24))
|
||||
* build mkdir errors ([#122](https://github.com/sern-handler/cli/issues/122)) ([f1d7d6c](https://github.com/sern-handler/cli/commit/f1d7d6c911bc54ed3ca3e39eefbc7de6ee33b10d))
|
||||
|
||||
## [1.0.1](https://github.com/sern-handler/cli/compare/v1.0.0...v1.0.1) (2023-10-05)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* multiple bugs ([#119](https://github.com/sern-handler/cli/issues/119)) ([d9ca5ff](https://github.com/sern-handler/cli/commit/d9ca5ff3ff2f304a6d75f2b7a296bd900431d41f))
|
||||
|
||||
## [1.0.0](https://github.com/sern-handler/cli/compare/v0.6.0...v1.0.0) (2023-09-05)
|
||||
|
||||
|
||||
|
||||
10
README.md
10
README.md
@@ -3,11 +3,11 @@
|
||||
</div>
|
||||
|
||||
# Features
|
||||
|
||||
😁 **User Friendly** <br>
|
||||
💦 **Simple** <br>
|
||||
🌱 **Efficient** <br>
|
||||
💪 **Powerful** <br>
|
||||
- Manage discord application commands from the command line.
|
||||
- Install plugins from the community.
|
||||
- Really fast startup times (I think).
|
||||
- Deploy with premade docker configurations.
|
||||
- Inhouse build tool based on esbuild built for sern applications, nearly **zero** config.
|
||||
|
||||
## Installation
|
||||
|
||||
|
||||
188
package-lock.json
generated
188
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@sern/cli",
|
||||
"version": "1.0.0",
|
||||
"version": "1.3.2",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@sern/cli",
|
||||
"version": "1.0.0",
|
||||
"version": "1.3.2",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@esbuild-kit/cjs-loader": "^2.4.2",
|
||||
@@ -30,7 +30,7 @@
|
||||
"@favware/npm-deprecate": "1.0.7",
|
||||
"@types/prompts": "2.4.4",
|
||||
"prettier": "2.8.8",
|
||||
"tsup": "6.7.0",
|
||||
"tsup": "^6.7.0",
|
||||
"typescript": "5.2.2"
|
||||
},
|
||||
"engines": {
|
||||
@@ -443,9 +443,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/android-arm": {
|
||||
"version": "0.19.2",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.19.2.tgz",
|
||||
"integrity": "sha512-tM8yLeYVe7pRyAu9VMi/Q7aunpLwD139EY1S99xbQkT4/q2qa6eA4ige/WJQYdJ8GBL1K33pPFhPfPdJ/WzT8Q==",
|
||||
"version": "0.19.1",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.19.1.tgz",
|
||||
"integrity": "sha512-yjTucwcOua52z14RL30JMwmCdylsQ5WrErGkAb6VL0MWPbnwJyLejydaRcUqkPO6g0MowlzavdxrR7AcfCW+yA==",
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
@@ -458,9 +458,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/android-arm64": {
|
||||
"version": "0.19.2",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.19.2.tgz",
|
||||
"integrity": "sha512-lsB65vAbe90I/Qe10OjkmrdxSX4UJDjosDgb8sZUKcg3oefEuW2OT2Vozz8ef7wrJbMcmhvCC+hciF8jY/uAkw==",
|
||||
"version": "0.19.1",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.19.1.tgz",
|
||||
"integrity": "sha512-CqhrKvDSt76I0so/5afqgKrMv41FjbfUKFrcZddMnrZKqJU70I1MWLVJrImJuYMaY4Yb9rn4UKfF7oZ0BOleVw==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -473,9 +473,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/android-x64": {
|
||||
"version": "0.19.2",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.19.2.tgz",
|
||||
"integrity": "sha512-qK/TpmHt2M/Hg82WXHRc/W/2SGo/l1thtDHZWqFq7oi24AjZ4O/CpPSu6ZuYKFkEgmZlFoa7CooAyYmuvnaG8w==",
|
||||
"version": "0.19.1",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.19.1.tgz",
|
||||
"integrity": "sha512-VA29h01MrPkymIL1bFtvL2L4WPogiMGW2N/M+vXZHHOv6LgA9vjzVskTt0v5LjeCjx1PFDcR0ASKy8Y7Gm+iIA==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -488,9 +488,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/darwin-arm64": {
|
||||
"version": "0.19.2",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.19.2.tgz",
|
||||
"integrity": "sha512-Ora8JokrvrzEPEpZO18ZYXkH4asCdc1DLdcVy8TGf5eWtPO1Ie4WroEJzwI52ZGtpODy3+m0a2yEX9l+KUn0tA==",
|
||||
"version": "0.19.1",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.19.1.tgz",
|
||||
"integrity": "sha512-Be4Cf6WDH7QkLHEpfzQOlBOFdqmqYTSqw2yG3SVmzB3++wy3K7wiNGedezL+q6Jb4weqT9tchO5kkLDC08Jnzg==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -503,9 +503,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/darwin-x64": {
|
||||
"version": "0.19.2",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.19.2.tgz",
|
||||
"integrity": "sha512-tP+B5UuIbbFMj2hQaUr6EALlHOIOmlLM2FK7jeFBobPy2ERdohI4Ka6ZFjZ1ZYsrHE/hZimGuU90jusRE0pwDw==",
|
||||
"version": "0.19.1",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.19.1.tgz",
|
||||
"integrity": "sha512-SewtenJi6zCEfZRSUchb+LgJ/IQw8QvnKECPu/qHII1fLQKnVPUVR+VH2IuS03DD9WWnAi3yfOvBNwtrp3WXtg==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -518,9 +518,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/freebsd-arm64": {
|
||||
"version": "0.19.2",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.19.2.tgz",
|
||||
"integrity": "sha512-YbPY2kc0acfzL1VPVK6EnAlig4f+l8xmq36OZkU0jzBVHcOTyQDhnKQaLzZudNJQyymd9OqQezeaBgkTGdTGeQ==",
|
||||
"version": "0.19.1",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.19.1.tgz",
|
||||
"integrity": "sha512-TadKO0AaTDAPV2RyGZQ0AaiDTVYg7RsgNaA6OJjXXmoLbTs++NwHtzAmVFBq8Q/P9A11wgkv36HeyAYhWHbW1w==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -533,9 +533,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/freebsd-x64": {
|
||||
"version": "0.19.2",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.19.2.tgz",
|
||||
"integrity": "sha512-nSO5uZT2clM6hosjWHAsS15hLrwCvIWx+b2e3lZ3MwbYSaXwvfO528OF+dLjas1g3bZonciivI8qKR/Hm7IWGw==",
|
||||
"version": "0.19.1",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.19.1.tgz",
|
||||
"integrity": "sha512-DrFMGLF0/aAcZgwhtZr1cby7aHlalpFjLCe5CiI8mm0Kqhhc8gyNZKreaZzvir8CQe0H17p9xx6M9ben5R3r0g==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -548,9 +548,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/linux-arm": {
|
||||
"version": "0.19.2",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.19.2.tgz",
|
||||
"integrity": "sha512-Odalh8hICg7SOD7XCj0YLpYCEc+6mkoq63UnExDCiRA2wXEmGlK5JVrW50vZR9Qz4qkvqnHcpH+OFEggO3PgTg==",
|
||||
"version": "0.19.1",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.19.1.tgz",
|
||||
"integrity": "sha512-lCWDVPpQO/Dt5MEqctKujgtUVmwQx7J2Q83EqX/9BejN7BIX4fGJ0QKMiIyy21PFh+/64ArN+Ovh1tzYkTt2wg==",
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
@@ -563,9 +563,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/linux-arm64": {
|
||||
"version": "0.19.2",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.19.2.tgz",
|
||||
"integrity": "sha512-ig2P7GeG//zWlU0AggA3pV1h5gdix0MA3wgB+NsnBXViwiGgY77fuN9Wr5uoCrs2YzaYfogXgsWZbm+HGr09xg==",
|
||||
"version": "0.19.1",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.19.1.tgz",
|
||||
"integrity": "sha512-6ku/R2EzsdjyBaqQn+xGOPbv+BBYBXQYzlA04/46YQLmXkdApi0GYyUwiCXYBxm578iyywzGmM0rep1/q8tuFQ==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -578,9 +578,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/linux-ia32": {
|
||||
"version": "0.19.2",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.19.2.tgz",
|
||||
"integrity": "sha512-mLfp0ziRPOLSTek0Gd9T5B8AtzKAkoZE70fneiiyPlSnUKKI4lp+mGEnQXcQEHLJAcIYDPSyBvsUbKUG2ri/XQ==",
|
||||
"version": "0.19.1",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.19.1.tgz",
|
||||
"integrity": "sha512-8AKFBk9v/zBDsADvK/0BWZUxkjEc0QDwO8rvbHJKqAZx6DF/VSeBxTRmqWeecrJmx+n3kemEwML9z0eD9IHweQ==",
|
||||
"cpu": [
|
||||
"ia32"
|
||||
],
|
||||
@@ -593,9 +593,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/linux-loong64": {
|
||||
"version": "0.19.2",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.19.2.tgz",
|
||||
"integrity": "sha512-hn28+JNDTxxCpnYjdDYVMNTR3SKavyLlCHHkufHV91fkewpIyQchS1d8wSbmXhs1fiYDpNww8KTFlJ1dHsxeSw==",
|
||||
"version": "0.19.1",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.19.1.tgz",
|
||||
"integrity": "sha512-6mOS5CxTGD8qOymp2y4KoM4ir+/REgjdJQFYpwP+WqjrWBo+PUevDGeHHjzCdw/R19PkFqS1bRzv8cTCmB/5kA==",
|
||||
"cpu": [
|
||||
"loong64"
|
||||
],
|
||||
@@ -608,9 +608,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/linux-mips64el": {
|
||||
"version": "0.19.2",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.19.2.tgz",
|
||||
"integrity": "sha512-KbXaC0Sejt7vD2fEgPoIKb6nxkfYW9OmFUK9XQE4//PvGIxNIfPk1NmlHmMg6f25x57rpmEFrn1OotASYIAaTg==",
|
||||
"version": "0.19.1",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.19.1.tgz",
|
||||
"integrity": "sha512-Bzmv6rRMzR4ErG2k/jwfj5jKNzVMVEI1tThuirFdAoE+duUv+jlDnlwxsN3s1eqMzADTOV2sSIcUUOfgv++Dgg==",
|
||||
"cpu": [
|
||||
"mips64el"
|
||||
],
|
||||
@@ -623,9 +623,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/linux-ppc64": {
|
||||
"version": "0.19.2",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.19.2.tgz",
|
||||
"integrity": "sha512-dJ0kE8KTqbiHtA3Fc/zn7lCd7pqVr4JcT0JqOnbj4LLzYnp+7h8Qi4yjfq42ZlHfhOCM42rBh0EwHYLL6LEzcw==",
|
||||
"version": "0.19.1",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.19.1.tgz",
|
||||
"integrity": "sha512-mPOxA7bd3nmx8TkuO/9M/tE0fnvmuX0wlpwnTL6DPLgkb/Z/KkupexSIw4cLfznn/fPzD89y17VWBjlVNyrpCQ==",
|
||||
"cpu": [
|
||||
"ppc64"
|
||||
],
|
||||
@@ -638,9 +638,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/linux-riscv64": {
|
||||
"version": "0.19.2",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.19.2.tgz",
|
||||
"integrity": "sha512-7Z/jKNFufZ/bbu4INqqCN6DDlrmOTmdw6D0gH+6Y7auok2r02Ur661qPuXidPOJ+FSgbEeQnnAGgsVynfLuOEw==",
|
||||
"version": "0.19.1",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.19.1.tgz",
|
||||
"integrity": "sha512-znYb2Mhe9xKIDeIYuTD6vCcUltvYzRT5Yq6sVcdhPrGu8DRdsNZS04B2tSeM+j7T03jL4yY+7/G/jxSJJ9LX2A==",
|
||||
"cpu": [
|
||||
"riscv64"
|
||||
],
|
||||
@@ -653,9 +653,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/linux-s390x": {
|
||||
"version": "0.19.2",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.19.2.tgz",
|
||||
"integrity": "sha512-U+RinR6aXXABFCcAY4gSlv4CL1oOVvSSCdseQmGO66H+XyuQGZIUdhG56SZaDJQcLmrSfRmx5XZOWyCJPRqS7g==",
|
||||
"version": "0.19.1",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.19.1.tgz",
|
||||
"integrity": "sha512-BBIE32cyqAYhMOQ42/jnecoF5P/S5lMob2vXSUiFpD3xCFbXOFkjP1OjfFKnalSO9+B5emvPTQFfNQXuLeVGEw==",
|
||||
"cpu": [
|
||||
"s390x"
|
||||
],
|
||||
@@ -668,9 +668,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/linux-x64": {
|
||||
"version": "0.19.2",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.19.2.tgz",
|
||||
"integrity": "sha512-oxzHTEv6VPm3XXNaHPyUTTte+3wGv7qVQtqaZCrgstI16gCuhNOtBXLEBkBREP57YTd68P0VgDgG73jSD8bwXQ==",
|
||||
"version": "0.19.1",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.19.1.tgz",
|
||||
"integrity": "sha512-PoCvKdHTIbnHmVJ5OEdewGMSw40HDFRTrC/imwh8vrp695RbSUpOqBqNBT45neK0FQleGFbSE/A9X6HlXPDhqA==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -683,9 +683,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/netbsd-x64": {
|
||||
"version": "0.19.2",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.19.2.tgz",
|
||||
"integrity": "sha512-WNa5zZk1XpTTwMDompZmvQLHszDDDN7lYjEHCUmAGB83Bgs20EMs7ICD+oKeT6xt4phV4NDdSi/8OfjPbSbZfQ==",
|
||||
"version": "0.19.1",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.19.1.tgz",
|
||||
"integrity": "sha512-4OrGMPorHCq9h52VLtyyyAmPjC2ZlANx54VDYyCrqXUOi+k0qxnPKXKKprVES67w2mE7TZJx9qZmT+jHeiZbHQ==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -698,9 +698,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/openbsd-x64": {
|
||||
"version": "0.19.2",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.19.2.tgz",
|
||||
"integrity": "sha512-S6kI1aT3S++Dedb7vxIuUOb3oAxqxk2Rh5rOXOTYnzN8JzW1VzBd+IqPiSpgitu45042SYD3HCoEyhLKQcDFDw==",
|
||||
"version": "0.19.1",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.19.1.tgz",
|
||||
"integrity": "sha512-3a7ZYMjBC4P3FKdTmUZHJw7Mhzp71m+iSFFhX1PnLZ03qmyaB2K+vJZCk4PjRjAvm5lSupJQQtM/AFMyLgKlxQ==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -713,9 +713,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/sunos-x64": {
|
||||
"version": "0.19.2",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.19.2.tgz",
|
||||
"integrity": "sha512-VXSSMsmb+Z8LbsQGcBMiM+fYObDNRm8p7tkUDMPG/g4fhFX5DEFmjxIEa3N8Zr96SjsJ1woAhF0DUnS3MF3ARw==",
|
||||
"version": "0.19.1",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.19.1.tgz",
|
||||
"integrity": "sha512-29yWBN5XfEjXT8yoeVb8cXfN1jAQLB+uskog1vBMhFR+YWOYvsrwPnh4hspETC/JnF95J+iETrvxgOUlICTWIw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -728,9 +728,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/win32-arm64": {
|
||||
"version": "0.19.2",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.19.2.tgz",
|
||||
"integrity": "sha512-5NayUlSAyb5PQYFAU9x3bHdsqB88RC3aM9lKDAz4X1mo/EchMIT1Q+pSeBXNgkfNmRecLXA0O8xP+x8V+g/LKg==",
|
||||
"version": "0.19.1",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.19.1.tgz",
|
||||
"integrity": "sha512-9Hb/WUXgyXlL55w3iNVyLkN9gq9x+agv3kk80foWbfpOwe7Qw4Vx6JGB+XQdsIfvvP1kShVQPIvBgVj0TxLlVw==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
@@ -743,9 +743,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/win32-ia32": {
|
||||
"version": "0.19.2",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.19.2.tgz",
|
||||
"integrity": "sha512-47gL/ek1v36iN0wL9L4Q2MFdujR0poLZMJwhO2/N3gA89jgHp4MR8DKCmwYtGNksbfJb9JoTtbkoe6sDhg2QTA==",
|
||||
"version": "0.19.1",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.19.1.tgz",
|
||||
"integrity": "sha512-VGdtEcXX/f01NgoM8emDnpdOyrZCQ7VTwLv89MOl3mvJ5fbCOBMNCa8t7RZS4lf12RS87qOuJFX7Bh9aLTbSxg==",
|
||||
"cpu": [
|
||||
"ia32"
|
||||
],
|
||||
@@ -758,9 +758,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@esbuild/win32-x64": {
|
||||
"version": "0.19.2",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.19.2.tgz",
|
||||
"integrity": "sha512-tcuhV7ncXBqbt/Ybf0IyrMcwVOAPDckMK9rXNHtF17UTK18OKLpg08glminN06pt2WCoALhXdLfSPbVvK/6fxw==",
|
||||
"version": "0.19.1",
|
||||
"resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.19.1.tgz",
|
||||
"integrity": "sha512-H6u8OHmJkKJubLbukVOyi9yA5lzK8VE4TFEkZj2vgusTUPvFeMQ8YnWviVc9F6PuKS6ZIpOvi2/sfiW8tQZQ2g==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
@@ -1447,9 +1447,9 @@
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/esbuild": {
|
||||
"version": "0.19.2",
|
||||
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.19.2.tgz",
|
||||
"integrity": "sha512-G6hPax8UbFakEj3hWO0Vs52LQ8k3lnBhxZWomUJDxfz3rZTLqF5k/FCzuNdLx2RbpBiQQF9H9onlDDH1lZsnjg==",
|
||||
"version": "0.19.1",
|
||||
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.19.1.tgz",
|
||||
"integrity": "sha512-IknHHwV4B/H4imOAu+416fuCvPfRjdncoyGi7eunhSvHuHkdNs50sLWan2LEG2Mym07TuW6gJUIyRS9G1miHEg==",
|
||||
"hasInstallScript": true,
|
||||
"bin": {
|
||||
"esbuild": "bin/esbuild"
|
||||
@@ -1458,28 +1458,28 @@
|
||||
"node": ">=12"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"@esbuild/android-arm": "0.19.2",
|
||||
"@esbuild/android-arm64": "0.19.2",
|
||||
"@esbuild/android-x64": "0.19.2",
|
||||
"@esbuild/darwin-arm64": "0.19.2",
|
||||
"@esbuild/darwin-x64": "0.19.2",
|
||||
"@esbuild/freebsd-arm64": "0.19.2",
|
||||
"@esbuild/freebsd-x64": "0.19.2",
|
||||
"@esbuild/linux-arm": "0.19.2",
|
||||
"@esbuild/linux-arm64": "0.19.2",
|
||||
"@esbuild/linux-ia32": "0.19.2",
|
||||
"@esbuild/linux-loong64": "0.19.2",
|
||||
"@esbuild/linux-mips64el": "0.19.2",
|
||||
"@esbuild/linux-ppc64": "0.19.2",
|
||||
"@esbuild/linux-riscv64": "0.19.2",
|
||||
"@esbuild/linux-s390x": "0.19.2",
|
||||
"@esbuild/linux-x64": "0.19.2",
|
||||
"@esbuild/netbsd-x64": "0.19.2",
|
||||
"@esbuild/openbsd-x64": "0.19.2",
|
||||
"@esbuild/sunos-x64": "0.19.2",
|
||||
"@esbuild/win32-arm64": "0.19.2",
|
||||
"@esbuild/win32-ia32": "0.19.2",
|
||||
"@esbuild/win32-x64": "0.19.2"
|
||||
"@esbuild/android-arm": "0.19.1",
|
||||
"@esbuild/android-arm64": "0.19.1",
|
||||
"@esbuild/android-x64": "0.19.1",
|
||||
"@esbuild/darwin-arm64": "0.19.1",
|
||||
"@esbuild/darwin-x64": "0.19.1",
|
||||
"@esbuild/freebsd-arm64": "0.19.1",
|
||||
"@esbuild/freebsd-x64": "0.19.1",
|
||||
"@esbuild/linux-arm": "0.19.1",
|
||||
"@esbuild/linux-arm64": "0.19.1",
|
||||
"@esbuild/linux-ia32": "0.19.1",
|
||||
"@esbuild/linux-loong64": "0.19.1",
|
||||
"@esbuild/linux-mips64el": "0.19.1",
|
||||
"@esbuild/linux-ppc64": "0.19.1",
|
||||
"@esbuild/linux-riscv64": "0.19.1",
|
||||
"@esbuild/linux-s390x": "0.19.1",
|
||||
"@esbuild/linux-x64": "0.19.1",
|
||||
"@esbuild/netbsd-x64": "0.19.1",
|
||||
"@esbuild/openbsd-x64": "0.19.1",
|
||||
"@esbuild/sunos-x64": "0.19.1",
|
||||
"@esbuild/win32-arm64": "0.19.1",
|
||||
"@esbuild/win32-ia32": "0.19.1",
|
||||
"@esbuild/win32-x64": "0.19.1"
|
||||
}
|
||||
},
|
||||
"node_modules/execa": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@sern/cli",
|
||||
"version": "1.0.0",
|
||||
"version": "1.3.2",
|
||||
"description": "Official CLI for @sern/handler",
|
||||
"exports": "./dist/index.js",
|
||||
"bin": {
|
||||
@@ -50,7 +50,7 @@
|
||||
"@favware/npm-deprecate": "1.0.7",
|
||||
"@types/prompts": "2.4.4",
|
||||
"prettier": "2.8.8",
|
||||
"tsup": "6.7.0",
|
||||
"tsup": "^6.7.0",
|
||||
"typescript": "5.2.2"
|
||||
},
|
||||
"engines": {
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
import esbuild from 'esbuild';
|
||||
import { getConfig } from '../utilities/getConfig';
|
||||
import { resolve } from 'node:path';
|
||||
import p from 'node:path';
|
||||
import { glob } from 'glob';
|
||||
import { configDotenv } from 'dotenv';
|
||||
import assert from 'node:assert';
|
||||
import { imageLoader, validExtensions } from '../plugins/imageLoader';
|
||||
import defaultEsbuild from '../utilities/defaultEsbuildConfig';
|
||||
import { require } from '../utilities/require';
|
||||
import { pathExists, pathExistsSync } from 'find-up';
|
||||
import { mkdir, writeFile } from 'fs/promises';
|
||||
import { mkdir, writeFile, readFile } from 'fs/promises';
|
||||
import * as Preprocessor from '../utilities/preprocessor';
|
||||
import { bold, magentaBright } from 'colorette';
|
||||
import { parseTsConfig } from '../utilities/parseTsconfig';
|
||||
|
||||
const VALID_EXTENSIONS = ['.ts', '.js' ];
|
||||
|
||||
type BuildOptions = {
|
||||
/**
|
||||
@@ -23,10 +25,6 @@ type BuildOptions = {
|
||||
* default = esm
|
||||
*/
|
||||
format?: 'cjs' | 'esm';
|
||||
/**
|
||||
* extra esbuild plugins to build with sern.
|
||||
*/
|
||||
esbuildPlugins?: esbuild.Plugin[];
|
||||
/**
|
||||
* https://esbuild.github.io/api/#drop-labels
|
||||
**/
|
||||
@@ -48,72 +46,74 @@ type BuildOptions = {
|
||||
env?: string;
|
||||
};
|
||||
|
||||
const CommandHandlerPlugin = (buildConfig: Partial<BuildOptions>, ambientFilePath: string, sernTsConfigPath: string) => {
|
||||
return {
|
||||
name: "commandhandler",
|
||||
setup(build) {
|
||||
|
||||
const options = build.initialOptions
|
||||
const defVersion = () => JSON.stringify(require(p.resolve('package.json')).version);
|
||||
options.define = {
|
||||
...buildConfig.define ?? {},
|
||||
__DEV__: `${buildConfig.mode === 'development'}`,
|
||||
__PROD__: `${buildConfig.mode === 'production'}`,
|
||||
__VERSION__: `${buildConfig.defineVersion ? `${defVersion()}` : 'undefined'}`
|
||||
} ?? {}
|
||||
Preprocessor.writeTsConfig(buildConfig.format!, sernTsConfigPath, writeFile);
|
||||
Preprocessor.writeAmbientFile(ambientFilePath, options.define!, writeFile);
|
||||
|
||||
}
|
||||
} as esbuild.Plugin
|
||||
}
|
||||
const resolveBuildConfig = (path: string|undefined, language: string) => {
|
||||
if(language === 'javascript') {
|
||||
return path ?? 'jsconfig.json'
|
||||
}
|
||||
return path ?? 'tsconfig.json'
|
||||
}
|
||||
|
||||
export async function build(options: Record<string, any>) {
|
||||
if (!options.supressWarnings) {
|
||||
console.info(`${magentaBright('EXPERIMENTAL')}: This API has not been stabilized. add -W or --suppress-warnings flag to suppress`);
|
||||
}
|
||||
const sernConfig = await getConfig();
|
||||
let buildConfig: Partial<BuildOptions> = {};
|
||||
const entryPoints = await glob(`./src/**/*{${validExtensions.join(',')}}`, {
|
||||
//for some reason, my ignore glob wasn't registering correctly'
|
||||
ignore: {
|
||||
ignored: (p) => p.name.endsWith('.d.ts'),
|
||||
},
|
||||
});
|
||||
const buildConfigPath = resolve(options.project ?? 'sern.build.js');
|
||||
let buildConfig: BuildOptions;
|
||||
const buildConfigPath = p.resolve(options.project ?? 'sern.build.js');
|
||||
|
||||
const defaultBuildConfig = {
|
||||
defineVersion: true,
|
||||
format: options.format ?? 'esm',
|
||||
mode: options.mode ?? 'development',
|
||||
dropLabels: [],
|
||||
tsconfig: options.tsconfig ?? resolve('tsconfig.json'),
|
||||
|
||||
env: options.env ?? resolve('.env'),
|
||||
tsconfig: resolveBuildConfig(options.tsconfig, sernConfig.language),
|
||||
env: options.env ?? '.env',
|
||||
include: []
|
||||
};
|
||||
if (pathExistsSync(buildConfigPath)) {
|
||||
try {
|
||||
buildConfig = {
|
||||
...defaultBuildConfig,
|
||||
...(await import('file:///' + buildConfigPath)).default,
|
||||
};
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
process.exit(1);
|
||||
}
|
||||
//throwable, buildConfigPath may not exist
|
||||
buildConfig = { ...defaultBuildConfig, ...(await import('file:///' + buildConfigPath)).default };
|
||||
} else {
|
||||
buildConfig = {
|
||||
...defaultBuildConfig,
|
||||
};
|
||||
buildConfig = defaultBuildConfig;
|
||||
console.log('No build config found, defaulting');
|
||||
}
|
||||
let env = {} as Record<string, string>;
|
||||
configDotenv({ path: buildConfig.env, processEnv: env });
|
||||
|
||||
if (env.MODE && !env.NODE_ENV) {
|
||||
console.warn('Use NODE_ENV instead of MODE');
|
||||
console.warn('MODE has no effect.');
|
||||
console.warn(`https://nodejs.dev/en/learn/nodejs-the-difference-between-development-and-production/`);
|
||||
}
|
||||
|
||||
if (env.NODE_ENV) {
|
||||
buildConfig.mode = env.NODE_ENV as 'production' | 'development';
|
||||
configDotenv({ path: buildConfig.env });
|
||||
|
||||
if (process.env.NODE_ENV) {
|
||||
buildConfig.mode = process.env.NODE_ENV as 'production' | 'development';
|
||||
console.log(magentaBright('NODE_ENV:'), 'Found NODE_ENV variable, setting `mode` to this.');
|
||||
}
|
||||
assert(buildConfig.mode === 'development' || buildConfig.mode === 'production', 'Mode is not `production` or `development`');
|
||||
try {
|
||||
let config = await parseTsConfig(buildConfig.tsconfig!);
|
||||
config?.extends && console.warn("Extend the generated tsconfig")
|
||||
} catch(e) {
|
||||
console.error("no tsconfig / jsconfig found");
|
||||
console.error(`Please create a ${sernConfig.language === 'javascript' ? 'jsconfig.json' : 'tsconfig.json' }`);
|
||||
console.error('It should have at least extend the generated one sern makes.\n \
|
||||
{ "extends": "./.sern/tsconfig.json" }');
|
||||
throw e;
|
||||
}
|
||||
|
||||
const defaultTsConfig = {
|
||||
extends: './.sern/tsconfig.json',
|
||||
};
|
||||
!buildConfig.tsconfig && console.log('Using default options for tsconfig', defaultTsConfig);
|
||||
const tsconfigRaw = require(buildConfig.tsconfig!);
|
||||
|
||||
sernConfig.language === 'typescript' &&
|
||||
tsconfigRaw &&
|
||||
!tsconfigRaw.extends &&
|
||||
(console.warn('tsconfig does not contain an "extends". Will not use sern automatic path aliasing'),
|
||||
console.warn('For projects that predate sern build and want to fully integrate, extend the tsconfig generated in .sern'),
|
||||
console.warn('Extend preexisting tsconfig with top level: "extends": "./.sern/tsconfig.json"'));
|
||||
console.log(bold('Building with:'));
|
||||
console.log(' ', magentaBright('defineVersion'), buildConfig.defineVersion);
|
||||
console.log(' ', magentaBright('format'), buildConfig.format);
|
||||
@@ -121,41 +121,32 @@ export async function build(options: Record<string, any>) {
|
||||
console.log(' ', magentaBright('tsconfig'), buildConfig.tsconfig);
|
||||
console.log(' ', magentaBright('env'), buildConfig.env);
|
||||
|
||||
const sernDir = resolve('.sern'),
|
||||
genDir = resolve(sernDir, 'generated'),
|
||||
ambientFilePath = resolve(sernDir, 'ambient.d.ts'),
|
||||
packageJsonPath = resolve('package.json'),
|
||||
sernTsConfigPath = resolve(sernDir, 'tsconfig.json'),
|
||||
packageJson = () => require(packageJsonPath);
|
||||
const sernDir = p.resolve('.sern'),
|
||||
[ambientFilePath, sernTsConfigPath, genDir] =
|
||||
['ambient.d.ts', 'tsconfig.json', 'generated'].map(f => p.resolve(sernDir, f));
|
||||
|
||||
if (!(await pathExists(genDir))) {
|
||||
console.log('Making .sern/generated dir, does not exist');
|
||||
await mkdir(genDir);
|
||||
await mkdir(genDir, { recursive: true });
|
||||
}
|
||||
|
||||
const entryPoints = await glob(`src/**/*{${VALID_EXTENSIONS.join(',')}}`,{
|
||||
ignore: {
|
||||
ignored: (p) => p.name.endsWith('.d.ts'),
|
||||
}
|
||||
});
|
||||
//https://esbuild.github.io/content-types/#tsconfig-json
|
||||
const ctx = await esbuild.context({
|
||||
entryPoints,
|
||||
plugins: [CommandHandlerPlugin(buildConfig, ambientFilePath, sernTsConfigPath)],
|
||||
...defaultEsbuild(buildConfig.format!, buildConfig.tsconfig),
|
||||
dropLabels: [buildConfig.mode === 'production' ? '__DEV__' : '__PROD__', ...buildConfig.dropLabels!],
|
||||
});
|
||||
|
||||
try {
|
||||
const defVersion = () => JSON.stringify(packageJson().version);
|
||||
const define = {
|
||||
...(buildConfig.define ?? {}),
|
||||
__DEV__: `${buildConfig.mode === 'development'}`,
|
||||
__PROD__: `${buildConfig.mode === 'production'}`,
|
||||
} satisfies Record<string, string>;
|
||||
|
||||
buildConfig.defineVersion && Object.assign(define, { __VERSION__: defVersion() });
|
||||
|
||||
await Preprocessor.writeTsConfig(buildConfig.format!, sernTsConfigPath, writeFile);
|
||||
await Preprocessor.writeAmbientFile(ambientFilePath, define, writeFile);
|
||||
|
||||
//https://esbuild.github.io/content-types/#tsconfig-json
|
||||
await esbuild.build({
|
||||
entryPoints,
|
||||
plugins: [imageLoader, ...(buildConfig.esbuildPlugins ?? [])],
|
||||
...defaultEsbuild(buildConfig.format!, tsconfigRaw),
|
||||
define,
|
||||
dropLabels: [buildConfig.mode === 'production' ? '__DEV__' : '__PROD__', ...buildConfig.dropLabels!],
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
await ctx.rebuild()
|
||||
if(options.watch) {
|
||||
await ctx.watch()
|
||||
} else {
|
||||
await ctx.dispose()
|
||||
}
|
||||
}
|
||||
|
||||
60
src/commands/command-clear.ts
Normal file
60
src/commands/command-clear.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import * as Rest from '../rest.js'
|
||||
import assert from 'node:assert'
|
||||
import dotenv from 'dotenv'
|
||||
import ora from 'ora';
|
||||
import type { CommandData, GuildId } from '../utilities/types.js';
|
||||
import { readFileSync, writeFile } from 'node:fs'
|
||||
import { resolve } from 'node:path'
|
||||
import prompts from 'prompts';
|
||||
|
||||
const getConfirmation = (args: Record<string,any> ) => {
|
||||
if(args.yes) {
|
||||
return args.yes
|
||||
} else {
|
||||
return prompts({
|
||||
type: 'confirm',
|
||||
name: 'confirmation',
|
||||
message: 'Are you sure you want to delete ALL your application commands?',
|
||||
initial: true
|
||||
}, { onCancel: () => (console.log("Cancelled operation ( ̄┰ ̄*)"), process.exit(1)) })
|
||||
.then(response => response.confirmation);
|
||||
}
|
||||
}
|
||||
export async function commandClear(args: Record<string,any>) {
|
||||
dotenv.configDotenv({ path: args.env || resolve('.env') })
|
||||
const token = process.env.token || process.env.DISCORD_TOKEN;
|
||||
assert(token, 'Could not find a token for this bot in .env or commandline. Do you have DISCORD_TOKEN in env?');
|
||||
|
||||
const confirmation = await getConfirmation(args);
|
||||
|
||||
if (confirmation) {
|
||||
const spin = ora({
|
||||
text: `Deleting ALL application commands...`,
|
||||
spinner: 'aesthetic',
|
||||
}).start();
|
||||
const rest = await Rest.create(token);
|
||||
let guildCommands: Record<GuildId, CommandData[]>
|
||||
try {
|
||||
guildCommands = JSON.parse(readFileSync('.sern/command-data-remote.json', 'utf-8'))
|
||||
await rest.updateGlobal([]);
|
||||
delete guildCommands.global
|
||||
for (const guildId in guildCommands) {
|
||||
await rest.putGuildCommands(guildId, []);
|
||||
}
|
||||
writeFile('.sern/command-data-remote.json', "{}", (err) => {
|
||||
if(err) {
|
||||
spin.fail("Error happened while writing to json:");
|
||||
console.error(err)
|
||||
process.exit(1)
|
||||
}
|
||||
})
|
||||
spin.succeed();
|
||||
} catch(e) {
|
||||
spin.fail("Something went wrong. ");
|
||||
throw e;
|
||||
}
|
||||
} else {
|
||||
console.log('Operation canceled. ( ̄┰ ̄*)');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,9 +14,11 @@ export function list() {
|
||||
const globalCommands = commands.global;
|
||||
|
||||
delete commands.global;
|
||||
console.log(bold('Global Commands'));
|
||||
for (const command of globalCommands) log(command);
|
||||
|
||||
if(globalCommands) {
|
||||
console.log(bold('Global Commands'));
|
||||
for (const command of globalCommands) log(command);
|
||||
}
|
||||
|
||||
console.log('\t');
|
||||
|
||||
for (const guildId in commands) {
|
||||
|
||||
@@ -2,12 +2,13 @@ import { greenBright } from 'colorette';
|
||||
import fs from 'fs';
|
||||
import prompt from 'prompts';
|
||||
import { fetch } from 'undici';
|
||||
import { pluginsQ } from '../prompts/plugin.js';
|
||||
import { fromCwd } from '../utilities/fromCwd.js';
|
||||
import esbuild from 'esbuild';
|
||||
import { getLang } from '../utilities/getLang.js';
|
||||
import { getConfig } from '../utilities/getConfig.js';
|
||||
import type { PromptObject } from 'prompts';
|
||||
import { resolve } from 'path';
|
||||
import { require } from '../utilities/require.js';
|
||||
|
||||
interface PluginData {
|
||||
description: string;
|
||||
hash: string;
|
||||
@@ -15,25 +16,57 @@ interface PluginData {
|
||||
author: string[];
|
||||
link: string;
|
||||
example: string;
|
||||
version: '1.0.0';
|
||||
version: string;
|
||||
}
|
||||
|
||||
const link = `https://raw.githubusercontent.com/sern-handler/awesome-plugins/main/pluginlist.json`;
|
||||
export async function fetchPluginData(): Promise<PluginData[]> {
|
||||
return fetch(link)
|
||||
.then(res => res.json())
|
||||
.then(data => (data as PluginData[]))
|
||||
.catch(() => [])
|
||||
}
|
||||
|
||||
export function pluginsQ(choices: PluginData[]): PromptObject[] {
|
||||
return [{
|
||||
name: 'list',
|
||||
type: 'autocompleteMultiselect',
|
||||
message: 'What plugins do you want to install?',
|
||||
choices: choices.map(e => ({ title: e.name, value: e })),
|
||||
min: 1,
|
||||
}];
|
||||
}
|
||||
/**
|
||||
* Installs plugins to project
|
||||
*/
|
||||
export async function plugins() {
|
||||
const e: PluginData[] = (await prompt([await pluginsQ()])).list;
|
||||
if (!e) process.exit(1);
|
||||
|
||||
const lang = await getLang();
|
||||
for await (const plgData of e) {
|
||||
export async function plugins(args: string[], opts: Record<string, unknown>) {
|
||||
const plugins = await fetchPluginData();
|
||||
let selectedPlugins : PluginData[];
|
||||
if(args.length) {
|
||||
const normalizedArgs = args.map(str => str.toLowerCase())
|
||||
console.log("Trying to find plugins to install...");
|
||||
const results = plugins.reduce((acc, cur) => {
|
||||
if(normalizedArgs.includes(cur.name.toLowerCase())) {
|
||||
return [...acc, cur]
|
||||
}
|
||||
return acc;
|
||||
}, [] as PluginData[]);
|
||||
selectedPlugins = results;
|
||||
} else {
|
||||
selectedPlugins = (await prompt(pluginsQ(plugins))).list;
|
||||
}
|
||||
if (!selectedPlugins.length) {
|
||||
process.exit(1);
|
||||
}
|
||||
const { language } = await getConfig();
|
||||
for await (const plgData of selectedPlugins) {
|
||||
const pluginText = await download(plgData.link);
|
||||
const dir = fromCwd('/src/plugins');
|
||||
const linkNoExtension = `${process.cwd()}/src/plugins/${plgData.name}`;
|
||||
if (!fs.existsSync(dir)) {
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
}
|
||||
if (lang === 'typescript') {
|
||||
if (language === 'typescript') {
|
||||
fs.writeFileSync(linkNoExtension + '.ts', pluginText);
|
||||
} else {
|
||||
const { type = undefined } = require(resolve('package.json'));
|
||||
@@ -54,7 +87,7 @@ export async function plugins() {
|
||||
}
|
||||
}
|
||||
|
||||
const pluginNames = e.map((data) => {
|
||||
const pluginNames = selectedPlugins.map((data) => {
|
||||
return 'Installed ' + data.name + ' ' + 'from ' + data.author.join(',');
|
||||
});
|
||||
console.log(`Successfully downloaded plugin(s):\n${greenBright(pluginNames.join('\n'))}`);
|
||||
|
||||
@@ -14,21 +14,17 @@ export async function publish(commandDir: string | undefined, args: Partial<Publ
|
||||
// assign args.import to empty array if non existent
|
||||
args.import ??= [];
|
||||
|
||||
args.token && console.info('token passed through command line');
|
||||
args.applicationId && console.info('applicationId passed through command line');
|
||||
commandDir && console.info('Publishing with override path: ', commandDir);
|
||||
|
||||
const dotenvLocation = new URL('../node_modules/dotenv/config.js', rootPath),
|
||||
esmLoader = new URL('../node_modules/@esbuild-kit/esm-loader/dist/index.js', rootPath);
|
||||
const isBunOrPnpm = rootPath.pathname.includes('.bun') || rootPath.pathname.includes('.pnpm');
|
||||
|
||||
const dotenvLocation = new URL(`${isBunOrPnpm ? '../../' : '../'}node_modules/dotenv/config.js`, rootPath),
|
||||
esmLoader = new URL(`${isBunOrPnpm ? '../../' : '../'}node_modules/@esbuild-kit/esm-loader/dist/index.js`, rootPath);
|
||||
|
||||
// We dynamically load the create-publish script in a child process so that we can pass the special
|
||||
// loader flag to require typescript files
|
||||
const command = fork(fileURLToPath(publishScript), [], {
|
||||
execArgv: ['--loader', esmLoader.toString(), '-r', fileURLToPath(dotenvLocation), '--no-warnings'],
|
||||
env: {
|
||||
token: args.token ?? '',
|
||||
applicationId: args.applicationId ?? '',
|
||||
},
|
||||
});
|
||||
// send paths object so we dont have to recalculate it in script
|
||||
command.send({ config, preloads: args.import, commandDir });
|
||||
|
||||
@@ -2,63 +2,39 @@
|
||||
* This file is meant to be run with the esm / cjs esbuild-kit loader to properly import typescript modules
|
||||
*/
|
||||
|
||||
import { readdir, stat, mkdir, writeFile } from 'fs/promises';
|
||||
import { join, basename, extname, resolve } from 'node:path';
|
||||
import { readdir, mkdir, writeFile } from 'fs/promises';
|
||||
import { basename, resolve, posix as pathpsx } from 'node:path';
|
||||
import { pathExistsSync } from 'find-up';
|
||||
import assert from 'assert';
|
||||
import { once } from 'node:events';
|
||||
import * as Rest from './rest';
|
||||
import type { sernConfig } from './utilities/getConfig';
|
||||
import type { SernConfig } from './utilities/getConfig';
|
||||
import type { PublishableData, PublishableModule, Typeable } from './create-publish.d.ts';
|
||||
import { cyanBright, greenBright, redBright } from 'colorette';
|
||||
import { inspect } from 'node:util'
|
||||
import ora from 'ora';
|
||||
import type { TheoreticalEnv } from './types/config';
|
||||
|
||||
async function deriveFileInfo(dir: string, file: string) {
|
||||
const fullPath = join(dir, file);
|
||||
return {
|
||||
fullPath,
|
||||
fileStats: await stat(fullPath),
|
||||
base: basename(file),
|
||||
};
|
||||
}
|
||||
|
||||
function isSkippable(filename: string) {
|
||||
// empty string is for non extension files (directories)
|
||||
const validExtensions = ['.js', '.cjs', '.mts', '.mjs', '.cts', '.ts', ''];
|
||||
return filename[0] === '!' || !validExtensions.includes(extname(filename));
|
||||
}
|
||||
|
||||
async function* readPaths(dir: string, shouldDebug: boolean): AsyncGenerator<string> {
|
||||
try {
|
||||
const files = await readdir(dir);
|
||||
for (const file of files) {
|
||||
const { fullPath, fileStats, base } = await deriveFileInfo(dir, file);
|
||||
|
||||
if (fileStats.isDirectory()) {
|
||||
// TODO: refactor so that i dont repeat myself for files (line 71)
|
||||
if (isSkippable(base)) {
|
||||
if (shouldDebug) console.info(`ignored directory: ${fullPath}`);
|
||||
} else {
|
||||
yield* readPaths(fullPath, shouldDebug);
|
||||
}
|
||||
} else {
|
||||
if (isSkippable(base)) {
|
||||
if (shouldDebug) console.info(`ignored: ${fullPath}`);
|
||||
} else {
|
||||
yield 'file:///' + fullPath;
|
||||
}
|
||||
const files = await readdir(dir, { withFileTypes: true });
|
||||
for (const file of files) {
|
||||
const fullPath = pathpsx.join(dir, file.name);
|
||||
if (file.isDirectory()) {
|
||||
if (!file.name.startsWith('!')) {
|
||||
yield* readPaths(fullPath, shouldDebug);
|
||||
}
|
||||
} else if (!file.name.startsWith('!')) {
|
||||
yield "file:///"+resolve(fullPath);
|
||||
}
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
// recieved sern config
|
||||
const [{ config, preloads, commandDir }] = await once(process, 'message'),
|
||||
{ paths } = config as sernConfig;
|
||||
{ paths } = config as SernConfig;
|
||||
|
||||
for (const preload of preloads) {
|
||||
console.log("preloading: ", preload);
|
||||
await import('file:///' + resolve(preload));
|
||||
}
|
||||
|
||||
@@ -76,21 +52,19 @@ for await (const absPath of filePaths) {
|
||||
commandModule = commandModule.default;
|
||||
}
|
||||
|
||||
if (typeof config === 'function') {
|
||||
config = config(absPath, commandModule);
|
||||
}
|
||||
|
||||
try {
|
||||
commandModule = commandModule.getInstance();
|
||||
} catch {}
|
||||
|
||||
if ((PUBLISHABLE & commandModule.type) != 0) {
|
||||
// assign defaults
|
||||
const filename = basename(absPath);
|
||||
const filenameNoExtension = filename.substring(0, filename.lastIndexOf('.'));
|
||||
commandModule.name ??= filenameNoExtension;
|
||||
commandModule.description ??= '';
|
||||
commandModule.meta = {
|
||||
absPath
|
||||
}
|
||||
commandModule.absPath = absPath;
|
||||
if (typeof config === 'function') {
|
||||
config = config(absPath, commandModule);
|
||||
}
|
||||
modules.push({ commandModule, config });
|
||||
}
|
||||
}
|
||||
@@ -126,6 +100,18 @@ const makeDescription = (type: number, desc: string) => {
|
||||
}
|
||||
return desc;
|
||||
};
|
||||
const serialize = (permissions: unknown) => {
|
||||
if(typeof permissions === 'bigint' || typeof permissions === 'number') {
|
||||
return permissions.toString();
|
||||
}
|
||||
|
||||
if(Array.isArray(permissions)) {
|
||||
return permissions
|
||||
.reduce((acc, cur) => acc | cur, BigInt(0))
|
||||
.toString()
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
const makePublishData = ({ commandModule, config }: Record<string, Record<string, unknown>>) => {
|
||||
const applicationType = intoApplicationType(commandModule.type as number);
|
||||
@@ -136,8 +122,23 @@ const makePublishData = ({ commandModule, config }: Record<string, Record<string
|
||||
description: makeDescription(applicationType, commandModule.description as string),
|
||||
absPath: commandModule.absPath as string,
|
||||
options: optionsTransformer((commandModule?.options ?? []) as Typeable[]),
|
||||
dm_permission: config?.dmPermission,
|
||||
default_member_permissions: config?.defaultMemberPermissions ?? null,
|
||||
dm_permission: config?.dmPermission ?? false,
|
||||
default_member_permissions: serialize(config?.defaultMemberPermissions),
|
||||
//@ts-ignore
|
||||
integration_types: (config?.integrationTypes ?? ['Guild']).map(
|
||||
(s: string) => {
|
||||
if(s === "Guild") {
|
||||
return "0"
|
||||
} else if (s == "User") {
|
||||
return "1"
|
||||
} else {
|
||||
throw Error("IntegrationType is not one of Guild (0) or User (1)");
|
||||
}
|
||||
}),
|
||||
//@ts-ignore
|
||||
contexts: config?.contexts ?? undefined,
|
||||
name_localizations: commandModule.name_localizations,
|
||||
description_localizations: commandModule.description_localizations
|
||||
},
|
||||
config,
|
||||
};
|
||||
@@ -145,12 +146,9 @@ const makePublishData = ({ commandModule, config }: Record<string, Record<string
|
||||
|
||||
// We can use these objects to publish to DAPI
|
||||
const publishableData = modules.map(makePublishData),
|
||||
token = process.env.token || process.env.DISCORD_TOKEN,
|
||||
appid = process.env.applicationId || process.env.APPLICATION_ID;
|
||||
token = process.env.token || process.env.DISCORD_TOKEN;
|
||||
|
||||
assert(token, 'Could not find a token for this bot in .env or commandline. Do you have DISCORD_TOKEN in env?');
|
||||
assert(appid, 'Could not find an application id for this bot in .env or commandline. Do you have APPLICATION_ID in env?');
|
||||
|
||||
// partition globally published and guilded commands
|
||||
const [globalCommands, guildedCommands] = publishableData.reduce(
|
||||
([globals, guilded], module) => {
|
||||
@@ -167,28 +165,40 @@ const spin = ora(`Publishing ${cyanBright('Global')} commands`);
|
||||
|
||||
globalCommands.length && spin.start();
|
||||
|
||||
const rest = Rest.create(appid, token);
|
||||
const rest = await Rest.create(token);
|
||||
const res = await rest.updateGlobal(globalCommands);
|
||||
|
||||
let globalCommandsResponse: unknown;
|
||||
|
||||
|
||||
if (res.ok) {
|
||||
spin.succeed(`All ${cyanBright('Global')} commands published`);
|
||||
globalCommands.length && spin.succeed(`All ${cyanBright('Global')} commands published`);
|
||||
globalCommandsResponse = await res.json();
|
||||
} else {
|
||||
spin.fail(`Failed to publish global commands [Code: ${redBright(res.status)}]`);
|
||||
if (res.status === 429) {
|
||||
throw Error('Chill out homie, too many requests');
|
||||
let err: Error
|
||||
console.error("Status Text ", res.statusText);
|
||||
switch(res.status) {
|
||||
case 400 : {
|
||||
const validation_errors = await res.json()
|
||||
console.error('errors:', inspect(validation_errors, { depth: Infinity }));
|
||||
console.error("Modules with validation errors:"
|
||||
+ inspect(Object.keys(validation_errors.errors).map(idx => globalCommands[idx as any])))
|
||||
throw Error("400: Ensure your commands have proper fields and data with nothing left out");
|
||||
}
|
||||
case 404 : {
|
||||
console.error('errors:', inspect(await res.json(), { depth: Infinity }));
|
||||
throw Error("Forbidden 404. Is you application id and/or token correct?")
|
||||
}
|
||||
case 429: {
|
||||
console.error('errors:', inspect(await res.json(), { depth: Infinity }));
|
||||
err = Error('Chill out homie, too many requests')
|
||||
} break;
|
||||
default: {
|
||||
console.error('errors:', inspect(await res.json(), { depth: Infinity }));
|
||||
throw Error(res.status.toString() + " error")
|
||||
}
|
||||
}
|
||||
console.error(
|
||||
'errors:',
|
||||
await res.json().then((res) => {
|
||||
const errors = Object.values(res.errors);
|
||||
// @ts-ignore
|
||||
return errors.map((err) => err?.name?._errors);
|
||||
})
|
||||
);
|
||||
console.error(res.statusText);
|
||||
}
|
||||
|
||||
function associateGuildIdsWithData(data: PublishableModule[]): Map<string, PublishableData[]> {
|
||||
@@ -208,11 +218,9 @@ function associateGuildIdsWithData(data: PublishableModule[]): Map<string, Publi
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return guildIdMap;
|
||||
}
|
||||
const guildCommandMap = associateGuildIdsWithData(guildedCommands);
|
||||
|
||||
let guildCommandMapResponse = new Map<string, Record<string, unknown>>();
|
||||
|
||||
for (const [guildId, array] of guildCommandMap.entries()) {
|
||||
@@ -227,14 +235,29 @@ for (const [guildId, array] of guildCommandMap.entries()) {
|
||||
spin.succeed(`[${greenBright(guildId)}] Successfully updated commands for guild`);
|
||||
} else {
|
||||
spin.fail(`[${redBright(guildId)}] Failed to update commands for guild, Reason: ${result.message}`);
|
||||
throw Error(result.message);
|
||||
switch(response.status) {
|
||||
case 400 : {
|
||||
console.error(inspect(result, { depth: Infinity }))
|
||||
console.error("Modules with validation errors:"
|
||||
+ inspect(Object.keys(result.errors).map(idx => array[idx as any])))
|
||||
|
||||
throw Error("400: Ensure your commands have proper fields and data and nothing left out");
|
||||
}
|
||||
case 404 : {
|
||||
console.error(inspect(result, { depth: Infinity }))
|
||||
throw Error("Forbidden 404. Is you application id and/or token correct?")
|
||||
}
|
||||
case 429: {
|
||||
console.error(inspect(result, { depth: Infinity }))
|
||||
throw Error('Chill out homie, too many requests')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const remoteData = {
|
||||
global: globalCommandsResponse,
|
||||
...Object.fromEntries(guildCommandMapResponse),
|
||||
};
|
||||
|
||||
await writeFile(resolve(cacheDir, 'command-data-remote.json'), JSON.stringify(remoteData, null, 4), 'utf8');
|
||||
|
||||
// TODO: add this in a verbose flag
|
||||
|
||||
19
src/index.ts
19
src/index.ts
@@ -23,7 +23,7 @@ program
|
||||
program
|
||||
.command('plugins')
|
||||
.description('Install plugins from https://github.com/sern-handler/awesome-plugins')
|
||||
.option('-n --name', 'Name of plugin')
|
||||
.argument('[names...]', 'Names of plugins to install')
|
||||
.action((...args) => importDynamic('plugins.js').then((m) => m.plugins(...args)));
|
||||
|
||||
program
|
||||
@@ -40,23 +40,26 @@ program //
|
||||
.option('-W --suppress-warnings', 'suppress experimental warning')
|
||||
.option('-i, --import [scriptPath...]', 'Prerequire a script to load into publisher')
|
||||
.option('-t, --token [token]')
|
||||
.option('--appId [applicationId]')
|
||||
.argument('[path]', 'path with respect to current working directory that will locate all published files')
|
||||
.action(async (...args) => importDynamic('publish.js').then((m) => m.publish(...args)))
|
||||
)
|
||||
.addCommand(
|
||||
).addCommand(
|
||||
new Command('list') //
|
||||
.description('List all slash commands')
|
||||
.action(async (...args) => importDynamic('list.js').then((m) => m.list(...args)))
|
||||
);
|
||||
|
||||
.action(async (...args) => importDynamic('list.js').then((m) => m.list(...args))))
|
||||
.addCommand(
|
||||
new Command('clear')
|
||||
.description('Clear and reset commands-data-remote.json and the api')
|
||||
.option('-y, --yes', "Say yes to all prompts")
|
||||
.option('-e, --env [path]', "Supply a path to a .env")
|
||||
.action(async (...args) => importDynamic('command-clear.js').then((m) => m.commandClear(...args))));
|
||||
program
|
||||
.command('build')
|
||||
.description('Build your bot')
|
||||
.option('-f --format [fmt]', 'The module system of your application. `cjs` or `esm`', 'esm')
|
||||
.option('-m --mode [mode]', 'the mode for sern to build in. `production` or `development`', 'development')
|
||||
.option('-w --watch')
|
||||
.option('-W --suppress-warnings', 'suppress experimental warning')
|
||||
.option('-p --project [filePath]', 'build with this sern.build file')
|
||||
.option('-p --project [filePath]', 'build with the provided sern.build file')
|
||||
.option('-e --env', 'path to .env file')
|
||||
.option('--tsconfig [filePath]', 'Use this tsconfig')
|
||||
.action(async (...args) => importDynamic('build.js').then((m) => m.build(...args)));
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
import fs from 'fs/promises';
|
||||
import path from 'node:path';
|
||||
import { require } from '../utilities/require.js';
|
||||
import { type Plugin } from 'esbuild';
|
||||
import { basename } from 'node:path';
|
||||
|
||||
export const validExtensions = ['.ts', '.js', '.json', '.png', '.jpg', '.jpeg', '.webp'];
|
||||
|
||||
//https://github.com/evanw/esbuild/issues/1051
|
||||
export const imageLoader = {
|
||||
name: 'attachment-loader',
|
||||
setup: (b) => {
|
||||
const filter = new RegExp(`\.${validExtensions.slice(3).join('|')}$`);
|
||||
b.onResolve({ filter }, (args) => {
|
||||
//if the module is being imported, resolve the path and transform to the js stub
|
||||
if (args.importer) {
|
||||
const newPath = path
|
||||
.format({ ...path.parse(args.path), base: '', ext: '.js' })
|
||||
.split(path.sep)
|
||||
.join(path.posix.sep);
|
||||
return { path: newPath, namespace: 'attachment-loader', external: true };
|
||||
}
|
||||
// if the file is actually the attachment, resolve the full dir
|
||||
return { path: require.resolve(args.path, { paths: [args.resolveDir] }), namespace: 'attachment-loader' };
|
||||
});
|
||||
|
||||
b.onLoad({ filter: /.*/, namespace: 'attachment-loader' }, async (args) => {
|
||||
const base64 = await fs.readFile(args.path).then((s) => s.toString('base64'));
|
||||
return {
|
||||
contents: `
|
||||
var __toBuffer = (base64) => Buffer.from(base64, "base64");
|
||||
module.exports = {
|
||||
name: '${basename(args.path)}',
|
||||
attachment: __toBuffer("${base64}")
|
||||
}`,
|
||||
};
|
||||
});
|
||||
},
|
||||
} satisfies Plugin;
|
||||
@@ -1,31 +0,0 @@
|
||||
import type { Choice, PromptObject } from 'prompts';
|
||||
import { fetch } from 'undici';
|
||||
|
||||
async function gimmechoices(): Promise<Choice[]> {
|
||||
const link = `https://raw.githubusercontent.com/sern-handler/awesome-plugins/main/pluginlist.json`;
|
||||
|
||||
const resp = await fetch(link).catch(() => null);
|
||||
if (!resp) return [{ title: 'No plugins found!', value: '', disabled: true }];
|
||||
const data = (await resp.json()) as Data[];
|
||||
const choices = data.map((e) => ({
|
||||
title: e.name,
|
||||
value: e,
|
||||
}));
|
||||
|
||||
return choices;
|
||||
}
|
||||
|
||||
export async function pluginsQ(): Promise<PromptObject> {
|
||||
return {
|
||||
name: 'list',
|
||||
type: 'autocompleteMultiselect',
|
||||
message: 'What plugins do you want to install?',
|
||||
choices: await gimmechoices(),
|
||||
min: 1,
|
||||
};
|
||||
}
|
||||
|
||||
interface Data {
|
||||
name: string;
|
||||
link: string;
|
||||
}
|
||||
24
src/rest.ts
24
src/rest.ts
@@ -4,19 +4,29 @@ const baseURL = new URL('https://discord.com/api/v10/applications/');
|
||||
|
||||
const excludedKeys = new Set(['command', 'absPath']);
|
||||
|
||||
const publishablesIntoJson = (ps: PublishableModule[]) =>
|
||||
JSON.stringify(
|
||||
const publishablesIntoJson = (ps: PublishableModule[]) => {
|
||||
const s = JSON.stringify(
|
||||
ps.map((module) => module.data),
|
||||
(key, value) => (excludedKeys.has(key) ? undefined : value),
|
||||
4
|
||||
);
|
||||
(key, value) => (excludedKeys.has(key) ? undefined : value), 4);
|
||||
return s;
|
||||
}
|
||||
|
||||
export const create = (appid: string, token: string) => {
|
||||
const globalURL = new URL(`${appid}/commands`, baseURL);
|
||||
export const create = async (token: string) => {
|
||||
const headers = {
|
||||
Authorization: 'Bot ' + token,
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
let me;
|
||||
let appid: string;
|
||||
try {
|
||||
me = await fetch(new URL('@me', baseURL), { headers }).then(res => res.json());
|
||||
appid = me.id;
|
||||
} catch(e) {
|
||||
console.log("Something went wrong while trying to fetch your application:");
|
||||
throw e;
|
||||
}
|
||||
const globalURL = new URL(`${appid}/commands`, baseURL);
|
||||
|
||||
return {
|
||||
updateGlobal: (commands: PublishableModule[]) =>
|
||||
fetch(globalURL, {
|
||||
|
||||
7
src/types/config.d.ts
vendored
7
src/types/config.d.ts
vendored
@@ -4,16 +4,13 @@ export interface sernConfig {
|
||||
base: string;
|
||||
commands: string;
|
||||
};
|
||||
scripts?: {
|
||||
prepublish?: string;
|
||||
};
|
||||
buildPath: string;
|
||||
rest?: Record<string, Record<string, unknown>>;
|
||||
}
|
||||
|
||||
export interface TheoreticalEnv {
|
||||
DISCORD_TOKEN: string;
|
||||
APPLICATION_ID: string;
|
||||
MODE: 'PROD' | 'DEV';
|
||||
APPLICATION_ID?: string;
|
||||
MODE: 'production' | 'environment';
|
||||
[name: string]: string;
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import type esbuild from 'esbuild';
|
||||
import { resolve } from 'path';
|
||||
|
||||
export default (format: 'cjs' | 'esm', tsconfigRaw: unknown) =>
|
||||
({
|
||||
export default (format: 'cjs' | 'esm', tsconfig: string|undefined, outdir='dist') => ({
|
||||
platform: 'node',
|
||||
format,
|
||||
tsconfigRaw: tsconfigRaw as esbuild.TsconfigRaw,
|
||||
tsconfig,
|
||||
logLevel: 'info',
|
||||
minify: false,
|
||||
outdir: resolve('dist'),
|
||||
outdir: resolve(outdir),
|
||||
} satisfies esbuild.BuildOptions);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { findUp } from 'find-up';
|
||||
import { readFile, rename, writeFile } from 'node:fs/promises';
|
||||
import { fromCwd } from './fromCwd.js';
|
||||
import { parseTsConfig } from './parseTsconfig.js';
|
||||
|
||||
/**
|
||||
* It takes a string, finds the package.json file in the directory of the string, and changes the name
|
||||
@@ -61,10 +62,12 @@ export async function editDirs(
|
||||
});
|
||||
|
||||
if (tsconfig) {
|
||||
const output = JSON.parse(await readFile(tsconfig, 'utf8'));
|
||||
const output = await parseTsConfig(tsconfig);
|
||||
if (!output) throw new Error("Can't read your tsconfig.json.");
|
||||
if (!output.compilerOptions) throw new Error("Can't find compilerOptions in your tsconfig.json.");
|
||||
output.compilerOptions.rootDir = srcName;
|
||||
|
||||
// This will strip comments/trailing commas from the tsconfig.json file
|
||||
await writeFile(tsconfig, JSON.stringify(output, null, 2));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import { findUp } from 'find-up';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
import assert from 'node:assert';
|
||||
export async function getConfig(): Promise<sernConfig> {
|
||||
|
||||
|
||||
export async function getConfig(): Promise<SernConfig> {
|
||||
const sernLocation = await findUp('sern.config.json');
|
||||
assert(sernLocation, "Can't find sern.config.json");
|
||||
|
||||
const output = JSON.parse(await readFile(sernLocation, 'utf8')) as sernConfig;
|
||||
const output = JSON.parse(await readFile(sernLocation, 'utf8')) as SernConfig;
|
||||
|
||||
assert(output, "Can't read your sern.config.json.");
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
export interface sernConfig {
|
||||
export interface SernConfig {
|
||||
language: 'typescript' | 'javascript';
|
||||
defaultPrefix?: string;
|
||||
paths: {
|
||||
@@ -20,5 +21,7 @@ export interface sernConfig {
|
||||
commands: string;
|
||||
events?: string;
|
||||
};
|
||||
buildPath: string;
|
||||
build?: {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
import { findUp } from 'find-up';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
|
||||
/**
|
||||
* It finds the sern.config.json file, reads it, and returns the language property
|
||||
* @returns The language of the project.
|
||||
*/
|
||||
export async function getLang(): Promise<'typescript' | 'javascript'> {
|
||||
const sernLocation = await findUp('sern.config.json');
|
||||
|
||||
if (!sernLocation) throw new Error("Can't find sern.config.json");
|
||||
|
||||
const output = JSON.parse(await readFile(sernLocation, 'utf8'));
|
||||
|
||||
if (!output) throw new Error("Can't read your sern.config.json.");
|
||||
|
||||
return output.language;
|
||||
}
|
||||
50
src/utilities/parseTsconfig.ts
Normal file
50
src/utilities/parseTsconfig.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { resolve } from 'node:path';
|
||||
import { readFile } from 'node:fs/promises';
|
||||
|
||||
interface CompilerOptions {
|
||||
target: string;
|
||||
module: string;
|
||||
lib: string[];
|
||||
allowJs: boolean;
|
||||
checkJs: boolean;
|
||||
jsx: string;
|
||||
declaration: boolean;
|
||||
sourceMap: boolean;
|
||||
outDir: string;
|
||||
rootDir: string;
|
||||
strict: boolean;
|
||||
esModuleInterop: boolean;
|
||||
forceConsistentCasingInFileNames: boolean;
|
||||
noEmit: boolean;
|
||||
importHelpers: boolean;
|
||||
isolatedModules: boolean;
|
||||
moduleResolution: string;
|
||||
resolveJsonModule: boolean;
|
||||
noEmitHelpers: boolean;
|
||||
}
|
||||
|
||||
interface TsConfig {
|
||||
compilerOptions: CompilerOptions;
|
||||
files: string[];
|
||||
include: string[];
|
||||
exclude: string[];
|
||||
extends: string;
|
||||
}
|
||||
|
||||
const cleanJson = (json: string) =>
|
||||
json
|
||||
.replace(/\/\/.*$/gm, '')
|
||||
.replace(/\/\*[\s\S]*?\*\//gm, '')
|
||||
.replace(/,\s*([}\]])/g, '$1');
|
||||
|
||||
export const parseTsConfig = async (path: string) => {
|
||||
const absPath = resolve(path);
|
||||
const fileContent = await readFile(absPath, 'utf-8');
|
||||
const cleanContent = cleanJson(fileContent);
|
||||
|
||||
try {
|
||||
return JSON.parse(cleanContent) as Partial<TsConfig>;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
@@ -6,9 +6,9 @@ const processEnvType = (env: NodeJS.ProcessEnv) => {
|
||||
const envBuilder = new StringWriter();
|
||||
|
||||
for (const key of entries) {
|
||||
envBuilder.tab();
|
||||
envBuilder.tab();
|
||||
envBuilder.envField(key);
|
||||
envBuilder.tab()
|
||||
.tab()
|
||||
.envField(key);
|
||||
}
|
||||
return envBuilder.build();
|
||||
};
|
||||
@@ -37,13 +37,14 @@ const writeAmbientFile = async (path: string, define: Record<string, string>, wr
|
||||
|
||||
const writeTsConfig = async (format: 'cjs' | 'esm', configPath: string, fw: FileWriter) => {
|
||||
//maybe better way to do this
|
||||
const target = format === 'esm' ? { target: 'esnext' } : {};
|
||||
const sernTsConfig = {
|
||||
compilerOptions: {
|
||||
moduleResolution: 'node',
|
||||
//module determines top level await. CJS doesn't have that abliity afaik
|
||||
module: format === 'cjs' ? 'node' : 'esnext',
|
||||
moduleResolution: 'node16',
|
||||
strict: true,
|
||||
skipLibCheck: true,
|
||||
...target,
|
||||
target: 'esnext',
|
||||
rootDirs: ['./generated', '../src'],
|
||||
},
|
||||
include: ['./ambient.d.ts', '../src'],
|
||||
@@ -69,6 +70,7 @@ class StringWriter {
|
||||
return this;
|
||||
}
|
||||
envField(key: string) {
|
||||
//if env field has space or parens, wrap key in ""
|
||||
if (/\s|\(|\)/g.test(key)) {
|
||||
this.fileString += `"${key}": string`;
|
||||
} else {
|
||||
|
||||
92
src/utilities/routebuilder.ts
Normal file
92
src/utilities/routebuilder.ts
Normal file
@@ -0,0 +1,92 @@
|
||||
import { readdir, stat } from 'fs/promises';
|
||||
import { basename, join, parse, dirname } from 'path';
|
||||
import assert from 'assert';
|
||||
|
||||
|
||||
/**
|
||||
* Import any module based on the absolute path.
|
||||
* This can accept four types of exported modules
|
||||
* commonjs, javascript :
|
||||
* ```js
|
||||
* exports = commandModule({ })
|
||||
*
|
||||
* //or
|
||||
* exports.default = commandModule({ })
|
||||
* ```
|
||||
* esm javascript, typescript, and commonjs typescript
|
||||
* export default commandModule({})
|
||||
*/
|
||||
export async function importModule<T>(absPath: string) {
|
||||
let fileModule = await import(absPath);
|
||||
|
||||
let commandModule = fileModule.default;
|
||||
|
||||
assert(commandModule , `Found no export @ ${absPath}. Forgot to ignore with "!"? (!${basename(absPath)})?`);
|
||||
if ('default' in commandModule ) {
|
||||
commandModule = commandModule.default;
|
||||
}
|
||||
return { module: commandModule } as T;
|
||||
}
|
||||
|
||||
|
||||
export const fmtFileName = (fileName: string) => parse(fileName).name;
|
||||
|
||||
|
||||
export const getfilename = (path: string) => fmtFileName(basename(path));
|
||||
|
||||
|
||||
|
||||
async function deriveFileInfo(dir: string, file: string) {
|
||||
const fullPath = join(dir, file);
|
||||
return { fullPath,
|
||||
fileStats: await stat(fullPath),
|
||||
base: basename(file) };
|
||||
}
|
||||
|
||||
function parseWildcardName(filename: string): string | null {
|
||||
const wildcardMatch = filename.match(/\[(.*?)\]/);
|
||||
return wildcardMatch ? wildcardMatch[1] : null;
|
||||
}
|
||||
|
||||
export class RouteEntry {
|
||||
public import_path: string
|
||||
public filename: string
|
||||
public parent: string
|
||||
public wildcardName: string | null;
|
||||
constructor(public route: string) {
|
||||
this.import_path = "file:///"+route
|
||||
this.filename = getfilename(this.route)
|
||||
this.parent = dirname(this.route);
|
||||
this.wildcardName = parseWildcardName(this.filename);
|
||||
}
|
||||
}
|
||||
|
||||
export interface ReadPathsConfig {
|
||||
dir: string
|
||||
onDir?: (dir: string) => Promise<boolean>|boolean
|
||||
onEntry?: (etry: RouteEntry) => RouteEntry
|
||||
}
|
||||
|
||||
export async function* readPaths(
|
||||
config: ReadPathsConfig
|
||||
): AsyncGenerator<RouteEntry> {
|
||||
const files = await readdir(config.dir);
|
||||
for (const file of files) {
|
||||
const { fullPath, fileStats } = await deriveFileInfo(config.dir, file);
|
||||
if (fileStats.isDirectory()) {
|
||||
if(config.onDir && await config.onDir(fullPath)) {
|
||||
yield* readPaths({ ...config, dir: fullPath });
|
||||
} else {
|
||||
yield* readPaths({ ...config, dir: fullPath });
|
||||
}
|
||||
} else {
|
||||
const nowindowsPath = fullPath.replace(/\\/g, '/');
|
||||
if(config.onEntry) {
|
||||
yield config.onEntry(new RouteEntry(nowindowsPath));
|
||||
} else {
|
||||
yield new RouteEntry(nowindowsPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
117
templates/cf.js
Normal file
117
templates/cf.js
Normal file
@@ -0,0 +1,117 @@
|
||||
// i got this idea from chooks22
|
||||
"use modules";
|
||||
|
||||
import {
|
||||
InteractionResponseFlags,
|
||||
InteractionType,
|
||||
verifyKey,
|
||||
InteractionResponseType
|
||||
} from 'discord-interactions';
|
||||
//this will import all the modules statically
|
||||
|
||||
class JsonResponse extends Response {
|
||||
constructor(body, init) {
|
||||
const jsonBody = JSON.stringify(body);
|
||||
init = init || {
|
||||
headers: {
|
||||
'content-type': 'application/json;charset=UTF-8',
|
||||
},
|
||||
};
|
||||
super(jsonBody, init);
|
||||
}
|
||||
}
|
||||
|
||||
function createContext(rawcontext) {
|
||||
return rawcontext
|
||||
}
|
||||
async function executeModule(
|
||||
emitter,
|
||||
logger,
|
||||
errHandler,
|
||||
{ module, task, args },
|
||||
) {
|
||||
try {
|
||||
await module.execute(args);
|
||||
//emitter.emit('module.activate', /*resultPayload(PayloadType.Success, module)*/);
|
||||
} catch(e) {
|
||||
throw e
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async function applyPlugins(module, payload) {
|
||||
let success = true;
|
||||
for (const plg of module.onEvent) {
|
||||
const res = await plg.execute(payload);
|
||||
if(!res.isOk()) {
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
const router = Router();
|
||||
|
||||
/**
|
||||
* A simple :wave: hello page to verify the worker is working.
|
||||
*/
|
||||
router.get('/', (request, env) => {
|
||||
return new Response(`👋 ${env.DISCORD_APPLICATION_ID}`);
|
||||
});
|
||||
|
||||
/**
|
||||
* Main route for all requests sent from Discord. All incoming messages will
|
||||
* include a JSON payload described here:
|
||||
* https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
|
||||
*/
|
||||
router.post('/', async (request, env) => {
|
||||
const { isValid, interaction } = await server.verifyDiscordRequest(
|
||||
request,
|
||||
env,
|
||||
);
|
||||
if (!isValid || !interaction) {
|
||||
return new Response('Bad request signature.', { status: 401 });
|
||||
}
|
||||
|
||||
if (interaction.type === InteractionType.PING) {
|
||||
// The `PING` message is used during the initial webhook handshake, and is
|
||||
// required to configure the webhook in the developer portal.
|
||||
return new JsonResponse({
|
||||
type: InteractionResponseType.PONG,
|
||||
});
|
||||
}
|
||||
if(interaction.type === InteractionType.APPLICATION_COMMAND_AUTOCOMPLETE) {
|
||||
"use autocomplete";
|
||||
} else if (interaction.type === InteractionType.APPLICATION_COMMAND) {
|
||||
"use slash";
|
||||
}
|
||||
|
||||
console.error('Unknown Type');
|
||||
return new JsonResponse({ error: 'Unknown Type' }, { status: 400 });
|
||||
});
|
||||
router.all('*', () => new Response('Not Found.', { status: 404 }));
|
||||
|
||||
|
||||
async function verifyDiscordRequest(request, env) {
|
||||
const signature = request.headers.get('x-signature-ed25519');
|
||||
const timestamp = request.headers.get('x-signature-timestamp');
|
||||
const body = await request.text();
|
||||
const isValidRequest =
|
||||
signature &&
|
||||
timestamp &&
|
||||
verifyKey(body, signature, timestamp, env.DISCORD_PUBLIC_KEY);
|
||||
if (!isValidRequest) {
|
||||
return { isValid: false };
|
||||
}
|
||||
|
||||
return { interaction: JSON.parse(body), isValid: true };
|
||||
}
|
||||
|
||||
|
||||
const server = {
|
||||
verifyDiscordRequest: verifyDiscordRequest,
|
||||
fetch: async function (request, env) {
|
||||
return router.handle(request, env);
|
||||
},
|
||||
};
|
||||
export default server;
|
||||
@@ -1,7 +1,12 @@
|
||||
import { defineConfig } from 'tsup';
|
||||
import { createRequire } from 'node:module';
|
||||
|
||||
const shared = {
|
||||
entry: ['src/index.ts', 'src/create-publish.mts', 'src/commands/**', 'sern-tsconfig.json'],
|
||||
entry: [
|
||||
'src/index.ts',
|
||||
'src/create-publish.mts',
|
||||
'src/commands/**',
|
||||
],
|
||||
clean: true,
|
||||
sourcemap: true,
|
||||
};
|
||||
@@ -18,8 +23,5 @@ export default defineConfig({
|
||||
define: {
|
||||
__VERSION__: `"${createRequire(import.meta.url)('./package.json').version}"`,
|
||||
},
|
||||
loader: {
|
||||
'.json': 'file',
|
||||
},
|
||||
...shared,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user