@storm-software/config-tools 1.37.0 → 1.38.1

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.
Files changed (40) hide show
  1. package/CHANGELOG.md +30 -24
  2. package/LICENSE +201 -0
  3. package/README.md +43 -7
  4. package/declarations.d.ts +26 -23
  5. package/index.cjs +72683 -0
  6. package/index.js +72641 -0
  7. package/meta.cjs.json +1 -0
  8. package/meta.esm.json +1 -0
  9. package/package.json +3 -2
  10. package/utilities/chalk.cjs +1610 -0
  11. package/utilities/chalk.js +1606 -0
  12. package/utilities/find-workspace-root.cjs +111 -0
  13. package/utilities/find-workspace-root.js +84 -0
  14. package/utilities/logger.cjs +1785 -0
  15. package/utilities/logger.js +1770 -0
  16. package/.eslintrc.json +0 -37
  17. package/jest.config.ts +0 -3
  18. package/project.json +0 -67
  19. package/src/config-file/get-config-file.ts +0 -69
  20. package/src/config-file/index.ts +0 -1
  21. package/src/create-storm-config.ts +0 -134
  22. package/src/env/get-env.ts +0 -141
  23. package/src/env/index.ts +0 -2
  24. package/src/env/set-env.ts +0 -207
  25. package/src/index.ts +0 -14
  26. package/src/types.ts +0 -45
  27. package/src/utilities/apply-workspace-tokens.ts +0 -83
  28. package/src/utilities/chalk.ts +0 -53
  29. package/src/utilities/correct-paths.ts +0 -12
  30. package/src/utilities/file-path-utils.ts +0 -26
  31. package/src/utilities/find-up.ts +0 -21
  32. package/src/utilities/find-workspace-root.ts +0 -68
  33. package/src/utilities/get-default-config.ts +0 -106
  34. package/src/utilities/get-log-level.ts +0 -64
  35. package/src/utilities/index.ts +0 -10
  36. package/src/utilities/logger.ts +0 -239
  37. package/src/utilities/process-handler.ts +0 -44
  38. package/src/utilities/run.ts +0 -37
  39. package/tsconfig.json +0 -15
  40. package/tsconfig.spec.json +0 -16
