First Commit
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
export default function exitWithError(msg: string, code?: number) {
|
||||
console.error(msg);
|
||||
process.exit(code || 1);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
const AppNames = {
|
||||
defaultPort: 7000,
|
||||
defaultAssetPrefix: "_bunext/static",
|
||||
name: "Bunext",
|
||||
defaultDistDir: ".bunext",
|
||||
} as const;
|
||||
|
||||
export default AppNames;
|
||||
@@ -0,0 +1,16 @@
|
||||
import AppNames from "./grab-app-names";
|
||||
import numberfy from "./numberfy";
|
||||
|
||||
export default function grabAppPort() {
|
||||
if (process.env.PORT) {
|
||||
return numberfy(process.env.PORT);
|
||||
}
|
||||
|
||||
if (global.CONFIG.port) {
|
||||
return global.CONFIG.port;
|
||||
}
|
||||
|
||||
const { defaultPort } = AppNames;
|
||||
|
||||
return numberfy(defaultPort);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import AppNames from "./grab-app-names";
|
||||
|
||||
export default function grabAssetsPrefix() {
|
||||
if (global.CONFIG.assetsPrefix) {
|
||||
return global.CONFIG.assetsPrefix;
|
||||
}
|
||||
|
||||
const { defaultAssetPrefix } = AppNames;
|
||||
|
||||
return defaultAssetPrefix;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import path from "path";
|
||||
|
||||
type Params = {
|
||||
dir?: string;
|
||||
};
|
||||
|
||||
export default function grabDirNames(params?: Params) {
|
||||
const rootDir = params?.dir || process.cwd();
|
||||
const appDir = path.resolve(__dirname, "..");
|
||||
const entrypoint = path.join(
|
||||
appDir,
|
||||
"functions",
|
||||
"server",
|
||||
"start-server.ts"
|
||||
);
|
||||
|
||||
const pagesDir = path.join(rootDir, "pages");
|
||||
const componentsDir = path.join(rootDir, "components");
|
||||
const publicDir = path.join(rootDir, "public");
|
||||
const stylesDir = path.join(rootDir, "styles");
|
||||
const utilsDir = path.join(rootDir, "utils");
|
||||
const typesDir = path.join(rootDir, "types");
|
||||
const configFile = path.join(rootDir, "bunext.config.ts");
|
||||
|
||||
return {
|
||||
rootDir,
|
||||
pagesDir,
|
||||
componentsDir,
|
||||
publicDir,
|
||||
stylesDir,
|
||||
utilsDir,
|
||||
typesDir,
|
||||
configFile,
|
||||
appDir,
|
||||
entrypoint,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import grabAppPort from "./grab-app-port";
|
||||
|
||||
export default function grabOrigin() {
|
||||
if (global.CONFIG.origin) {
|
||||
return global.CONFIG.origin;
|
||||
}
|
||||
|
||||
const port = grabAppPort();
|
||||
|
||||
return `http://localhost:${port}`;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
export default function numberfy(num: any, decimals?: number): number {
|
||||
try {
|
||||
const numberString = String(num)
|
||||
.replace(/[^0-9\.]/g, "")
|
||||
.replace(/\.$/, "");
|
||||
|
||||
if (!numberString.match(/./)) return 0;
|
||||
|
||||
const existingDecimals = numberString.match(/\./)
|
||||
? numberString.split(".").pop()?.length
|
||||
: undefined;
|
||||
|
||||
const numberfiedNum = Number(numberString);
|
||||
|
||||
if (typeof numberfiedNum !== "number") return 0;
|
||||
if (isNaN(numberfiedNum)) return 0;
|
||||
|
||||
if (decimals == 0) {
|
||||
return Math.round(Number(numberfiedNum));
|
||||
} else if (decimals) {
|
||||
return Number(numberfiedNum.toFixed(decimals));
|
||||
}
|
||||
|
||||
if (existingDecimals)
|
||||
return Number(numberfiedNum.toFixed(existingDecimals));
|
||||
return Math.round(numberfiedNum);
|
||||
} catch (error: any) {
|
||||
console.log(`Numberfy ERROR: ${error.message}`);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
export const _n = numberfy;
|
||||
Reference in New Issue
Block a user