@mxpicture/build-api 0.2.4

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 (87) hide show
  1. package/dist/barrel/Barrel.d.ts +15 -0
  2. package/dist/barrel/Barrel.js +136 -0
  3. package/dist/barrel/index.d.ts +1 -0
  4. package/dist/barrel/index.js +2 -0
  5. package/dist/cleanup/Cleanup.d.ts +24 -0
  6. package/dist/cleanup/Cleanup.js +83 -0
  7. package/dist/cleanup/index.d.ts +1 -0
  8. package/dist/cleanup/index.js +2 -0
  9. package/dist/deps/FixWorkspaceDeps.d.ts +30 -0
  10. package/dist/deps/FixWorkspaceDeps.js +121 -0
  11. package/dist/deps/index.d.ts +1 -0
  12. package/dist/deps/index.js +2 -0
  13. package/dist/osInfo/index.d.ts +1 -0
  14. package/dist/osInfo/index.js +2 -0
  15. package/dist/osInfo/osInfo.common.d.ts +4 -0
  16. package/dist/osInfo/osInfo.common.js +56 -0
  17. package/dist/pkg/Pkg.d.ts +7 -0
  18. package/dist/pkg/Pkg.js +13 -0
  19. package/dist/pkg/index.d.ts +2 -0
  20. package/dist/pkg/index.js +3 -0
  21. package/dist/pkg/pkg.common.d.ts +5 -0
  22. package/dist/pkg/pkg.common.js +41 -0
  23. package/dist/scripts/fix-workspace-deps.d.ts +2 -0
  24. package/dist/scripts/fix-workspace-deps.js +16 -0
  25. package/dist/types/index.d.ts +7 -0
  26. package/dist/types/index.js +8 -0
  27. package/dist/types/types.barrel.d.ts +11 -0
  28. package/dist/types/types.barrel.js +1 -0
  29. package/dist/types/types.cleanup.d.ts +8 -0
  30. package/dist/types/types.cleanup.js +1 -0
  31. package/dist/types/types.common.d.ts +25 -0
  32. package/dist/types/types.common.js +1 -0
  33. package/dist/types/types.deps.d.ts +8 -0
  34. package/dist/types/types.deps.js +10 -0
  35. package/dist/types/types.os.d.ts +7 -0
  36. package/dist/types/types.os.js +1 -0
  37. package/dist/types/types.package.d.ts +27 -0
  38. package/dist/types/types.package.js +1 -0
  39. package/dist/types/types.vscode.d.ts +36 -0
  40. package/dist/types/types.vscode.js +1 -0
  41. package/dist/types/types.workspace.d.ts +27 -0
  42. package/dist/types/types.workspace.js +6 -0
  43. package/dist/vscode/OSUser.d.ts +9 -0
  44. package/dist/vscode/OSUser.js +62 -0
  45. package/dist/vscode/VSCodeSettings.d.ts +10 -0
  46. package/dist/vscode/VSCodeSettings.js +41 -0
  47. package/dist/vscode/VSCodeWorkspace.d.ts +9 -0
  48. package/dist/vscode/VSCodeWorkspace.js +29 -0
  49. package/dist/vscode/common.vscode.d.ts +21 -0
  50. package/dist/vscode/common.vscode.js +65 -0
  51. package/dist/vscode/config.vscode.d.ts +2 -0
  52. package/dist/vscode/config.vscode.js +4 -0
  53. package/dist/vscode/index.d.ts +5 -0
  54. package/dist/vscode/index.js +6 -0
  55. package/dist/vscode/profiles.vscode.d.ts +5 -0
  56. package/dist/vscode/profiles.vscode.js +29 -0
  57. package/dist/vscode/storage.vscode.d.ts +3 -0
  58. package/dist/vscode/storage.vscode.js +15 -0
  59. package/dist/vscode/types.vscode.d.ts +37 -0
  60. package/dist/vscode/types.vscode.js +6 -0
  61. package/dist/vscode/vscode.config.d.ts +2 -0
  62. package/dist/vscode/vscode.config.js +4 -0
  63. package/dist/vscode/vscode.profiles.d.ts +5 -0
  64. package/dist/vscode/vscode.profiles.js +30 -0
  65. package/dist/vscode/vscode.settings.d.ts +3 -0
  66. package/dist/vscode/vscode.settings.js +26 -0
  67. package/dist/vscode/vscode.storage.d.ts +3 -0
  68. package/dist/vscode/vscode.storage.js +15 -0
  69. package/dist/vscode/vscode.workspace.d.ts +3 -0
  70. package/dist/vscode/vscode.workspace.js +14 -0
  71. package/dist/vscode/workspace.vscode.d.ts +11 -0
  72. package/dist/vscode/workspace.vscode.js +149 -0
  73. package/dist/workspace/IFixWorkspaceDeps.d.ts +22 -0
  74. package/dist/workspace/IFixWorkspaceDeps.js +118 -0
  75. package/dist/workspace/WorkspacePaths.d.ts +7 -0
  76. package/dist/workspace/WorkspacePaths.js +30 -0
  77. package/dist/workspace/fixWorkspaceDeps.d.ts +22 -0
  78. package/dist/workspace/fixWorkspaceDeps.js +118 -0
  79. package/dist/workspace/index.d.ts +2 -0
  80. package/dist/workspace/index.js +3 -0
  81. package/dist/workspace/workspace.common.d.ts +13 -0
  82. package/dist/workspace/workspace.common.js +152 -0
  83. package/dist/zod/index.d.ts +1 -0
  84. package/dist/zod/index.js +2 -0
  85. package/dist/zod/zod.package.d.ts +9 -0
  86. package/dist/zod/zod.package.js +8 -0
  87. package/package.json +45 -0
