mirror of
https://github.com/sern-handler/cli
synced 2026-06-08 00:42:25 +00:00
Compare commits
2 Commits
feat/watch
...
v1.0.3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3f994d6948 | ||
|
|
a5cb66828e |
@@ -2,6 +2,13 @@
|
||||
|
||||
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)
|
||||
|
||||
|
||||
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@sern/cli",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.3",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@sern/cli",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.3",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@esbuild-kit/cjs-loader": "^2.4.2",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@sern/cli",
|
||||
"version": "1.0.2",
|
||||
"version": "1.0.3",
|
||||
"description": "Official CLI for @sern/handler",
|
||||
"exports": "./dist/index.js",
|
||||
"bin": {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import esbuild from 'esbuild';
|
||||
import { getConfig, type sernConfig } from '../utilities/getConfig';
|
||||
import { getConfig } from '../utilities/getConfig';
|
||||
import { resolve } from 'node:path';
|
||||
import { glob } from 'glob';
|
||||
import { configDotenv } from 'dotenv';
|
||||
@@ -48,63 +48,55 @@ type BuildOptions = {
|
||||
env?: string;
|
||||
};
|
||||
|
||||
/*
|
||||
* 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: [],
|
||||
esbuildPlugins: [],
|
||||
tsconfig: resolveConfigPath(options.tsconfig, sernConfig.language),
|
||||
env: options.env ?? resolve('.env'),
|
||||
} satisfies BuildOptions;
|
||||
|
||||
if(pathExistsSync(buildConfigPath)) {
|
||||
return {
|
||||
...defaultBuildConfig,
|
||||
...(await import('file:///' + buildConfigPath)).default,
|
||||
}
|
||||
} else {
|
||||
return defaultBuildConfig;
|
||||
}
|
||||
}
|
||||
|
||||
function fillEnv(options: Record<string, any>) {
|
||||
let env = {} as Record<string, string>;
|
||||
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();
|
||||
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 buildConfig = await createBuildConfig(options, sernConfig);
|
||||
let env = fillEnv(options);
|
||||
const buildConfigPath = resolve(options.project ?? 'sern.build.js');
|
||||
|
||||
if (env.MODE && !env.NODE_ENV) {
|
||||
const resolveBuildConfig = (path: string|undefined, language: string) => {
|
||||
if(language === 'javascript') {
|
||||
return path ?? resolve('jsconfig.json')
|
||||
}
|
||||
return path ?? resolve('tsconfig.json')
|
||||
}
|
||||
|
||||
const defaultBuildConfig = {
|
||||
defineVersion: true,
|
||||
format: options.format ?? 'esm',
|
||||
mode: options.mode ?? 'development',
|
||||
dropLabels: [],
|
||||
tsconfig: resolveBuildConfig(options.tsconfig, sernConfig.language),
|
||||
env: options.env ?? resolve('.env'),
|
||||
};
|
||||
if (pathExistsSync(buildConfigPath)) {
|
||||
//throwable, buildConfigPath may not exist
|
||||
buildConfig = {
|
||||
...defaultBuildConfig,
|
||||
...(await import('file:///' + buildConfigPath)).default,
|
||||
};
|
||||
} else {
|
||||
buildConfig = defaultBuildConfig;
|
||||
console.log('No build config found, defaulting');
|
||||
}
|
||||
|
||||
let env = {} as Record<string, string>;
|
||||
configDotenv({ path: buildConfig.env, processEnv: env });
|
||||
const modeButNotNodeEnvExists = env.MODE && !env.NODE_ENV;
|
||||
if (modeButNotNodeEnvExists) {
|
||||
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/`);
|
||||
console.warn(`https://nodejs.org/en/learn/getting-started/nodejs-the-difference-between-development-and-production`);
|
||||
}
|
||||
|
||||
if (env.NODE_ENV) {
|
||||
@@ -112,13 +104,12 @@ 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 {
|
||||
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) {
|
||||
console.warn("no tsconfig / jsconfig found");
|
||||
console.warn(`Please create a ${sernConfig.language === 'javascript' ? 'jsconfig.json' : 'tsconfig.json' }`);
|
||||
@@ -138,11 +129,11 @@ export async function build(options: Record<string, any>) {
|
||||
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);
|
||||
genDir = resolve(sernDir, 'generated'),
|
||||
ambientFilePath = resolve(sernDir, 'ambient.d.ts'),
|
||||
packageJsonPath = resolve('package.json'),
|
||||
sernTsConfigPath = resolve(sernDir, 'tsconfig.json'),
|
||||
packageJson = () => require(packageJsonPath);
|
||||
|
||||
if (!(await pathExists(genDir))) {
|
||||
console.log('Making .sern/generated dir, does not exist');
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
import esbuild from 'esbuild'
|
||||
|
||||
export async function watch(argv: unknown) {
|
||||
|
||||
}
|
||||
@@ -60,8 +60,5 @@ program
|
||||
.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();
|
||||
|
||||
@@ -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();
|
||||
};
|
||||
@@ -40,6 +40,8 @@ const writeTsConfig = async (format: 'cjs' | 'esm', configPath: string, fw: File
|
||||
const target = format === 'esm' ? { target: 'esnext' } : {};
|
||||
const sernTsConfig = {
|
||||
compilerOptions: {
|
||||
//module determines top level await. CJS doesn't have that abliity afaik
|
||||
module: format === 'cjs' ? 'node' : 'esnext',
|
||||
moduleResolution: 'node',
|
||||
strict: true,
|
||||
skipLibCheck: true,
|
||||
@@ -69,6 +71,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 {
|
||||
|
||||
Reference in New Issue
Block a user