@stacksjs/utils 0.38.3
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/LICENSE.md +21 -0
- package/dist/helpers.d.ts +32 -0
- package/dist/helpers.mjs +74 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.mjs +5 -0
- package/package.json +71 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Open Web Foundation
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type CliOptions, type Manifest, type NpmScript } from '@stacksjs/types';
|
|
2
|
+
export declare function isProjectCreated(): Promise<boolean>;
|
|
3
|
+
export declare function readVersion(): Promise<any>;
|
|
4
|
+
export declare function isAppKeySet(): Promise<boolean>;
|
|
5
|
+
/**
|
|
6
|
+
* Determines the utilized reset preset.
|
|
7
|
+
*
|
|
8
|
+
* @url https://www.npmjs.com/package/@unocss/reset
|
|
9
|
+
* @param preset
|
|
10
|
+
*/
|
|
11
|
+
export declare function determineResetPreset(preset?: string): string[];
|
|
12
|
+
export declare function env(key?: string, fallback?: any): any;
|
|
13
|
+
export declare function config(key?: string, fallback?: string): void;
|
|
14
|
+
/**
|
|
15
|
+
* Determines whether the specified value is a package manifest.
|
|
16
|
+
*/
|
|
17
|
+
export declare function isManifest(obj: any): obj is Manifest;
|
|
18
|
+
/**
|
|
19
|
+
* Determines whether the specified value is a string, null, or undefined.
|
|
20
|
+
*/
|
|
21
|
+
export declare function isOptionalString(value: any): value is string | undefined;
|
|
22
|
+
export declare function setEnvValue(key: string, value: string): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Runs the specified NPM script in the package.json file.
|
|
25
|
+
*/
|
|
26
|
+
export declare function runNpmScript(script: NpmScript, options?: CliOptions): Promise<any>;
|
|
27
|
+
/**
|
|
28
|
+
* Determines whether the specified NPM script exists in the given manifest.
|
|
29
|
+
*/
|
|
30
|
+
export declare function hasScript(manifest: Manifest, script: NpmScript): boolean;
|
|
31
|
+
export * as detectIndent from 'detect-indent';
|
|
32
|
+
export { detectNewline } from 'detect-newline';
|
package/dist/helpers.mjs
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { log, runCommand, spawn } from "@stacksjs/cli";
|
|
2
|
+
import { ExitCode } from "@stacksjs/types";
|
|
3
|
+
import { frameworkPath, projectPath } from "@stacksjs/path";
|
|
4
|
+
import storage from "@stacksjs/storage";
|
|
5
|
+
import { ui } from "@stacksjs/config";
|
|
6
|
+
export async function isProjectCreated() {
|
|
7
|
+
if (storage.isFile(".env"))
|
|
8
|
+
return await isAppKeySet();
|
|
9
|
+
if (storage.isFile(".env.example"))
|
|
10
|
+
await spawn("cp .env.example .env", { stdio: "inherit", cwd: projectPath() });
|
|
11
|
+
return await isAppKeySet();
|
|
12
|
+
}
|
|
13
|
+
export async function readVersion() {
|
|
14
|
+
const packageJson = await storage.fs.readJson(frameworkPath("package.json"));
|
|
15
|
+
return packageJson.version;
|
|
16
|
+
}
|
|
17
|
+
export async function isAppKeySet() {
|
|
18
|
+
const env2 = await storage.readTextFile(".env", projectPath());
|
|
19
|
+
const lines = env2.data.split("\n");
|
|
20
|
+
const appKey = lines.find((line) => line.startsWith("APP_KEY="));
|
|
21
|
+
if (appKey && appKey.length > 16)
|
|
22
|
+
return true;
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
export function determineResetPreset(preset) {
|
|
26
|
+
if (ui.reset)
|
|
27
|
+
preset = ui.reset;
|
|
28
|
+
if (preset === "tailwind")
|
|
29
|
+
return ["import '@unocss/reset/tailwind.css'"];
|
|
30
|
+
if (preset === "normalize")
|
|
31
|
+
return ["import '@unocss/reset/normalize.css'"];
|
|
32
|
+
if (preset === "sanitize")
|
|
33
|
+
return ["import '@unocss/reset/sanitize/sanitize.css'", "import '@unocss/reset/sanitize/assets.css"];
|
|
34
|
+
if (preset === "eric-meyer")
|
|
35
|
+
return ["import '@unocss/reset/eric-meyer.css'"];
|
|
36
|
+
if (preset === "antfu")
|
|
37
|
+
return ["import '@unocss/reset/antfu.css'"];
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
export function env(key, fallback) {
|
|
41
|
+
return fallback;
|
|
42
|
+
}
|
|
43
|
+
export function config(key, fallback) {
|
|
44
|
+
console.log("key", key, "fallback", fallback);
|
|
45
|
+
}
|
|
46
|
+
export function isManifest(obj) {
|
|
47
|
+
return obj && typeof obj === "object" && isOptionalString(obj.name) && isOptionalString(obj.version) && isOptionalString(obj.description);
|
|
48
|
+
}
|
|
49
|
+
export function isOptionalString(value) {
|
|
50
|
+
const type = typeof value;
|
|
51
|
+
return value === null || type === "undefined" || type === "string";
|
|
52
|
+
}
|
|
53
|
+
export async function setEnvValue(key, value) {
|
|
54
|
+
const file = await storage.readTextFile(projectPath(".env"));
|
|
55
|
+
await storage.writeTextFile({
|
|
56
|
+
path: projectPath(".env"),
|
|
57
|
+
data: file.data.replace(/APP_KEY=/g, `APP_KEY=${value}`)
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
export async function runNpmScript(script, options) {
|
|
61
|
+
const { data: manifest } = await storage.readJsonFile("package.json", frameworkPath());
|
|
62
|
+
if (isManifest(manifest) && hasScript(manifest, script))
|
|
63
|
+
return await runCommand(`pnpm run ${script}`, { ...options, cwd: frameworkPath() });
|
|
64
|
+
log.error(`The specified npm script "${script}" does not exist in the package.json file`);
|
|
65
|
+
process.exit(ExitCode.FatalError);
|
|
66
|
+
}
|
|
67
|
+
export function hasScript(manifest, script) {
|
|
68
|
+
const scripts = manifest.scripts;
|
|
69
|
+
if (scripts && typeof scripts === "object")
|
|
70
|
+
return Boolean(scripts[script]);
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
export * as detectIndent from "detect-indent";
|
|
74
|
+
export { detectNewline } from "detect-newline";
|
package/dist/index.d.ts
ADDED
package/dist/index.mjs
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stacksjs/utils",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.38.3",
|
|
5
|
+
"packageManager": "pnpm@7.15.0",
|
|
6
|
+
"description": "The Stacks helper functions.",
|
|
7
|
+
"author": "Chris Breuer",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"funding": "https://github.com/sponsors/chrisbbreuer",
|
|
10
|
+
"homepage": "https://github.com/stacksjs/stacks/tree/main/.stacks/core/helpers#readme",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/stacksjs/stacks.git",
|
|
14
|
+
"directory": "./.stacks/core/helpers"
|
|
15
|
+
},
|
|
16
|
+
"bugs": {
|
|
17
|
+
"url": "https://github.com/stacksjs/stacks/issues"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"objects",
|
|
21
|
+
"strings",
|
|
22
|
+
"arrays",
|
|
23
|
+
"alias",
|
|
24
|
+
"helpers",
|
|
25
|
+
"utilities",
|
|
26
|
+
"functions",
|
|
27
|
+
"stacks"
|
|
28
|
+
],
|
|
29
|
+
"main": "dist/index.mjs",
|
|
30
|
+
"module": "dist/index.mjs",
|
|
31
|
+
"types": "dist/index.d.ts",
|
|
32
|
+
"contributors": [
|
|
33
|
+
"Chris Breuer <chris@ow3.org>"
|
|
34
|
+
],
|
|
35
|
+
"files": [
|
|
36
|
+
"dist",
|
|
37
|
+
"README.md"
|
|
38
|
+
],
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=v18.12.1",
|
|
41
|
+
"pnpm": ">=7.15.0"
|
|
42
|
+
},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"@stacksjs/cli": "0.38.3",
|
|
45
|
+
"@stacksjs/config": "0.38.3",
|
|
46
|
+
"@stacksjs/lint": "0.38.3",
|
|
47
|
+
"@stacksjs/path": "0.38.3",
|
|
48
|
+
"@stacksjs/storage": "0.38.3",
|
|
49
|
+
"@stacksjs/types": "0.38.3",
|
|
50
|
+
"@vueuse/core": "^9.5.0",
|
|
51
|
+
"@vueuse/head": "^0.9.8",
|
|
52
|
+
"@vueuse/math": "^9.5.0",
|
|
53
|
+
"@vueuse/shared": "^9.5.0",
|
|
54
|
+
"defu": "^6.1.0",
|
|
55
|
+
"detect-indent": "^7.0.1",
|
|
56
|
+
"detect-newline": "^4.0.0",
|
|
57
|
+
"esno": "^0.16.3",
|
|
58
|
+
"fast-glob": "^3.2.12",
|
|
59
|
+
"kolorist": "1.6.0",
|
|
60
|
+
"rimraf": "^3.0.2"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"mkdist": "^0.4.0",
|
|
64
|
+
"typescript": "^4.8.4"
|
|
65
|
+
},
|
|
66
|
+
"scripts": {
|
|
67
|
+
"build": "mkdist -d",
|
|
68
|
+
"dev": "mkdist -d",
|
|
69
|
+
"typecheck": "tsc --noEmit"
|
|
70
|
+
}
|
|
71
|
+
}
|