@@ -0,0 +1,25 @@
1
+ export type Logger = (...data: any[]) => void;
2
+ export interface PnpmWorkspace {
3
+ packages: string[];
4
+ }
5
+ export interface PackageJson {
6
+ name: string;
7
+ version: string;
8
+ exports?: Record<string, string>;
9
+ dependencies?: Record<string, string>;
10
+ devDependencies?: Record<string, string>;
11
+ peerDependencies?: Record<string, string>;
12
+ [key: string]: unknown;
13
+ }
14
+ export interface PackageEntry {
15
+ jsonPath: string;
16
+ repoPath: string;
17
+ wsName: string;
18
+ content: PackageJson;
19
+ modified: boolean;
20
+ }
21
+ export interface MapEntry {
22
+ fromPkg: PackageEntry;
23
+ toPkg: PackageEntry;
24
+ relPath: string;
25
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ export declare enum DepsProcessMode {
2
+ fix = "fix",
3
+ restore = "restore"
4
+ }
5
+ export declare enum DepsReplacementMode {
6
+ version = "version",
7
+ file = "file"
8
+ }
@@ -0,0 +1,10 @@
1
+ export var DepsProcessMode;
2
+ (function (DepsProcessMode) {
3
+ DepsProcessMode["fix"] = "fix";
4
+ DepsProcessMode["restore"] = "restore";
5
+ })(DepsProcessMode || (DepsProcessMode = {}));
6
+ export var DepsReplacementMode;
7
+ (function (DepsReplacementMode) {
8
+ DepsReplacementMode["version"] = "version";
9
+ DepsReplacementMode["file"] = "file";
10
+ })(DepsReplacementMode || (DepsReplacementMode = {}));
@@ -0,0 +1,7 @@
1
+ export interface OSInfo {
2
+ homedir: string;
3
+ username: string;
4
+ platform: NodeJS.Platform;
5
+ configDir: string;
6
+ isWSL?: boolean;
7
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,27 @@
1
+ export interface PackageVersion {
2
+ major: number;
3
+ minor: number | null;
4
+ patch: number | null;
5
+ prefix: string | null;
6
+ }
7
+ export interface PackageJson {
8
+ name: string;
9
+ version: string;
10
+ exports?: Record<string, string>;
11
+ dependencies?: Record<string, string>;
12
+ devDependencies?: Record<string, string>;
13
+ peerDependencies?: Record<string, string>;
14
+ [key: string]: unknown;
15
+ }
16
+ export interface PackageEntry {
17
+ jsonPath: string;
18
+ repoPath: string;
19
+ wsName: string;
20
+ content: PackageJson;
21
+ modified: boolean;
22
+ }
23
+ export interface MapEntry {
24
+ fromPkg: PackageEntry;
25
+ toPkg: PackageEntry;
26
+ relPath: string;
27
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,36 @@
1
+ export interface VSCodeProfile {
2
+ location: string;
3
+ name: string;
4
+ settingsPath: string;
5
+ }
6
+ export interface VSCodeStorage {
7
+ userDataProfiles: {
8
+ location: string;
9
+ name: string;
10
+ icon: string;
11
+ useDefaultFlags?: {
12
+ settings?: boolean;
13
+ keybindings?: boolean;
14
+ snippets?: boolean;
15
+ tasks?: boolean;
16
+ extensions?: boolean;
17
+ };
18
+ }[];
19
+ profileAssociations: {
20
+ workspaces: {
21
+ [key: string]: string;
22
+ };
23
+ };
24
+ }
25
+ export type VSCodeSettings = Record<string, unknown>;
26
+ export interface VSCodeWorkspaceFolder {
27
+ path: string;
28
+ name?: string;
29
+ uri?: string;
30
+ }
31
+ export interface VSCodeWorkspace {
32
+ folders: VSCodeWorkspaceFolder[];
33
+ settings?: Record<string, unknown>;
34
+ launch?: Record<string, unknown>;
35
+ extensions?: Record<string, unknown>;
36
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,27 @@
1
+ import { MapEntry, PackageEntry } from "./types.package.js";
2
+ export type Logger = (...data: any[]) => void;
3
+ export interface PnpmWorkspace {
4
+ packages: string[];
5
+ }
6
+ export declare enum WorkspaceFileType {
7
+ package = "package",
8
+ workspace = "workspace",
9
+ other = "other"
10
+ }
11
+ export interface WorkspaceFile {
12
+ filePath: string;
13
+ dirPath: string;
14
+ filename: string;
15
+ level: number;
16
+ type: WorkspaceFileType;
17
+ }
18
+ export interface FixWorkspaceDepsMain {
19
+ mapEntries: MapEntry[];
20
+ consumingPkg: PackageEntry;
21
+ versionMap: Map<string, string>;
22
+ workspacePackages: Set<string>;
23
+ }
24
+ export interface FixWorkspaceDepsParams extends FixWorkspaceDepsMain {
25
+ pkg: string;
26
+ version: string;
27
+ }
@@ -0,0 +1,6 @@
1
+ export var WorkspaceFileType;
2
+ (function (WorkspaceFileType) {
3
+ WorkspaceFileType["package"] = "package";
4
+ WorkspaceFileType["workspace"] = "workspace";
5
+ WorkspaceFileType["other"] = "other";
6
+ })(WorkspaceFileType || (WorkspaceFileType = {}));
@@ -0,0 +1,9 @@
1
+ import { OSInfo } from "../types/types.os.js";
2
+ export declare class OSUser {
3
+ protected static info?: OSInfo;
4
+ static getInfo(): OSInfo;
5
+ protected constructor();
6
+ protected static load(): void;
7
+ protected static getWSL(): OSInfo;
8
+ protected static getDefault(): OSInfo;
9
+ }
@@ -0,0 +1,62 @@
1
+ import { execSync } from "child_process";
2
+ import * as os from "os";
3
+ import { join, sep } from "path";
4
+ export class OSUser {
5
+ static info;
6
+ static getInfo() {
7
+ this.load();
8
+ if (!this.info)
9
+ throw new Error("Load OS info failed");
10
+ return this.info;
11
+ }
12
+ constructor() { }
13
+ static load() {
14
+ if (this.info)
15
+ return;
16
+ const isWSL = os.release().toLowerCase().includes("microsoft");
17
+ this.info = isWSL ? this.getWSL() : this.getDefault();
18
+ }
19
+ static getWSL() {
20
+ const whoamiParts = execSync("whoami.exe").toString().split(sep);
21
+ if (whoamiParts.length === 0)
22
+ throw new Error("Windows user could not be determined");
23
+ // const winUser = process.env["WINUSER"] || process.env["USER"];
24
+ const platform = process.platform;
25
+ let username = whoamiParts[whoamiParts.length - 1];
26
+ // remove AD group
27
+ const userParts = username.split("\\");
28
+ username = userParts[userParts.length - 1];
29
+ username = username.replace("\r", "").replace("\n", "");
30
+ const parts = ["/mnt", "c", "Users", username];
31
+ const homedir = join(...parts);
32
+ const configDir = join(homedir, "AppData", "Roaming");
33
+ return {
34
+ username,
35
+ homedir,
36
+ configDir,
37
+ platform,
38
+ isWSL: true,
39
+ };
40
+ }
41
+ static getDefault() {
42
+ const platform = process.platform;
43
+ const homedir = os.homedir();
44
+ const configDirParts = [];
45
+ if (platform === "win32") {
46
+ if (process.env.APPDATA)
47
+ configDirParts.push(process.env.APPDATA);
48
+ }
49
+ else if (platform === "darwin") {
50
+ configDirParts.push(homedir, "Library", "Application Support");
51
+ }
52
+ else {
53
+ configDirParts.push(homedir, ".config");
54
+ }
55
+ return {
56
+ username: os.userInfo().username,
57
+ homedir,
58
+ platform,
59
+ configDir: join(...configDirParts),
60
+ };
61
+ }
62
+ }
@@ -0,0 +1,10 @@
1
+ import { VSCodeSettingsContent } from "../types/types.vscode.js";
2
+ export declare class VSCodeSettings {
3
+ protected static instance: VSCodeSettings | undefined;
4
+ protected content: VSCodeSettingsContent;
5
+ static load(): Promise<VSCodeSettings>;
6
+ protected constructor(content: VSCodeSettingsContent);
7
+ getProperty(name: string): unknown;
8
+ getContent(): VSCodeSettingsContent;
9
+ getClangFormatStyle(): string | undefined;
10
+ }
@@ -0,0 +1,41 @@
1
+ import * as fs from "fs";
2
+ import pkg from "json5";
3
+ import { activeProfile, defaultSettingsPath } from "./profiles.vscode.js";
4
+ export class VSCodeSettings {
5
+ static instance;
6
+ content;
7
+ static async load() {
8
+ if (this.instance)
9
+ return this.instance;
10
+ let settingsPath;
11
+ try {
12
+ // check profile
13
+ settingsPath = (await activeProfile()).settingsPath;
14
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
15
+ }
16
+ catch (error) {
17
+ // check default
18
+ settingsPath = defaultSettingsPath();
19
+ }
20
+ if (!settingsPath)
21
+ throw new Error("No settings path found");
22
+ const raw = fs.readFileSync(settingsPath, "utf-8");
23
+ this.instance = new VSCodeSettings(pkg.parse(raw));
24
+ return this.instance;
25
+ }
26
+ constructor(content) {
27
+ this.content = content;
28
+ }
29
+ getProperty(name) {
30
+ return this.getContent()[name];
31
+ }
32
+ getContent() {
33
+ return { ...this.content };
34
+ }
35
+ getClangFormatStyle() {
36
+ const value = this.getProperty("C_Cpp.clang_format_style");
37
+ if (typeof value !== "string")
38
+ throw new Error("C_Cpp.clang_format_style not found in settings.json");
39
+ return value;
40
+ }
41
+ }
@@ -0,0 +1,9 @@
1
+ import { VSCodeWorkspaceContent } from "../types/types.vscode.js";
2
+ export declare class VSCodeWorkspace {
3
+ readonly workspaceFile: string;
4
+ readonly content: VSCodeWorkspaceContent;
5
+ protected static instances: VSCodeWorkspace[];
6
+ static load(workspaceFile?: string): Promise<VSCodeWorkspace>;
7
+ protected constructor(workspaceFile: string, content: VSCodeWorkspaceContent);
8
+ get root(): string;
9
+ }
@@ -0,0 +1,29 @@
1
+ import { dirname } from "path";
2
+ import pkg from "json5";
3
+ import { readFile } from "fs/promises";
4
+ import { findWorkspaceRoot } from "../workspace/workspace.common.js";
5
+ export class VSCodeWorkspace {
6
+ workspaceFile;
7
+ content;
8
+ static instances = [];
9
+ static async load(workspaceFile) {
10
+ if (!workspaceFile) {
11
+ const foundWorkspaceFile = await findWorkspaceRoot();
12
+ workspaceFile = foundWorkspaceFile.filePath;
13
+ }
14
+ let found = this.instances.find((inst) => inst.workspaceFile === workspaceFile);
15
+ if (!found) {
16
+ const workspaceContent = await readFile(workspaceFile, "utf-8");
17
+ found = new VSCodeWorkspace(workspaceFile, pkg.parse(workspaceContent));
18
+ this.instances.push(found);
19
+ }
20
+ return found;
21
+ }
22
+ constructor(workspaceFile, content) {
23
+ this.workspaceFile = workspaceFile;
24
+ this.content = content;
25
+ }
26
+ get root() {
27
+ return dirname(this.workspaceFile);
28
+ }
29
+ }
@@ -0,0 +1,21 @@
1
+ import { WorkspaceFileType } from "./types.vscode.js";
2
+ import { z } from "zod";
3
+ export declare const DEFAULT_WORKSPACE_FILE_ENDING = ".code-workspace";
4
+ export declare const removeLastPathElement: (path: string) => string | undefined;
5
+ export declare const getFileType: (filename: string) => WorkspaceFileType;
6
+ export interface PackageVersion {
7
+ major: number;
8
+ minor: number | null;
9
+ patch: number | null;
10
+ prefix: string | null;
11
+ }
12
+ export declare const packageVersionSchema: z.ZodObject<{
13
+ major: z.ZodNumber;
14
+ minor: z.ZodXor<readonly [z.ZodNumber, z.ZodNull]>;
15
+ patch: z.ZodXor<readonly [z.ZodNumber, z.ZodNull]>;
16
+ prefix: z.ZodXor<readonly [z.ZodString, z.ZodNull]>;
17
+ }, z.core.$strip>;
18
+ export declare const splitVersion: (version: string) => PackageVersion;
19
+ export declare const concatVersion: (version: PackageVersion) => string;
20
+ export declare const compareVersions: (a: PackageVersion | string, b: PackageVersion | string) => number;
21
+ export declare const compareVersionsGT: (a: PackageVersion | string, b: PackageVersion | string) => boolean;
@@ -0,0 +1,65 @@
1
+ import { join, sep } from "path";
2
+ import { WorkspaceFileType } from "./types.vscode.js";
3
+ import { z } from "zod";
4
+ export const DEFAULT_WORKSPACE_FILE_ENDING = ".code-workspace";
5
+ export const removeLastPathElement = (path) => {
6
+ const parts = path.split(sep);
7
+ parts.pop();
8
+ if (parts.length <= 1)
9
+ return;
10
+ if (parts[0] === "")
11
+ parts[0] = "/";
12
+ return join(...parts);
13
+ };
14
+ export const getFileType = (filename) => filename.endsWith(DEFAULT_WORKSPACE_FILE_ENDING)
15
+ ? WorkspaceFileType.workspace
16
+ : filename === "package.json"
17
+ ? WorkspaceFileType.package
18
+ : WorkspaceFileType.other;
19
+ export const packageVersionSchema = z.object({
20
+ major: z.number().min(0),
21
+ minor: z.xor([z.number(), z.null()]),
22
+ patch: z.xor([z.number(), z.null()]),
23
+ prefix: z.xor([z.string(), z.null()]),
24
+ });
25
+ export const splitVersion = (version) => {
26
+ const parts = version.split(".");
27
+ let major = parts.shift();
28
+ const prefix = major.startsWith("v") ? "v" : null;
29
+ if (major.startsWith("v"))
30
+ major = major.substring(1);
31
+ const minor = parts.shift();
32
+ const patch = parts.shift();
33
+ return {
34
+ major: Number(major),
35
+ minor: minor ? Number(minor) : null,
36
+ patch: patch ? Number(patch) : null,
37
+ prefix,
38
+ };
39
+ };
40
+ export const concatVersion = (version) => {
41
+ let result = version.major.toString();
42
+ if (version.prefix)
43
+ result = version.prefix + result;
44
+ if (version.minor)
45
+ result += "." + version.minor.toString();
46
+ if (version.patch)
47
+ result += "." + version.patch.toString();
48
+ return result;
49
+ };
50
+ export const compareVersions = (a, b) => {
51
+ a = typeof a === "string" ? splitVersion(a) : a;
52
+ b = typeof b === "string" ? splitVersion(b) : b;
53
+ if (a.major !== b.major)
54
+ return a.major - b.major;
55
+ if (a.minor === null || b.minor === null)
56
+ return 0;
57
+ if (a.minor !== b.minor)
58
+ return a.minor - b.minor;
59
+ if (a.patch === null || b.patch === null)
60
+ return 0;
61
+ if (a.patch !== b.patch)
62
+ return a.patch - b.patch;
63
+ return 0;
64
+ };
65
+ export const compareVersionsGT = (a, b) => compareVersions(a, b) > 0;
@@ -0,0 +1,2 @@
1
+ export declare const configPath: () => string;
2
+ export declare const configUserPath: () => string;
@@ -0,0 +1,4 @@
1
+ import { join } from "path";
2
+ import { OSUser } from "./OSUser.js";
3
+ export const configPath = () => join(OSUser.getInfo().configDir, "Code");
4
+ export const configUserPath = () => join(configPath(), "User");
@@ -0,0 +1,5 @@
1
+ export * from "./vscode.config.js";
2
+ export * from "./vscode.profiles.js";
3
+ export * from "./vscode.settings.js";
4
+ export * from "./vscode.storage.js";
5
+ export * from "./vscode.workspace.js";
@@ -0,0 +1,6 @@
1
+ // This file is auto-generated. Do not edit manually.
2
+ export * from "./vscode.config.js";
3
+ export * from "./vscode.profiles.js";
4
+ export * from "./vscode.settings.js";
5
+ export * from "./vscode.storage.js";
6
+ export * from "./vscode.workspace.js";
@@ -0,0 +1,5 @@
1
+ import { VSCodeProfile } from "../types/types.vscode.js";
2
+ export declare const profiles: () => VSCodeProfile[];
3
+ export declare const activeProfile: () => Promise<VSCodeProfile>;
4
+ export declare const profileSettingsPath: (profile: string) => string;
5
+ export declare const defaultSettingsPath: () => string;
@@ -0,0 +1,29 @@
1
+ import { join } from "path";
2
+ import { storage } from "./storage.vscode.js";
3
+ import { configUserPath } from "./config.vscode.js";
4
+ import { findWorkspaceRoot } from "./workspace.vscode.js";
5
+ export const profiles = () => storage().userDataProfiles.map((prof) => ({
6
+ name: prof.name,
7
+ location: prof.location,
8
+ settingsPath: profileSettingsPath(prof.location),
9
+ }));
10
+ export const activeProfile = async () => {
11
+ const foundWS = await findWorkspaceRoot();
12
+ const storageContent = storage();
13
+ const profs = profiles();
14
+ let foundProfile;
15
+ // eslint-disable-next-line prefer-const
16
+ for (let [path, profile] of Object.entries(storageContent.profileAssociations.workspaces)) {
17
+ path = path.replace("file://", "");
18
+ if (foundWS.filePath !== path)
19
+ continue;
20
+ foundProfile = profs.find((prof) => prof.location === profile);
21
+ if (foundProfile)
22
+ break;
23
+ }
24
+ if (!foundProfile)
25
+ throw new Error("No active profile found");
26
+ return foundProfile;
27
+ };
28
+ export const profileSettingsPath = (profile) => join(configUserPath(), "profiles", profile, "settings.json");
29
+ export const defaultSettingsPath = () => join(configUserPath(), "settings.json");
@@ -0,0 +1,3 @@
1
+ import { VSCodeStorage } from "../types/types.vscode.js";
2
+ export declare const storagePath: () => string;
3
+ export declare const storage: () => VSCodeStorage;
@@ -0,0 +1,15 @@
1
+ import * as fs from "fs";
2
+ import { join } from "path";
3
+ import pkg from "json5";
4
+ import { configUserPath } from "./config.vscode.js";
5
+ export const storagePath = () => join(configUserPath(), "globalStorage", "storage.json");
6
+ let __storage;
7
+ export const storage = () => {
8
+ if (__storage)
9
+ return __storage;
10
+ const content = fs.readFileSync(storagePath()).toString();
11
+ __storage = pkg.parse(content);
12
+ if (!__storage)
13
+ throw new Error("VS Code storage.json could not be loaded");
14
+ return __storage;
15
+ };
@@ -0,0 +1,37 @@
1
+ export interface VSCodeProfile {
2
+ location: string;
3
+ name: string;
4
+ settingsPath: string;
5
+ }
6
+ export interface VSCodeStorage {
7
+ userDataProfiles: {
8
+ location: string;
9
+ name: string;
10
+ icon: string;
11
+ useDefaultFlags?: {
12
+ settings?: boolean;
13
+ keybindings?: boolean;
14
+ snippets?: boolean;
15
+ tasks?: boolean;
16
+ extensions?: boolean;
17
+ };
18
+ }[];
19
+ profileAssociations: {
20
+ workspaces: {
21
+ [key: string]: string;
22
+ };
23
+ };
24
+ }
25
+ export declare enum WorkspaceFileType {
26
+ package = "package",
27
+ workspace = "workspace",
28
+ other = "other"
29
+ }
30
+ export interface WorkspaceFile {
31
+ filePath: string;
32
+ dirPath: string;
33
+ filename: string;
34
+ level: number;
35
+ type: WorkspaceFileType;
36
+ }
37
+ export type ProcessMode = "fix" | "restore";
@@ -0,0 +1,6 @@
1
+ export var WorkspaceFileType;
2
+ (function (WorkspaceFileType) {
3
+ WorkspaceFileType["package"] = "package";
4
+ WorkspaceFileType["workspace"] = "workspace";
5
+ WorkspaceFileType["other"] = "other";
6
+ })(WorkspaceFileType || (WorkspaceFileType = {}));
@@ -0,0 +1,2 @@
1
+ export declare const configPath: () => string;
2
+ export declare const configUserPath: () => string;
@@ -0,0 +1,4 @@
1
+ import { join } from "path";
2
+ import { osInfo } from "../osInfo/osInfo.common.js";
3
+ export const configPath = () => join(osInfo().configDir, "Code");
4
+ export const configUserPath = () => join(configPath(), "User");
@@ -0,0 +1,5 @@
1
+ import { VSCodeProfile } from "../types/types.vscode.js";
2
+ export declare const profiles: () => VSCodeProfile[];
3
+ export declare const activeProfile: (dir?: string) => Promise<VSCodeProfile>;
4
+ export declare const profileSettingsPath: (profile: string) => string;
5
+ export declare const defaultSettingsPath: () => string;
@@ -0,0 +1,30 @@
1
+ import { join } from "path";
2
+ import { storage } from "./vscode.storage.js";
3
+ import { configUserPath } from "./vscode.config.js";
4
+ import { findWorkspaceRoot } from "../workspace/workspace.common.js";
5
+ import { cwd } from "process";
6
+ export const profiles = () => storage().userDataProfiles.map((prof) => ({
7
+ name: prof.name,
8
+ location: prof.location,
9
+ settingsPath: profileSettingsPath(prof.location),
10
+ }));
11
+ export const activeProfile = async (dir) => {
12
+ const foundWS = await findWorkspaceRoot(dir ?? cwd());
13
+ const storageContent = storage();
14
+ const profs = profiles();
15
+ let foundProfile;
16
+ // eslint-disable-next-line prefer-const
17
+ for (let [path, profile] of Object.entries(storageContent.profileAssociations.workspaces)) {
18
+ path = path.replace("file://", "");
19
+ if (foundWS.filePath !== path)
20
+ continue;
21
+ foundProfile = profs.find((prof) => prof.location === profile);
22
+ if (foundProfile)
23
+ break;
24
+ }
25
+ if (!foundProfile)
26
+ throw new Error("No active profile found");
27
+ return foundProfile;
28
+ };
29
+ export const profileSettingsPath = (profile) => join(configUserPath(), "profiles", profile, "settings.json");
30
+ export const defaultSettingsPath = () => join(configUserPath(), "settings.json");
@@ -0,0 +1,3 @@
1
+ import { VSCodeSettings } from "../types/types.vscode.js";
2
+ export declare const vscodeSettings: (dir?: string) => Promise<VSCodeSettings>;
3
+ export declare const clangFormatStyle: (cwd: string) => Promise<string>;
@@ -0,0 +1,26 @@
1
+ import { activeProfile, defaultSettingsPath } from "./vscode.profiles.js";
2
+ import { readFile } from "fs/promises";
3
+ import pkg from "json5";
4
+ let __settings = null;
5
+ export const vscodeSettings = async (dir) => {
6
+ if (!__settings) {
7
+ let settingsPath;
8
+ try {
9
+ settingsPath = (await activeProfile(dir)).settingsPath;
10
+ }
11
+ catch {
12
+ settingsPath = defaultSettingsPath();
13
+ }
14
+ const raw = await readFile(settingsPath, "utf-8");
15
+ __settings = pkg.parse(raw);
16
+ if (!__settings)
17
+ throw new Error("No settings found");
18
+ }
19
+ return { ...__settings };
20
+ };
21
+ export const clangFormatStyle = async (cwd) => {
22
+ const settings = await vscodeSettings(cwd);
23
+ if (!("C_Cpp.clang_format_style" in settings))
24
+ throw new Error("C_Cpp.clang_format_style not found in settings.json");
25
+ return settings["C_Cpp.clang_format_style"];
26
+ };
@@ -0,0 +1,3 @@
1
+ import { VSCodeStorage } from "../types/types.vscode.js";
2
+ export declare const storagePath: () => string;
3
+ export declare const storage: () => VSCodeStorage;
@@ -0,0 +1,15 @@
1
+ import * as fs from "fs";
2
+ import { join } from "path";
3
+ import pkg from "json5";
4
+ import { configUserPath } from "./vscode.config.js";
5
+ export const storagePath = () => join(configUserPath(), "globalStorage", "storage.json");
6
+ let __storage;
7
+ export const storage = () => {
8
+ if (__storage)
9
+ return __storage;
10
+ const content = fs.readFileSync(storagePath()).toString();
11
+ __storage = pkg.parse(content);
12
+ if (!__storage)
13
+ throw new Error("VS Code storage.json could not be loaded");
14
+ return __storage;
15
+ };