@stacksjs/utils 0.74.3 → 0.74.5

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.
package/dist/helpers.d.ts CHANGED
@@ -5,7 +5,6 @@ import type { Result } from '@stacksjs/error-handling';
5
5
  // Bun has native YAML support via Bun.YAML
6
6
  // import { semver } from './versions'
7
7
  export declare function packageManager(): Promise<string>;
8
- export declare function initProject(): Promise<Result<Subprocess, Error>>;
9
8
  export declare function ensureProjectIsInitialized(): Promise<boolean>;
10
9
  /**
11
10
  * Determines whether the current working directory is a Stacks project.
package/dist/helpers.js CHANGED
@@ -1,4 +1,4 @@
1
- import process from"node:process";import{runAction}from"@stacksjs/actions";import{log,runCommand}from"@stacksjs/cli";import{app,ui}from"@stacksjs/config";import{Action}from"@stacksjs/enums";import{err,handleError,ok}from"@stacksjs/error-handling";import{frameworkPath,projectPath}from"@stacksjs/path";import{fs,readJsonFile,readPackageJson,readTextFile,writeTextFile}from"@stacksjs/storage";export async function packageManager(){const{packageManager}=await readPackageJson(frameworkPath("package.json"));return packageManager??""}export async function initProject(){if(app.env!=="production")log.info("Project not yet initialized, generating application key...");else handleError("Please run `buddy key:generate` to generate an application key");const result=await runAction(Action.KeyGenerate,{cwd:projectPath()});if(result.isErr)return err(handleError(result.error));log.info("Application key generated.");return ok(result.value)}export async function ensureProjectIsInitialized(){if(!isStacksProject()){console.error("This command must be run inside a Stacks project; create one with: panx @stacksjs/buddy new my-app");process.exit(1)}if(await isAppKeySet())return!0;if(fs.existsSync(projectPath(".env")))return!1;if(fs.existsSync(projectPath(".env.example")))fs.copyFileSync(projectPath(".env.example"),projectPath(".env"));else console.error("no .env.example file found");return await isAppKeySet()}export function isStacksProject(){if(!fs.existsSync(projectPath("package.json")))return!1;return fs.existsSync(projectPath("config"))||fs.existsSync(projectPath("storage/framework/core"))}export async function installIfVersionMismatch(){}export async function frameworkVersion(){return(await readPackageJson(frameworkPath("package.json"))).version??""}export async function isAppKeySet(){if(String(process.env.APP_KEY??"").trim().length>16)return!0;try{const appKey=(await readTextFile(".env",projectPath())).data.split(`
1
+ import process from"node:process";import{runCommand}from"@stacksjs/cli";import{app,ui}from"@stacksjs/config";import{err,handleError}from"@stacksjs/error-handling";import{frameworkPath,projectPath}from"@stacksjs/path";import{fs,readJsonFile,readPackageJson,readTextFile,writeTextFile}from"@stacksjs/storage";export async function packageManager(){const{packageManager}=await readPackageJson(frameworkPath("package.json"));return packageManager??""}export async function ensureProjectIsInitialized(){if(!isStacksProject()){console.error("This command must be run inside a Stacks project; create one with: panx @stacksjs/buddy new my-app");process.exit(1)}if(await isAppKeySet())return!0;if(fs.existsSync(projectPath(".env")))return!1;if(fs.existsSync(projectPath(".env.example")))fs.copyFileSync(projectPath(".env.example"),projectPath(".env"));else console.error("no .env.example file found");return await isAppKeySet()}export function isStacksProject(){if(!fs.existsSync(projectPath("package.json")))return!1;return fs.existsSync(projectPath("config"))||fs.existsSync(projectPath("storage/framework/core"))}export async function installIfVersionMismatch(){}export async function frameworkVersion(){return(await readPackageJson(frameworkPath("package.json"))).version??""}export async function isAppKeySet(){if(String(process.env.APP_KEY??"").trim().length>16)return!0;try{const appKey=(await readTextFile(".env",projectPath())).data.split(`
2
2
  `).find((line)=>line.startsWith("APP_KEY="));return!!(appKey&&appKey.length>16)}catch{return!1}}export function determineResetPreset(preset){if(preset===void 0&&ui.reset)preset=ui.reset;if(preset===null)return[];const resetImport={tailwind:'import { tailwindPreflight as reset } from "@cwcss/crosswind"',preflight:'import { tailwindPreflight as reset } from "@cwcss/crosswind"',forms:'import { tailwindFormsPreflight as reset } from "@cwcss/crosswind"'}[preset??"tailwind"];return resetImport?[resetImport]:[]}export function isManifest(obj){if(!obj||typeof obj!=="object")return!1;const candidate=obj;return isOptionalString(candidate.name)&&isOptionalString(candidate.version)&&isOptionalString(candidate.description)}export function isOptionalString(value){const type=typeof value;return value===null||type==="undefined"||type==="string"}export async function setEnvValue(key,value){const file=await readTextFile(projectPath(".env")),escapedKey=key.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),keyPattern=new RegExp(`^${escapedKey}=.*$`,"m"),nextValue=`${key}=${value}`,data=keyPattern.test(file.data)?file.data.replace(keyPattern,nextValue):`${file.data}${file.data.endsWith(`
3
3
  `)?"":`
4
4
  `}${nextValue}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/utils",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.74.3",
5
+ "version": "0.74.5",
6
6
  "description": "The Stacks helper functions.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -62,21 +62,20 @@
62
62
  "size": "bun scripts/export-size.ts"
63
63
  },
64
64
  "dependencies": {
65
- "@stacksjs/actions": "0.74.3",
66
- "@stacksjs/browser": "0.74.3",
67
- "@stacksjs/cli": "0.74.3",
68
- "@stacksjs/config": "0.74.3",
69
- "@stacksjs/enums": "0.74.3",
70
- "@stacksjs/error-handling": "0.74.3",
71
- "@stacksjs/logging": "0.74.3",
72
- "@stacksjs/path": "0.74.3",
73
- "@stacksjs/storage": "0.74.3",
74
- "@stacksjs/strings": "0.74.3",
75
- "@stacksjs/types": "0.74.3"
65
+ "@stacksjs/browser": "0.74.5",
66
+ "@stacksjs/cli": "0.74.5",
67
+ "@stacksjs/config": "0.74.5",
68
+ "@stacksjs/enums": "0.74.5",
69
+ "@stacksjs/error-handling": "0.74.5",
70
+ "@stacksjs/logging": "0.74.5",
71
+ "@stacksjs/path": "0.74.5",
72
+ "@stacksjs/storage": "0.74.5",
73
+ "@stacksjs/strings": "0.74.5",
74
+ "@stacksjs/types": "0.74.5"
76
75
  },
77
76
  "devDependencies": {
78
- "@stacksjs/arrays": "0.74.3",
79
- "@stacksjs/lint": "0.74.3",
77
+ "@stacksjs/arrays": "0.74.5",
78
+ "@stacksjs/lint": "0.74.5",
80
79
  "better-dx": "^0.2.24",
81
80
  "filesize": "^11.0.22",
82
81
  "markdown-table": "^3.0.4"