mirror of
https://github.com/sern-handler/cli
synced 2026-06-28 02:32:20 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3f994d6948 | ||
|
|
a5cb66828e | ||
|
|
667d0c1b89 | ||
|
|
5dbf2a87dc | ||
| a309c085e9 | |||
| f1d7d6c911 | |||
|
|
4ec96dbe17 | ||
|
|
3970cc6911 |
28
.github/workflows/continuous-integration.yml
vendored
28
.github/workflows/continuous-integration.yml
vendored
@@ -11,25 +11,25 @@ on:
|
|||||||
- main
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
Lint:
|
# Lint:
|
||||||
name: Linting
|
# name: Linting
|
||||||
runs-on: ubuntu-latest
|
# runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
# steps:
|
||||||
- name: Check out Git repository
|
# - name: Check out Git repository
|
||||||
uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3
|
# uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3
|
||||||
|
|
||||||
- name: Set up Node.js
|
# - name: Set up Node.js
|
||||||
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3
|
# uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3
|
||||||
with:
|
# with:
|
||||||
node-version: 17
|
# node-version: 17
|
||||||
|
|
||||||
# Prettier must be in `package.json`
|
# Prettier must be in `package.json`
|
||||||
- name: Install Node.js dependencies
|
# - name: Install Node.js dependencies
|
||||||
run: npm i
|
# run: npm i
|
||||||
|
|
||||||
- name: Run Prettier
|
# - name: Run Prettier
|
||||||
run: npm run format
|
# run: npm run format
|
||||||
|
|
||||||
Test:
|
Test:
|
||||||
name: Testing
|
name: Testing
|
||||||
|
|||||||
15
CHANGELOG.md
15
CHANGELOG.md
@@ -2,6 +2,21 @@
|
|||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
## [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)
|
## [1.0.1](https://github.com/sern-handler/cli/compare/v1.0.0...v1.0.1) (2023-10-05)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@sern/cli",
|
"name": "@sern/cli",
|
||||||
"version": "1.0.1",
|
"version": "1.0.3",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@sern/cli",
|
"name": "@sern/cli",
|
||||||
"version": "1.0.1",
|
"version": "1.0.3",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@esbuild-kit/cjs-loader": "^2.4.2",
|
"@esbuild-kit/cjs-loader": "^2.4.2",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@sern/cli",
|
"name": "@sern/cli",
|
||||||
"version": "1.0.1",
|
"version": "1.0.3",
|
||||||
"description": "Official CLI for @sern/handler",
|
"description": "Official CLI for @sern/handler",
|
||||||
"exports": "./dist/index.js",
|
"exports": "./dist/index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
|||||||
@@ -54,19 +54,23 @@ export async function build(options: Record<string, any>) {
|
|||||||
}
|
}
|
||||||
const sernConfig = await getConfig();
|
const sernConfig = await getConfig();
|
||||||
let buildConfig: Partial<BuildOptions> = {};
|
let buildConfig: Partial<BuildOptions> = {};
|
||||||
|
|
||||||
const entryPoints = await glob(`./src/**/*{${validExtensions.join(',')}}`, {
|
const entryPoints = await glob(`./src/**/*{${validExtensions.join(',')}}`, {
|
||||||
//for some reason, my ignore glob wasn't registering correctly'
|
//for some reason, my ignore glob wasn't registering correctly'
|
||||||
ignore: {
|
ignore: {
|
||||||
ignored: (p) => p.name.endsWith('.d.ts'),
|
ignored: (p) => p.name.endsWith('.d.ts'),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const buildConfigPath = resolve(options.project ?? 'sern.build.js');
|
const buildConfigPath = resolve(options.project ?? 'sern.build.js');
|
||||||
|
|
||||||
const resolveBuildConfig = (path: string|undefined, language: string) => {
|
const resolveBuildConfig = (path: string|undefined, language: string) => {
|
||||||
if(language === 'javascript') {
|
if(language === 'javascript') {
|
||||||
return path ?? resolve('jsconfig.json')
|
return path ?? resolve('jsconfig.json')
|
||||||
}
|
}
|
||||||
return path ?? resolve('tsconfig.json')
|
return path ?? resolve('tsconfig.json')
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultBuildConfig = {
|
const defaultBuildConfig = {
|
||||||
defineVersion: true,
|
defineVersion: true,
|
||||||
format: options.format ?? 'esm',
|
format: options.format ?? 'esm',
|
||||||
@@ -76,28 +80,23 @@ export async function build(options: Record<string, any>) {
|
|||||||
env: options.env ?? resolve('.env'),
|
env: options.env ?? resolve('.env'),
|
||||||
};
|
};
|
||||||
if (pathExistsSync(buildConfigPath)) {
|
if (pathExistsSync(buildConfigPath)) {
|
||||||
try {
|
//throwable, buildConfigPath may not exist
|
||||||
buildConfig = {
|
|
||||||
...defaultBuildConfig,
|
|
||||||
...(await import('file:///' + buildConfigPath)).default,
|
|
||||||
};
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
buildConfig = {
|
buildConfig = {
|
||||||
...defaultBuildConfig,
|
...defaultBuildConfig,
|
||||||
|
...(await import('file:///' + buildConfigPath)).default,
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
buildConfig = defaultBuildConfig;
|
||||||
console.log('No build config found, defaulting');
|
console.log('No build config found, defaulting');
|
||||||
}
|
}
|
||||||
|
|
||||||
let env = {} as Record<string, string>;
|
let env = {} as Record<string, string>;
|
||||||
configDotenv({ path: buildConfig.env, processEnv: env });
|
configDotenv({ path: buildConfig.env, processEnv: env });
|
||||||
|
const modeButNotNodeEnvExists = env.MODE && !env.NODE_ENV;
|
||||||
if (env.MODE && !env.NODE_ENV) {
|
if (modeButNotNodeEnvExists) {
|
||||||
console.warn('Use NODE_ENV instead of MODE');
|
console.warn('Use NODE_ENV instead of MODE');
|
||||||
console.warn('MODE has no effect.');
|
console.warn('MODE has no effect.');
|
||||||
console.warn(`https://nodejs.dev/en/learn/nodejs-the-difference-between-development-and-production/`);
|
console.warn(`https://nodejs.org/en/learn/getting-started/nodejs-the-difference-between-development-and-production`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (env.NODE_ENV) {
|
if (env.NODE_ENV) {
|
||||||
@@ -110,7 +109,7 @@ export async function build(options: Record<string, any>) {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
let config = require(buildConfig.tsconfig!);
|
let config = require(buildConfig.tsconfig!);
|
||||||
config.extends && console.warn("Please ensure to extend the generated tsconfig")
|
config.extends && console.warn("Extend the generated tsconfig")
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.warn("no tsconfig / jsconfig found");
|
console.warn("no tsconfig / jsconfig found");
|
||||||
console.warn(`Please create a ${sernConfig.language === 'javascript' ? 'jsconfig.json' : 'tsconfig.json' }`);
|
console.warn(`Please create a ${sernConfig.language === 'javascript' ? 'jsconfig.json' : 'tsconfig.json' }`);
|
||||||
@@ -130,15 +129,15 @@ export async function build(options: Record<string, any>) {
|
|||||||
console.log(' ', magentaBright('env'), buildConfig.env);
|
console.log(' ', magentaBright('env'), buildConfig.env);
|
||||||
|
|
||||||
const sernDir = resolve('.sern'),
|
const sernDir = resolve('.sern'),
|
||||||
genDir = resolve(sernDir, 'generated'),
|
genDir = resolve(sernDir, 'generated'),
|
||||||
ambientFilePath = resolve(sernDir, 'ambient.d.ts'),
|
ambientFilePath = resolve(sernDir, 'ambient.d.ts'),
|
||||||
packageJsonPath = resolve('package.json'),
|
packageJsonPath = resolve('package.json'),
|
||||||
sernTsConfigPath = resolve(sernDir, 'tsconfig.json'),
|
sernTsConfigPath = resolve(sernDir, 'tsconfig.json'),
|
||||||
packageJson = () => require(packageJsonPath);
|
packageJson = () => require(packageJsonPath);
|
||||||
|
|
||||||
if (!(await pathExists(genDir))) {
|
if (!(await pathExists(genDir))) {
|
||||||
console.log('Making .sern/generated dir, does not exist');
|
console.log('Making .sern/generated dir, does not exist');
|
||||||
await mkdir(genDir);
|
await mkdir(genDir, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -186,6 +186,7 @@ const res = await rest.updateGlobal(globalCommands);
|
|||||||
|
|
||||||
let globalCommandsResponse: unknown;
|
let globalCommandsResponse: unknown;
|
||||||
|
|
||||||
|
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
globalCommands.length && spin.succeed(`All ${cyanBright('Global')} commands published`);
|
globalCommands.length && spin.succeed(`All ${cyanBright('Global')} commands published`);
|
||||||
globalCommandsResponse = await res.json();
|
globalCommandsResponse = await res.json();
|
||||||
@@ -193,21 +194,23 @@ if (res.ok) {
|
|||||||
spin.fail(`Failed to publish global commands [Code: ${redBright(res.status)}]`);
|
spin.fail(`Failed to publish global commands [Code: ${redBright(res.status)}]`);
|
||||||
switch(res.status) {
|
switch(res.status) {
|
||||||
case 400 :
|
case 400 :
|
||||||
throw Error("400: Ensure your commands have proper fields and data with left nothing out");
|
throw Error("400: Ensure your commands have proper fields and data with nothing left out");
|
||||||
case 404 :
|
case 404 :
|
||||||
throw Error("Forbidden 404. Is you application id and/or token correct?")
|
throw Error("Forbidden 404. Is you application id and/or token correct?")
|
||||||
case 429:
|
case 429:
|
||||||
throw Error('Chill out homie, too many requests')
|
throw Error('Chill out homie, too many requests')
|
||||||
}
|
}
|
||||||
console.error(
|
console.error('errors:',
|
||||||
'errors:',
|
await res
|
||||||
await res.json().then((res) => {
|
.json()
|
||||||
const errors = Object.values(res.errors);
|
.then((res) => {
|
||||||
// @ts-ignore
|
const errors = Object.values(res?.errors ?? {});
|
||||||
return errors.map((err) => err?.name?._errors);
|
// @ts-ignore
|
||||||
})
|
return errors.map((err) => err?.name?._errors);
|
||||||
|
})
|
||||||
|
.catch(() => "No errors found (Unparsable json for a request with bad status code). Read the status code.")
|
||||||
);
|
);
|
||||||
console.error(res.statusText);
|
console.error("Status Text ", res.statusText);
|
||||||
}
|
}
|
||||||
|
|
||||||
function associateGuildIdsWithData(data: PublishableModule[]): Map<string, PublishableData[]> {
|
function associateGuildIdsWithData(data: PublishableModule[]): Map<string, PublishableData[]> {
|
||||||
@@ -247,7 +250,7 @@ for (const [guildId, array] of guildCommandMap.entries()) {
|
|||||||
spin.fail(`[${redBright(guildId)}] Failed to update commands for guild, Reason: ${result.message}`);
|
spin.fail(`[${redBright(guildId)}] Failed to update commands for guild, Reason: ${result.message}`);
|
||||||
switch(response.status) {
|
switch(response.status) {
|
||||||
case 400 :
|
case 400 :
|
||||||
throw Error("400: Ensure your commands have proper fields and data and left nothing out");
|
throw Error("400: Ensure your commands have proper fields and data and nothing left out");
|
||||||
case 404 :
|
case 404 :
|
||||||
throw Error("Forbidden 404. Is you application id and/or token correct?")
|
throw Error("Forbidden 404. Is you application id and/or token correct?")
|
||||||
case 429:
|
case 429:
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ program
|
|||||||
.option('-f --format [fmt]', 'The module system of your application. `cjs` or `esm`', 'esm')
|
.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('-m --mode [mode]', 'the mode for sern to build in. `production` or `development`', 'development')
|
||||||
.option('-W --suppress-warnings', 'suppress experimental warning')
|
.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('-e --env', 'path to .env file')
|
||||||
.option('--tsconfig [filePath]', 'Use this tsconfig')
|
.option('--tsconfig [filePath]', 'Use this tsconfig')
|
||||||
.action(async (...args) => importDynamic('build.js').then((m) => m.build(...args)));
|
.action(async (...args) => importDynamic('build.js').then((m) => m.build(...args)));
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ const processEnvType = (env: NodeJS.ProcessEnv) => {
|
|||||||
const envBuilder = new StringWriter();
|
const envBuilder = new StringWriter();
|
||||||
|
|
||||||
for (const key of entries) {
|
for (const key of entries) {
|
||||||
envBuilder.tab();
|
envBuilder.tab()
|
||||||
envBuilder.tab();
|
.tab()
|
||||||
envBuilder.envField(key);
|
.envField(key);
|
||||||
}
|
}
|
||||||
return envBuilder.build();
|
return envBuilder.build();
|
||||||
};
|
};
|
||||||
@@ -40,6 +40,8 @@ const writeTsConfig = async (format: 'cjs' | 'esm', configPath: string, fw: File
|
|||||||
const target = format === 'esm' ? { target: 'esnext' } : {};
|
const target = format === 'esm' ? { target: 'esnext' } : {};
|
||||||
const sernTsConfig = {
|
const sernTsConfig = {
|
||||||
compilerOptions: {
|
compilerOptions: {
|
||||||
|
//module determines top level await. CJS doesn't have that abliity afaik
|
||||||
|
module: format === 'cjs' ? 'node' : 'esnext',
|
||||||
moduleResolution: 'node',
|
moduleResolution: 'node',
|
||||||
strict: true,
|
strict: true,
|
||||||
skipLibCheck: true,
|
skipLibCheck: true,
|
||||||
@@ -69,6 +71,7 @@ class StringWriter {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
envField(key: string) {
|
envField(key: string) {
|
||||||
|
//if env field has space or parens, wrap key in ""
|
||||||
if (/\s|\(|\)/g.test(key)) {
|
if (/\s|\(|\)/g.test(key)) {
|
||||||
this.fileString += `"${key}": string`;
|
this.fileString += `"${key}": string`;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user