@mxpicture/gcp-functions-code 0.2.0
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/changelog/ChangeDetector.d.ts +25 -0
- package/dist/changelog/ChangeDetector.js +47 -0
- package/dist/changelog/Changelog.d.ts +15 -0
- package/dist/changelog/Changelog.js +98 -0
- package/dist/changelog/changelog.util.d.ts +94 -0
- package/dist/changelog/changelog.util.js +228 -0
- package/dist/changelog/index.d.ts +3 -0
- package/dist/changelog/index.js +4 -0
- package/dist/common/code.common.d.ts +17 -0
- package/dist/common/code.common.js +65 -0
- package/dist/common/hash.common.d.ts +1 -0
- package/dist/common/hash.common.js +2 -0
- package/dist/common/index.d.ts +4 -0
- package/dist/common/index.js +5 -0
- package/dist/common/string.common.d.ts +4 -0
- package/dist/common/string.common.js +8 -0
- package/dist/common/types.common.d.ts +20 -0
- package/dist/common/types.common.js +1 -0
- package/dist/deps/IFixWorkspaceDeps.d.ts +21 -0
- package/dist/deps/IFixWorkspaceDeps.js +76 -0
- package/dist/deps/fixWorkspaceDeps.d.ts +12 -0
- package/dist/deps/fixWorkspaceDeps.js +43 -0
- package/dist/deps/index.d.ts +2 -0
- package/dist/deps/index.js +3 -0
- package/dist/git/GitChanges.d.ts +33 -0
- package/dist/git/GitChanges.js +85 -0
- package/dist/git/git.util.d.ts +9 -0
- package/dist/git/git.util.js +33 -0
- package/dist/git/index.d.ts +3 -0
- package/dist/git/index.js +4 -0
- package/dist/git/types.git.d.ts +22 -0
- package/dist/git/types.git.js +1 -0
- package/dist/scripts/fix-workspace-deps.d.ts +2 -0
- package/dist/scripts/fix-workspace-deps.js +14 -0
- package/dist/scripts/generate-barrels.d.ts +1 -0
- package/dist/scripts/generate-barrels.js +81 -0
- package/dist/scripts/generate-changelog.d.ts +1 -0
- package/dist/scripts/generate-changelog.js +13 -0
- package/dist/scripts/index.d.ts +3 -0
- package/dist/scripts/index.js +4 -0
- package/dist/vscode/OSUser.d.ts +15 -0
- package/dist/vscode/OSUser.js +62 -0
- package/dist/vscode/VSCodeSettings.d.ts +10 -0
- package/dist/vscode/VSCodeSettings.js +41 -0
- package/dist/vscode/VSCodeWorkspace.d.ts +20 -0
- package/dist/vscode/VSCodeWorkspace.js +44 -0
- package/dist/vscode/common.vscode.d.ts +4 -0
- package/dist/vscode/common.vscode.js +17 -0
- package/dist/vscode/config.vscode.d.ts +2 -0
- package/dist/vscode/config.vscode.js +4 -0
- package/dist/vscode/index.d.ts +10 -0
- package/dist/vscode/index.js +11 -0
- package/dist/vscode/profiles.vscode.d.ts +5 -0
- package/dist/vscode/profiles.vscode.js +29 -0
- package/dist/vscode/storage.vscode.d.ts +3 -0
- package/dist/vscode/storage.vscode.js +15 -0
- package/dist/vscode/types.vscode.d.ts +36 -0
- package/dist/vscode/types.vscode.js +6 -0
- package/dist/vscode/workspaceAsync.vscode.d.ts +2 -0
- package/dist/vscode/workspaceAsync.vscode.js +54 -0
- package/dist/vscode/workspaceSync.vscode.d.ts +4 -0
- package/dist/vscode/workspaceSync.vscode.js +73 -0
- package/package.json +53 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import { dirname } from "path";
|
|
3
|
+
import pkg from "json5";
|
|
4
|
+
import { findWorkspaceRootAsync } from "./workspaceAsync.vscode.js";
|
|
5
|
+
import { findWorkspaceFile } from "./workspaceSync.vscode.js";
|
|
6
|
+
import { readFile } from "fs/promises";
|
|
7
|
+
export class VSCodeWorkspace {
|
|
8
|
+
workspaceFile;
|
|
9
|
+
content;
|
|
10
|
+
static instances = [];
|
|
11
|
+
static load(workspaceFile) {
|
|
12
|
+
if (!workspaceFile) {
|
|
13
|
+
const foundWorkspaceFile = findWorkspaceFile();
|
|
14
|
+
workspaceFile = foundWorkspaceFile.filePath;
|
|
15
|
+
}
|
|
16
|
+
let found = this.instances.find((inst) => inst.workspaceFile === workspaceFile);
|
|
17
|
+
if (!found) {
|
|
18
|
+
const workspaceContent = fs.readFileSync(workspaceFile, "utf-8");
|
|
19
|
+
found = new VSCodeWorkspace(workspaceFile, pkg.parse(workspaceContent));
|
|
20
|
+
this.instances.push(found);
|
|
21
|
+
}
|
|
22
|
+
return found;
|
|
23
|
+
}
|
|
24
|
+
static async loadAsync(workspaceFile) {
|
|
25
|
+
if (!workspaceFile) {
|
|
26
|
+
const foundWorkspaceFile = await findWorkspaceRootAsync();
|
|
27
|
+
workspaceFile = foundWorkspaceFile.filePath;
|
|
28
|
+
}
|
|
29
|
+
let found = this.instances.find((inst) => inst.workspaceFile === workspaceFile);
|
|
30
|
+
if (!found) {
|
|
31
|
+
const workspaceContent = await readFile(workspaceFile, "utf-8");
|
|
32
|
+
found = new VSCodeWorkspace(workspaceFile, pkg.parse(workspaceContent));
|
|
33
|
+
this.instances.push(found);
|
|
34
|
+
}
|
|
35
|
+
return found;
|
|
36
|
+
}
|
|
37
|
+
constructor(workspaceFile, content) {
|
|
38
|
+
this.workspaceFile = workspaceFile;
|
|
39
|
+
this.content = content;
|
|
40
|
+
}
|
|
41
|
+
get root() {
|
|
42
|
+
return dirname(this.workspaceFile);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { WorkspaceFileType } from "./types.vscode.js";
|
|
2
|
+
export declare const DEFAULT_WORKSPACE_FILE_ENDING = ".code-workspace";
|
|
3
|
+
export declare const removeLastPathElement: (path: string) => string | undefined;
|
|
4
|
+
export declare const getFileType: (filename: string) => WorkspaceFileType;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { join, sep } from "path";
|
|
2
|
+
import { WorkspaceFileType } from "./types.vscode.js";
|
|
3
|
+
export const DEFAULT_WORKSPACE_FILE_ENDING = ".code-workspace";
|
|
4
|
+
export const removeLastPathElement = (path) => {
|
|
5
|
+
const parts = path.split(sep);
|
|
6
|
+
parts.pop();
|
|
7
|
+
if (parts.length <= 1)
|
|
8
|
+
return;
|
|
9
|
+
if (parts[0] === "")
|
|
10
|
+
parts[0] = "/";
|
|
11
|
+
return join(...parts);
|
|
12
|
+
};
|
|
13
|
+
export const getFileType = (filename) => filename.endsWith(DEFAULT_WORKSPACE_FILE_ENDING)
|
|
14
|
+
? WorkspaceFileType.workspace
|
|
15
|
+
: filename === "package.json"
|
|
16
|
+
? WorkspaceFileType.package
|
|
17
|
+
: WorkspaceFileType.other;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./OSUser.js";
|
|
2
|
+
export * from "./VSCodeSettings.js";
|
|
3
|
+
export * from "./VSCodeWorkspace.js";
|
|
4
|
+
export * from "./common.vscode.js";
|
|
5
|
+
export * from "./config.vscode.js";
|
|
6
|
+
export * from "./profiles.vscode.js";
|
|
7
|
+
export * from "./storage.vscode.js";
|
|
8
|
+
export * from "./types.vscode.js";
|
|
9
|
+
export * from "./workspaceAsync.vscode.js";
|
|
10
|
+
export * from "./workspaceSync.vscode.js";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This file is auto-generated. Do not edit manually.
|
|
2
|
+
export * from "./OSUser.js";
|
|
3
|
+
export * from "./VSCodeSettings.js";
|
|
4
|
+
export * from "./VSCodeWorkspace.js";
|
|
5
|
+
export * from "./common.vscode.js";
|
|
6
|
+
export * from "./config.vscode.js";
|
|
7
|
+
export * from "./profiles.vscode.js";
|
|
8
|
+
export * from "./storage.vscode.js";
|
|
9
|
+
export * from "./types.vscode.js";
|
|
10
|
+
export * from "./workspaceAsync.vscode.js";
|
|
11
|
+
export * from "./workspaceSync.vscode.js";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { VSCodeProfile } from "./types.vscode.js";
|
|
2
|
+
export declare const profiles: () => VSCodeProfile[];
|
|
3
|
+
export declare const activeProfile: () => 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 { findWorkspaceFile } from "./workspaceSync.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 = () => {
|
|
11
|
+
const foundWS = findWorkspaceFile();
|
|
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,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,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 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
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { dirname, join } from "path";
|
|
2
|
+
import { fileURLToPath } from "url";
|
|
3
|
+
import { WorkspaceFileType } from "./types.vscode.js";
|
|
4
|
+
import { getFileType } from "./common.vscode.js";
|
|
5
|
+
import { readdir } from "fs/promises";
|
|
6
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
let __workspaceRoot = null;
|
|
8
|
+
export const findWorkspaceRootAsync = async (startPath) => __workspaceRoot ??
|
|
9
|
+
(__workspaceRoot = await _findWorkspaceRoot(startPath ?? __dirname));
|
|
10
|
+
const _findWorkspaceRoot = async (dirPath) => {
|
|
11
|
+
let path = dirPath;
|
|
12
|
+
let level = 0;
|
|
13
|
+
const promises = [];
|
|
14
|
+
while (path.length > 0) {
|
|
15
|
+
promises.push((async () => {
|
|
16
|
+
const l = level;
|
|
17
|
+
const entries = await readdir(path, { withFileTypes: true });
|
|
18
|
+
let pkg = null;
|
|
19
|
+
for (const entry of entries) {
|
|
20
|
+
if (!entry.isFile())
|
|
21
|
+
continue;
|
|
22
|
+
const type = getFileType(entry.name);
|
|
23
|
+
if (type === WorkspaceFileType.workspace)
|
|
24
|
+
return {
|
|
25
|
+
filePath: join(path, entry.name),
|
|
26
|
+
dirPath: path,
|
|
27
|
+
filename: entry.name,
|
|
28
|
+
level: l,
|
|
29
|
+
type,
|
|
30
|
+
};
|
|
31
|
+
if (!pkg && type === WorkspaceFileType.package)
|
|
32
|
+
pkg = {
|
|
33
|
+
filePath: join(path, entry.name),
|
|
34
|
+
dirPath: path,
|
|
35
|
+
filename: entry.name,
|
|
36
|
+
level: l,
|
|
37
|
+
type,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
if (!pkg)
|
|
41
|
+
throw new Error("");
|
|
42
|
+
return pkg;
|
|
43
|
+
})());
|
|
44
|
+
level++;
|
|
45
|
+
path = path.replace(/\/?[^\/]+\/?$/, ""); // remove last dir
|
|
46
|
+
}
|
|
47
|
+
const results = (await Promise.allSettled(promises)).filter((r) => r.status === "fulfilled");
|
|
48
|
+
results.sort((a, b) => a.value.level - b.value.level);
|
|
49
|
+
const result = results.find((r) => r.value.type === WorkspaceFileType.workspace)?.value &&
|
|
50
|
+
results.find((r) => r.value.type === WorkspaceFileType.package)?.value;
|
|
51
|
+
if (!result)
|
|
52
|
+
throw new Error("findWorkspaceRoot: no file found");
|
|
53
|
+
return result;
|
|
54
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { WorkspaceFile } from "./types.vscode.js";
|
|
2
|
+
export declare const findWorkspaceFile: (ending?: string) => WorkspaceFile;
|
|
3
|
+
export declare const findWorkspaceFiles: (ending?: string) => WorkspaceFile[];
|
|
4
|
+
export declare const findWorkspaceRoot: (startPath?: string) => WorkspaceFile | undefined;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import { dirname, join, sep } from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
import { WorkspaceFileType } from "./types.vscode.js";
|
|
5
|
+
import { DEFAULT_WORKSPACE_FILE_ENDING, getFileType, removeLastPathElement, } from "./common.vscode.js";
|
|
6
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
export const findWorkspaceFile = (ending) => {
|
|
8
|
+
const files = findWorkspaceFiles(ending);
|
|
9
|
+
if (files.length === 0)
|
|
10
|
+
throw new Error("findWorkspaceFile: no file found");
|
|
11
|
+
return files[0];
|
|
12
|
+
};
|
|
13
|
+
export const findWorkspaceFiles = (ending) => {
|
|
14
|
+
if (!ending)
|
|
15
|
+
ending = DEFAULT_WORKSPACE_FILE_ENDING;
|
|
16
|
+
const root = findWorkspaceRoot();
|
|
17
|
+
if (!root)
|
|
18
|
+
return [];
|
|
19
|
+
const files = fs
|
|
20
|
+
.readdirSync(root.dirPath, { recursive: true })
|
|
21
|
+
.filter((item) => item.toString().endsWith(ending));
|
|
22
|
+
const results = files.map((file) => {
|
|
23
|
+
const filePath = join(root.dirPath, file.toString());
|
|
24
|
+
const level = filePath.split(sep).length;
|
|
25
|
+
return {
|
|
26
|
+
...root,
|
|
27
|
+
filename: file.toString(),
|
|
28
|
+
filePath,
|
|
29
|
+
level,
|
|
30
|
+
type: WorkspaceFileType.other,
|
|
31
|
+
};
|
|
32
|
+
});
|
|
33
|
+
results.sort((a, b) => a.level - b.level);
|
|
34
|
+
return results;
|
|
35
|
+
};
|
|
36
|
+
let __workspaceRoot;
|
|
37
|
+
export const findWorkspaceRoot = (startPath) => __workspaceRoot ??
|
|
38
|
+
(__workspaceRoot = _findWorkspaceRoot(startPath ?? __dirname));
|
|
39
|
+
const _findWorkspaceRoot = (startPath) => {
|
|
40
|
+
const files = _findWorkspaceFiles(startPath);
|
|
41
|
+
const found = files.find((file) => file.type === WorkspaceFileType.workspace);
|
|
42
|
+
if (found)
|
|
43
|
+
return found;
|
|
44
|
+
files.sort((a, b) => b.level - a.level);
|
|
45
|
+
return files.shift();
|
|
46
|
+
};
|
|
47
|
+
const _findWorkspaceFiles = (dirPath, level = 0, prevFiles = []) => {
|
|
48
|
+
if (level > 15)
|
|
49
|
+
return prevFiles; // prevent endless-loop
|
|
50
|
+
const filenames = fs.readdirSync(dirPath);
|
|
51
|
+
const files = [];
|
|
52
|
+
let isLast = false; // if workspace file was found
|
|
53
|
+
for (const filename of filenames) {
|
|
54
|
+
const type = getFileType(filename);
|
|
55
|
+
if (type === WorkspaceFileType.other)
|
|
56
|
+
continue;
|
|
57
|
+
if (type === WorkspaceFileType.workspace)
|
|
58
|
+
isLast = true;
|
|
59
|
+
files.push({
|
|
60
|
+
filename,
|
|
61
|
+
level,
|
|
62
|
+
dirPath,
|
|
63
|
+
filePath: join(dirPath, filename),
|
|
64
|
+
type,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
if (isLast)
|
|
68
|
+
return [...prevFiles, ...files];
|
|
69
|
+
const nextPath = removeLastPathElement(dirPath);
|
|
70
|
+
return nextPath
|
|
71
|
+
? _findWorkspaceFiles(nextPath, level + 1, [...prevFiles, ...files])
|
|
72
|
+
: prevFiles;
|
|
73
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mxpicture/gcp-functions-code",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Tools for google cloud functions",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"author": "MXPicture",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/MXPicture/npm-gcp-functions.git"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
"./changelog": "./dist/changelog/index.js",
|
|
14
|
+
"./common": "./dist/common/index.js",
|
|
15
|
+
"./vscode": "./dist/vscode/index.js",
|
|
16
|
+
"./git": "./dist/git/index.js",
|
|
17
|
+
"./deps": "./dist/deps/index.js",
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=22"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"clean": "rm -rf dist .tsbuildinfo tsconfig.tsbuildinfo node_modules",
|
|
28
|
+
"lint": "eslint \"src/**/*.{ts,tsx}\" --ext .ts,.tsx",
|
|
29
|
+
"build": "tsc -b .",
|
|
30
|
+
"test:clean": "rm -rf src/4testing/generator-test-*",
|
|
31
|
+
"run:test": "pnpm exec tsx src/scripts/test.mts"
|
|
32
|
+
},
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@mxpicture/gcp-functions-common": "^0.2.0",
|
|
38
|
+
"json5": "^1.0.2",
|
|
39
|
+
"micromatch": "^4.0.8",
|
|
40
|
+
"prettier": "^3.8.1",
|
|
41
|
+
"simple-git": "^3.31.1",
|
|
42
|
+
"type-fest": "^5.4.4",
|
|
43
|
+
"yaml": "^2.8.2",
|
|
44
|
+
"zod": "^4.3.6"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/micromatch": "^4.0.10",
|
|
48
|
+
"@types/node": "^25.2.0",
|
|
49
|
+
"@types/prettier": "^3.0.0",
|
|
50
|
+
"eslint": "^9.39.2",
|
|
51
|
+
"typescript": "^5.9.3"
|
|
52
|
+
}
|
|
53
|
+
}
|