stonyx 0.2.3-alpha.30 → 0.2.3-alpha.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,16 @@
1
+ import type { StoynxConfig } from 'stonyx';
2
+
3
+ // project configuration, override-able by listed environment variables
4
+ const {
5
+ DEBUG,
6
+ NODE_ENV,
7
+ } = process.env;
8
+
9
+ const environment = NODE_ENV ?? 'development';
10
+
11
+ const config: StoynxConfig = {
12
+ environment,
13
+ debug: DEBUG ?? environment === 'development',
14
+ };
15
+
16
+ export default config;
package/dist/cli/serve.js CHANGED
@@ -1,5 +1,8 @@
1
+ import { resolve } from 'path';
2
+ import { pathToFileURL } from 'url';
1
3
  import { runStartupHooks, runShutdownHooks } from '../lifecycle.js';
2
4
  import { importConfig } from '../util/import-config.js';
5
+ import { resolveEntryPoint } from '../util/resolve-entry-point.js';
3
6
  export function createShutdownHandler(modules) {
4
7
  let shuttingDown = false;
5
8
  return async () => {
@@ -26,7 +29,8 @@ export function maybeRegisterAppShutdown(modules, appInstance, originalShutdown)
26
29
  export default async function serve({ args }) {
27
30
  const cwd = process.cwd();
28
31
  const entryFlag = args.indexOf('--entry');
29
- const entryPoint = (entryFlag !== -1 && entryFlag + 1 < args.length) ? args[entryFlag + 1] : 'app.js';
32
+ const entryArg = (entryFlag !== -1 && entryFlag + 1 < args.length) ? args[entryFlag + 1] : null;
33
+ const entryPoint = entryArg !== null ? resolve(cwd, entryArg) : resolveEntryPoint(`${cwd}/app`);
30
34
  const config = await importConfig(`${cwd}/config/environment`);
31
35
  const { default: Stonyx } = await import('../main.js');
32
36
  new Stonyx(config, cwd);
@@ -36,7 +40,7 @@ export default async function serve({ args }) {
36
40
  const shutdown = createShutdownHandler(modules);
37
41
  process.on('SIGTERM', shutdown);
38
42
  process.on('SIGINT', shutdown);
39
- const entryModule = await import(`${cwd}/${entryPoint}`);
43
+ const entryModule = await import(pathToFileURL(entryPoint).href);
40
44
  let appInstance;
41
45
  if (entryModule.default) {
42
46
  appInstance = new entryModule.default();
@@ -0,0 +1 @@
1
+ export declare function resolveEntryPoint(basePath: string): string;
@@ -0,0 +1,14 @@
1
+ import { existsSync } from 'fs';
2
+ import { resolve } from 'path';
3
+ const EXTENSIONS = ['ts', 'js'];
4
+ export function resolveEntryPoint(basePath) {
5
+ const matches = EXTENSIONS.filter(ext => existsSync(resolve(`${basePath}.${ext}`)));
6
+ if (matches.length === 0) {
7
+ throw new Error(`Entry point not found: ${basePath}.{ts,js}`);
8
+ }
9
+ if (matches.length > 1) {
10
+ console.warn(`Warning: both ${basePath}.ts and ${basePath}.js exist. Using .ts — delete the .js to silence this warning (it is likely a stale compiled artifact or postinstall stub).`);
11
+ }
12
+ const ext = matches[0];
13
+ return resolve(`${basePath}.${ext}`);
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stonyx",
3
- "version": "0.2.3-alpha.30",
3
+ "version": "0.2.3-alpha.31",
4
4
  "description": "Base stonyx framework module",
5
5
  "main": "dist/main.js",
6
6
  "types": "dist/main.d.ts",
@@ -7,14 +7,31 @@ const { copyFile, createDirectory } = await import('@stonyx/utils/file');
7
7
 
8
8
  const projectDir = process.env.INIT_CWD;
9
9
  const configDir = `${projectDir}/config`;
10
- const envFile = 'environment.js';
11
10
 
12
- // Skip if the consumer ships its own `config/environment copy.js` template —
13
- // they manage their own bootstrap (see abofs/stonyx#54).
14
- if (existsSync(`${configDir}/environment copy.js`)) process.exit(0);
11
+ // Detect consumer project type: presence of `tsconfig.json` in the consumer
12
+ // root signals a TypeScript project (see abofs/stonyx#62). TS consumers can't
13
+ // use the `.js` stub, so we ship both templates and copy the matching one.
14
+ const isTypeScriptConsumer = existsSync(`${projectDir}/tsconfig.json`);
15
+ const extension = isTypeScriptConsumer ? 'ts' : 'js';
16
+ const envFile = `environment.${extension}`;
17
+ const templateFile = `environment copy.${extension}`;
18
+
19
+ // Skip if the consumer ships its own `config/environment copy.{ts,js}` template —
20
+ // they manage their own bootstrap (see abofs/stonyx#54, extended in abofs/stonyx#62
21
+ // to honor either extension).
22
+ if (
23
+ existsSync(`${configDir}/environment copy.ts`) ||
24
+ existsSync(`${configDir}/environment copy.js`)
25
+ ) process.exit(0);
26
+
27
+ // Don't overwrite an existing consumer config (either extension).
28
+ if (
29
+ existsSync(`${configDir}/environment.ts`) ||
30
+ existsSync(`${configDir}/environment.js`)
31
+ ) process.exit(0);
15
32
 
16
33
  createDirectory(configDir);
17
34
 
18
- copyFile(`./config/environment copy.js`, `${configDir}/${envFile}`).then(result => {
35
+ copyFile(`./config/${templateFile}`, `${configDir}/${envFile}`).then(result => {
19
36
  if (result) console.log(`Stonyx: ${envFile} has been successfully created. Please see README.md for more information.`);
20
37
  });