7 Commits

Author SHA1 Message Date
jacob
5c06df12de start watch server 2023-11-07 11:36:24 -06:00
github-actions[bot]
667d0c1b89 chore(main): release 1.0.2 (#125)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2023-11-04 16:20:29 -05:00
Jacob Nguyen
5dbf2a87dc fix: better error handling 2023-11-04 16:14:00 -05:00
a309c085e9 chore: build docs rephrasing (#118)
Co-authored-by: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com>
2023-10-18 13:39:58 -05:00
f1d7d6c911 fix: build mkdir errors (#122)
Co-authored-by: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com>
2023-10-18 13:27:58 -05:00
Jacob Nguyen
4ec96dbe17 Update continuous-integration.yml 2023-10-18 13:18:29 -05:00
Peter-MJ-Parker
3970cc6911 chore: fix grammar in error message (#123) 2023-10-13 22:53:19 +05:30
8 changed files with 94 additions and 67 deletions

View File

@@ -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

View File

@@ -2,6 +2,14 @@
All notable changes to this project will be documented in this file.
## [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)

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "@sern/cli",
"version": "1.0.1",
"version": "1.0.2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@sern/cli",
"version": "1.0.1",
"version": "1.0.2",
"license": "MIT",
"dependencies": {
"@esbuild-kit/cjs-loader": "^2.4.2",

View File

@@ -1,6 +1,6 @@
{
"name": "@sern/cli",
"version": "1.0.1",
"version": "1.0.2",
"description": "Official CLI for @sern/handler",
"exports": "./dist/index.js",
"bin": {

View File

@@ -1,5 +1,5 @@
import esbuild from 'esbuild';
import { getConfig } from '../utilities/getConfig';
import { getConfig, type sernConfig } from '../utilities/getConfig';
import { resolve } from 'node:path';
import { glob } from 'glob';
import { configDotenv } from 'dotenv';
@@ -48,51 +48,58 @@ type BuildOptions = {
env?: string;
};
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');
const resolveBuildConfig = (path: string|undefined, language: string) => {
if(language === 'javascript') {
return path ?? resolve('jsconfig.json')
}
return path ?? resolve('tsconfig.json')
}
/*
* locates jsconfig or tsconfig depending on language.
* If path is not given, default to the current working directory's `(js|ts)config.json`
*/
function resolveConfigPath (path: string|undefined, language: string) {
if(language === 'javascript') {
return path ?? resolve('jsconfig.json')
}
return path ?? resolve('tsconfig.json')
}
async function createBuildConfig(options: Record<string,any>, sernConfig: sernConfig) {
const buildConfigPath = resolve(options.project ?? 'sern.build.js');
const defaultBuildConfig = {
defineVersion: true,
format: options.format ?? 'esm',
mode: options.mode ?? 'development',
dropLabels: [],
tsconfig: resolveBuildConfig(options.tsconfig, sernConfig.language),
esbuildPlugins: [],
tsconfig: resolveConfigPath(options.tsconfig, sernConfig.language),
env: options.env ?? resolve('.env'),
};
if (pathExistsSync(buildConfigPath)) {
try {
buildConfig = {
...defaultBuildConfig,
...(await import('file:///' + buildConfigPath)).default,
};
} catch (e) {
console.log(e);
process.exit(1);
} satisfies BuildOptions;
if(pathExistsSync(buildConfigPath)) {
return {
...defaultBuildConfig,
...(await import('file:///' + buildConfigPath)).default,
}
} else {
buildConfig = {
...defaultBuildConfig,
};
console.log('No build config found, defaulting');
return defaultBuildConfig;
}
}
function fillEnv(options: Record<string, any>) {
let env = {} as Record<string, string>;
configDotenv({ path: buildConfig.env, processEnv: env });
configDotenv({ path: options.env, processEnv: env });
return env;
}
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();
const entryPoints = await glob(`./src/**/*{${validExtensions.join(',')}}`, {
ignore: {
ignored: (p) => p.name.endsWith('.d.ts'),
},
});
const buildConfig = await createBuildConfig(options, sernConfig);
let env = fillEnv(options);
if (env.MODE && !env.NODE_ENV) {
console.warn('Use NODE_ENV instead of MODE');
@@ -105,7 +112,8 @@ export async function build(options: Record<string, any>) {
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`');
assert(buildConfig.mode === 'development'
|| buildConfig.mode === 'production', 'Mode is not `production` or `development`');
try {
@@ -138,7 +146,7 @@ export async function build(options: Record<string, any>) {
if (!(await pathExists(genDir))) {
console.log('Making .sern/generated dir, does not exist');
await mkdir(genDir);
await mkdir(genDir, { recursive: true });
}
try {

5
src/commands/watch.ts Normal file
View File

@@ -0,0 +1,5 @@
import esbuild from 'esbuild'
export async function watch(argv: unknown) {
}

View File

@@ -186,6 +186,7 @@ const res = await rest.updateGlobal(globalCommands);
let globalCommandsResponse: unknown;
if (res.ok) {
globalCommands.length && spin.succeed(`All ${cyanBright('Global')} commands published`);
globalCommandsResponse = await res.json();
@@ -193,21 +194,23 @@ if (res.ok) {
spin.fail(`Failed to publish global commands [Code: ${redBright(res.status)}]`);
switch(res.status) {
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 :
throw Error("Forbidden 404. Is you application id and/or token correct?")
case 429:
throw Error('Chill out homie, too many requests')
}
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('errors:',
await res
.json()
.then((res) => {
const errors = Object.values(res?.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[]> {
@@ -247,7 +250,7 @@ for (const [guildId, array] of guildCommandMap.entries()) {
spin.fail(`[${redBright(guildId)}] Failed to update commands for guild, Reason: ${result.message}`);
switch(response.status) {
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 :
throw Error("Forbidden 404. Is you application id and/or token correct?")
case 429:

View File

@@ -56,9 +56,12 @@ program
.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 --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)));
program
.command('watch')
.description('start a hmr session')
.action(async (...args) => importDynamic('watch.js').then((m) => m.watch(...args)))
program.parse();