package/src/types.ts DELETED
@@ -1,45 +0,0 @@
1
- import type { StormConfig } from "@storm-software/config";
2
-
3
- export type LogLevel = 0 | 10 | 20 | 30 | 35 | 40 | 60 | 70 | 100;
4
- export const LogLevel = {
5
- SILENT: 0 as LogLevel,
6
- FATAL: 10 as LogLevel,
7
- ERROR: 20 as LogLevel,
8
- WARN: 30 as LogLevel,
9
- SUCCESS: 35 as LogLevel,
10
- INFO: 40 as LogLevel,
11
- DEBUG: 60 as LogLevel,
12
- TRACE: 70 as LogLevel,
13
- ALL: 100 as LogLevel
14
- } as const;
15
-
16
- export type LogLevelLabel =
17
- | "silent"
18
- | "fatal"
19
- | "error"
20
- | "warn"
21
- | "info"
22
- | "debug"
23
- | "trace"
24
- | "all";
25
- export const LogLevelLabel = {
26
- SILENT: "silent" as LogLevelLabel,
27
- FATAL: "fatal" as LogLevelLabel,
28
- ERROR: "error" as LogLevelLabel,
29
- WARN: "warn" as LogLevelLabel,
30
- INFO: "info" as LogLevelLabel,
31
- DEBUG: "debug" as LogLevelLabel,
32
- TRACE: "trace" as LogLevelLabel,
33
- ALL: "all" as LogLevelLabel
34
- } as const;
35
-
36
- export interface BaseTokenizerOptions {
37
- workspaceRoot?: string;
38
- config?: StormConfig;
39
- }
40
-
41
- export interface ProjectTokenizerOptions extends BaseTokenizerOptions {
42
- projectRoot?: string;
43
- projectName?: string;
44
- sourceRoot?: string;
45
- }
@@ -1,83 +0,0 @@
1
- import type { BaseTokenizerOptions, ProjectTokenizerOptions } from "../../declarations";
2
- import { findWorkspaceRoot } from "./find-workspace-root";
3
-
4
- export const applyWorkspaceBaseTokens = async (
5
- option: string,
6
- tokenizerOptions: BaseTokenizerOptions
7
- ): Promise<string> => {
8
- let result = option;
9
- if (!result) {
10
- return result;
11
- }
12
-
13
- if (tokenizerOptions) {
14
- const optionKeys = Object.keys(tokenizerOptions);
15
- if (optionKeys.some((optionKey) => result.includes(`{${optionKey}}`))) {
16
- for (const optionKey of optionKeys) {
17
- if (result.includes(`{${optionKey}}`)) {
18
- result = result.replaceAll(`{${optionKey}}`, tokenizerOptions.config?.[optionKey] ?? "");
19
- }
20
- }
21
- }
22
- }
23
- if (tokenizerOptions.config) {
24
- const configKeys = Object.keys(tokenizerOptions.config);
25
- if (configKeys.some((configKey) => result.includes(`{${configKey}}`))) {
26
- for (const configKey of configKeys) {
27
- if (result.includes(`{${configKey}}`)) {
28
- result = result.replaceAll(`{${configKey}}`, tokenizerOptions.config[configKey]);
29
- }
30
- }
31
- }
32
- }
33
-
34
- if (result.includes("{workspaceRoot}")) {
35
- result = result.replaceAll(
36
- "{workspaceRoot}",
37
- tokenizerOptions.workspaceRoot ??
38
- tokenizerOptions.config?.workspaceRoot ??
39
- findWorkspaceRoot()
40
- );
41
- }
42
-
43
- return result;
44
- };
45
-
46
- export const applyWorkspaceProjectTokens = (
47
- option: string,
48
- tokenizerOptions: ProjectTokenizerOptions
49
- ): Promise<string> => {
50
- return applyWorkspaceBaseTokens(option, tokenizerOptions);
51
- };
52
-
53
- export const applyWorkspaceTokens = async <
54
- TConfig extends BaseTokenizerOptions = BaseTokenizerOptions
55
- >(
56
- options: Record<string, any>,
57
- config: TConfig,
58
- tokenizerFn: (option: string, config: TConfig) => string | Promise<string>
59
- ): Promise<Record<string, any>> => {
60
- if (!options) {
61
- return {};
62
- }
63
-
64
- const result: Record<string, any> = {};
65
-
66
- for (const option of Object.keys(options)) {
67
- if (typeof options[option] === "string") {
68
- result[option] = await Promise.resolve(tokenizerFn(options[option], config));
69
- } else if (Array.isArray(options[option])) {
70
- result[option] = await Promise.all(
71
- options[option].map(async (item: any) =>
72
- typeof item === "string" ? await Promise.resolve(tokenizerFn(item, config)) : item
73
- )
74
- );
75
- } else if (typeof options[option] === "object") {
76
- result[option] = await applyWorkspaceTokens(options[option], config, tokenizerFn);
77
- } else {
78
- result[option] = options[option];
79
- }
80
- }
81
-
82
- return result;
83
- };
@@ -1,53 +0,0 @@
1
- import chalk from "chalk";
2
-
3
- export type GetChalkReturn = {
4
- hex: (_: string) => (message?: string) => string | undefined;
5
- bgHex: (_: string) => {
6
- whiteBright: (message?: string) => string | undefined;
7
- };
8
- whiteBright: (message?: string) => string | undefined;
9
- bold: {
10
- hex: (_: string) => (message?: string) => string | undefined;
11
- bgHex: (_: string) => {
12
- whiteBright: (message?: string) => string | undefined;
13
- };
14
- whiteBright: (message?: string) => string | undefined;
15
- };
16
- };
17
-
18
- const chalkDefault: GetChalkReturn = {
19
- hex: (_: string) => (message?: string) => message,
20
- bgHex: (_: string) => ({
21
- whiteBright: (message?: string) => message
22
- }),
23
- whiteBright: (message?: string) => message,
24
- bold: {
25
- hex: (_: string) => (message?: string) => message,
26
- bgHex: (_: string) => ({
27
- whiteBright: (message?: string) => message
28
- }),
29
- whiteBright: (message?: string) => message
30
- }
31
- };
32
-
33
- /**
34
- * Get the chalk instance
35
- *
36
- * @remarks
37
- * Annoying polyfill to temporarily fix the issue with the `chalk` import
38
- *
39
- * @returns The chalk instance
40
- */
41
- export const getChalk = (): GetChalkReturn => {
42
- let _chalk = chalk as GetChalkReturn;
43
- if (
44
- !_chalk?.hex ||
45
- !_chalk?.bold?.hex ||
46
- !_chalk?.bgHex ||
47
- !_chalk?.whiteBright
48
- ) {
49
- _chalk = chalkDefault;
50
- }
51
-
52
- return _chalk;
53
- };
@@ -1,12 +0,0 @@
1
- export const correctPaths = (path?: string): string => {
2
- if (!path) {
3
- return "";
4
- }
5
-
6
- // Handle Windows absolute paths
7
- if (path?.toUpperCase()?.startsWith("C:")) {
8
- return path.replaceAll("/", "\\");
9
- }
10
-
11
- return path.replaceAll("\\", "/");
12
- };
@@ -1,26 +0,0 @@
1
- import { sep } from "node:path";
2
-
3
- export const removeExtension = (filePath?: string): string => {
4
- const result =
5
- !filePath || (filePath.match(/./g) || []).length <= 1
6
- ? "."
7
- : filePath.lastIndexOf(".")
8
- ? filePath.substring(0, filePath.lastIndexOf("."))
9
- : filePath;
10
-
11
- if (result.startsWith("./")) {
12
- return result.substring(2);
13
- }
14
- if (result.startsWith(".") || result.startsWith("/")) {
15
- return result.substring(1);
16
- }
17
-
18
- return result;
19
- };
20
-
21
- export function findFileName(filePath: string): string {
22
- return (
23
- filePath?.split(filePath?.includes(sep) ? sep : filePath?.includes("/") ? "/" : "\\")?.pop() ??
24
- ""
25
- );
26
- }
@@ -1,21 +0,0 @@
1
- import { existsSync } from "node:fs";
2
- import { join } from "node:path";
3
-
4
- const MAX_PATH_SEARCH_DEPTH = 30;
5
- let depth = 0;
6
-
7
- /**
8
- * Gets the nearest "node_modules" folder by walking up from start path.
9
- */
10
- export function findFolderUp(startPath: string, endFileNames: string[]): string | undefined {
11
- const _startPath = startPath ?? process.cwd();
12
-
13
- if (endFileNames.some((endFileName) => existsSync(join(_startPath, endFileName)))) {
14
- return _startPath;
15
- }
16
- if (_startPath !== "/" && depth++ < MAX_PATH_SEARCH_DEPTH) {
17
- const parent = join(_startPath, "..");
18
- return findFolderUp(parent, endFileNames);
19
- }
20
- return undefined;
21
- }
@@ -1,68 +0,0 @@
1
- import { correctPaths } from "./correct-paths";
2
- import { findFolderUp } from "./find-up";
3
-
4
- const rootFiles = [
5
- "storm.json",
6
- "storm.config.js",
7
- "storm.config.ts",
8
- ".storm.json",
9
- ".storm.yaml",
10
- ".storm.yml",
11
- ".storm.js",
12
- ".storm.ts",
13
- "lerna.json",
14
- "nx.json",
15
- "turbo.json",
16
- "npm-workspace.json",
17
- "yarn-workspace.json",
18
- "pnpm-workspace.json",
19
- "npm-workspace.yaml",
20
- "yarn-workspace.yaml",
21
- "pnpm-workspace.yaml",
22
- "npm-workspace.yml",
23
- "yarn-workspace.yml",
24
- "pnpm-workspace.yml",
25
- "npm-lock.json",
26
- "yarn-lock.json",
27
- "pnpm-lock.json",
28
- "npm-lock.yaml",
29
- "yarn-lock.yaml",
30
- "pnpm-lock.yaml",
31
- "npm-lock.yml",
32
- "yarn-lock.yml",
33
- "pnpm-lock.yml",
34
- "bun.lockb"
35
- ];
36
-
37
- /**
38
- * Find the monorepo root directory, searching upwards from `path`.
39
- *
40
- * @param pathInsideMonorepo - The path inside the monorepo to start searching from
41
- * @returns The monorepo root directory
42
- */
43
- export function findWorkspaceRootSafe(pathInsideMonorepo?: string): string | undefined {
44
- if (process.env.STORM_WORKSPACE_ROOT || process.env.NX_WORKSPACE_ROOT_PATH) {
45
- return correctPaths(process.env.STORM_WORKSPACE_ROOT ?? process.env.NX_WORKSPACE_ROOT_PATH);
46
- }
47
-
48
- return correctPaths(findFolderUp(pathInsideMonorepo ?? process.cwd(), rootFiles));
49
- }
50
-
51
- /**
52
- * Find the monorepo root directory, searching upwards from `path`.
53
- *
54
- * @param pathInsideMonorepo - The path inside the monorepo to start searching from
55
- * @returns The monorepo root directory
56
- */
57
- export function findWorkspaceRoot(pathInsideMonorepo?: string): string {
58
- const result = findWorkspaceRootSafe(pathInsideMonorepo);
59
- if (!result) {
60
- throw new Error(
61
- `Cannot find workspace root upwards from known path. Files search list includes: \n${rootFiles.join(
62
- "\n"
63
- )}\nPath: ${pathInsideMonorepo ? pathInsideMonorepo : process.cwd()}`
64
- );
65
- }
66
-
67
- return result;
68
- }
@@ -1,106 +0,0 @@
1
- import { existsSync, readFileSync } from "node:fs";
2
- import { join } from "node:path";
3
- import {
4
- type StormConfig,
5
- type ColorConfig,
6
- StormConfigSchema
7
- } from "@storm-software/config";
8
- import { findWorkspaceRoot } from "./find-workspace-root";
9
-
10
- /**
11
- * Storm theme config values used for styling various workspace elements
12
- */
13
- export const DEFAULT_COLOR_CONFIG: ColorConfig = {
14
- primary: "#1fb2a6",
15
- dark: "#1d232a",
16
- light: "#f4f4f5",
17
- success: "#087f5b",
18
- info: "#0ea5e9",
19
- warning: "#fcc419",
20
- error: "#990000",
21
- fatal: "#7d1a1a"
22
- };
23
-
24
- /**
25
- * Storm Workspace config values used during various dev-ops processes
26
- */
27
- export const DEFAULT_STORM_CONFIG: any = {
28
- name: "storm",
29
- namespace: "storm-software",
30
- license: "Apache License 2.0",
31
- homepage: "https://stormsoftware.com",
32
- owner: "@storm-software/development",
33
- worker: "stormie-bot",
34
- runtimeDirectory: "node_modules/.storm",
35
- cacheDirectory: "node_modules/.cache/storm",
36
- skipCache: false,
37
- packageManager: "npm",
38
- timezone: "America/New_York",
39
- locale: "en-US",
40
- env: "production",
41
- branch: "main",
42
- organization: "storm-software",
43
- ci: true,
44
- configFile: null,
45
- runtimeVersion: "1.0.0",
46
- colors: { ...DEFAULT_COLOR_CONFIG },
47
- extensions: {}
48
- };
49
-
50
- /**
51
- * Get the default Storm config values used during various dev-ops processes
52
- *
53
- * @returns The default Storm config values
54
- */
55
- export const getDefaultConfig = (
56
- config: Partial<StormConfig> = {},
57
- root?: string
58
- ): StormConfig => {
59
- let name = "storm-workspace";
60
- let namespace = "storm-software";
61
- let repository = "https://github.com/storm-software/storm-ops";
62
-
63
- let license = DEFAULT_STORM_CONFIG.license;
64
- let homepage = DEFAULT_STORM_CONFIG.homepage;
65
-
66
- const workspaceRoot = findWorkspaceRoot(root);
67
- if (existsSync(join(workspaceRoot, "package.json"))) {
68
- const file = readFileSync(join(workspaceRoot, "package.json"), {
69
- encoding: "utf-8"
70
- });
71
- if (file) {
72
- const packageJson = JSON.parse(file);
73
-
74
- if (packageJson.name) {
75
- name = packageJson.name;
76
- }
77
- if (packageJson.namespace) {
78
- namespace = packageJson.namespace;
79
- }
80
- if (packageJson.repository?.url) {
81
- repository = packageJson.repository?.url;
82
- }
83
- if (packageJson.license) {
84
- license = packageJson.license;
85
- }
86
- if (packageJson.homepage) {
87
- homepage = packageJson.homepage;
88
- }
89
- }
90
- }
91
-
92
- return StormConfigSchema.parse({
93
- ...(DEFAULT_STORM_CONFIG as Required<StormConfig>),
94
- ...config,
95
- colors: { ...DEFAULT_COLOR_CONFIG, ...config.colors },
96
- workspaceRoot,
97
- name,
98
- namespace,
99
- repository,
100
- license: license ?? DEFAULT_STORM_CONFIG.license,
101
- homepage: homepage ?? DEFAULT_STORM_CONFIG.homepage,
102
- extensions: {
103
- ...config.extensions
104
- }
105
- }) as StormConfig;
106
- };
@@ -1,64 +0,0 @@
1
- import { LogLevel, LogLevelLabel } from "../types";
2
-
3
- /**
4
- * Convert the log level label to a log level
5
- *
6
- * @param label - The log level label to convert
7
- * @returns The log level
8
- */
9
- export const getLogLevel = (label?: string): LogLevel => {
10
- switch (label) {
11
- case "all":
12
- return LogLevel.ALL;
13
- case "trace":
14
- return LogLevel.TRACE;
15
- case "debug":
16
- return LogLevel.DEBUG;
17
- case "info":
18
- return LogLevel.INFO;
19
- case "warn":
20
- return LogLevel.WARN;
21
- case "error":
22
- return LogLevel.ERROR;
23
- case "fatal":
24
- return LogLevel.FATAL;
25
- case "silent":
26
- return LogLevel.SILENT;
27
- default:
28
- return LogLevel.INFO;
29
- }
30
- };
31
-
32
- /**
33
- * Convert the log level to a log level label
34
- *
35
- * @param logLevel - The log level to convert
36
- * @returns The log level label
37
- */
38
- export const getLogLevelLabel = (logLevel: number = LogLevel.INFO): LogLevelLabel => {
39
- if (logLevel >= LogLevel.ALL) {
40
- return LogLevelLabel.ALL;
41
- }
42
- if (logLevel >= LogLevel.TRACE) {
43
- return LogLevelLabel.TRACE;
44
- }
45
- if (logLevel >= LogLevel.DEBUG) {
46
- return LogLevelLabel.DEBUG;
47
- }
48
- if (logLevel >= LogLevel.INFO) {
49
- return LogLevelLabel.INFO;
50
- }
51
- if (logLevel >= LogLevel.WARN) {
52
- return LogLevelLabel.WARN;
53
- }
54
- if (logLevel >= LogLevel.ERROR) {
55
- return LogLevelLabel.ERROR;
56
- }
57
- if (logLevel >= LogLevel.FATAL) {
58
- return LogLevelLabel.FATAL;
59
- }
60
- if (logLevel <= LogLevel.SILENT) {
61
- return LogLevelLabel.SILENT;
62
- }
63
- return LogLevelLabel.INFO;
64
- };
@@ -1,10 +0,0 @@
1
- export * from "./find-workspace-root";
2
- export * from "./get-default-config";
3
- export * from "./get-log-level";
4
- export * from "./logger";
5
- export * from "./process-handler";
6
- export * from "./run";
7
- export * from "./correct-paths";
8
- export * from "./file-path-utils";
9
- export * from "./apply-workspace-tokens";
10
- export * from "./chalk";