@ui5/task-adaptation 1.6.0 → 1.6.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.
- package/CHANGELOG.md +28 -9
- package/dist/adapters/abapAdapter.d.ts +14 -0
- package/dist/adapters/abapAdapter.js +45 -0
- package/dist/adapters/adapter.d.ts +8 -0
- package/dist/adapters/adapter.js +2 -0
- package/dist/adapters/cfAdapter.d.ts +12 -0
- package/dist/adapters/cfAdapter.js +46 -0
- package/dist/adapters/commands/addAppVariantIdHierarchyCommand.d.ts +7 -0
- package/dist/adapters/commands/addAppVariantIdHierarchyCommand.js +17 -0
- package/dist/adapters/commands/applyDescriptorChangesCommand.d.ts +10 -0
- package/dist/adapters/commands/applyDescriptorChangesCommand.js +43 -0
- package/dist/adapters/commands/command.d.ts +84 -0
- package/dist/adapters/commands/command.js +108 -0
- package/dist/adapters/commands/downloadAnnotationsCommand.d.ts +12 -0
- package/dist/adapters/commands/downloadAnnotationsCommand.js +26 -0
- package/dist/{util/i18nMerger.d.ts → adapters/commands/i18nPropertiesMergeCommand.d.ts} +13 -10
- package/dist/{util/i18nMerger.js → adapters/commands/i18nPropertiesMergeCommand.js} +30 -27
- package/dist/adapters/commands/setAppVariantIdCommand.d.ts +7 -0
- package/dist/adapters/commands/setAppVariantIdCommand.js +15 -0
- package/dist/adapters/commands/updateCloudDevAdaptationCommand.d.ts +4 -0
- package/dist/adapters/commands/updateCloudDevAdaptationCommand.js +11 -0
- package/dist/adapters/commands/updateCloudPlatformCommand.d.ts +6 -0
- package/dist/adapters/commands/updateCloudPlatformCommand.js +23 -0
- package/dist/adapters/commands/updateComponentNameCommand.d.ts +6 -0
- package/dist/adapters/commands/updateComponentNameCommand.js +13 -0
- package/dist/adapters/commands/xsAppJsonEnhanceRoutesCommand.d.ts +7 -0
- package/dist/adapters/commands/xsAppJsonEnhanceRoutesCommand.js +36 -0
- package/dist/adapters/commands/xsAppJsonMergeCommand.d.ts +5 -0
- package/dist/adapters/commands/xsAppJsonMergeCommand.js +17 -0
- package/dist/adapters/previewAdapter.d.ts +6 -0
- package/dist/adapters/previewAdapter.js +8 -0
- package/dist/appVariantManager.js +3 -0
- package/dist/baseAppManager.d.ts +0 -8
- package/dist/baseAppManager.js +3 -69
- package/dist/bundle.js +37 -35
- package/dist/cache/cacheHolder.js +9 -4
- package/dist/index.js +7 -3
- package/dist/model/appVariantIdHierarchyItem.d.ts +6 -1
- package/dist/model/types.d.ts +6 -0
- package/dist/previewManager.js +16 -23
- package/dist/processors/abapProcessor.d.ts +3 -7
- package/dist/processors/abapProcessor.js +4 -15
- package/dist/processors/cfProcessor.d.ts +5 -11
- package/dist/processors/cfProcessor.js +4 -90
- package/dist/processors/previewProcessor.d.ts +8 -0
- package/dist/processors/previewProcessor.js +11 -0
- package/dist/processors/processor.d.ts +3 -3
- package/dist/processors/processor.js +9 -0
- package/dist/repositories/abapRepoManager.d.ts +1 -1
- package/dist/repositories/html5RepoManager.js +6 -0
- package/dist/util/cf/xsAppJsonUtil.d.ts +13 -0
- package/dist/util/cf/xsAppJsonUtil.js +81 -0
- package/dist/util/cfUtil.d.ts +3 -3
- package/dist/util/cfUtil.js +1 -1
- package/dist/util/filesUtil.d.ts +3 -2
- package/dist/util/filesUtil.js +20 -4
- package/dist/util/fsUtil.d.ts +9 -0
- package/dist/util/fsUtil.js +40 -0
- package/dist/util/movingHandler/changeFileMoveHandler.js +2 -3
- package/dist/util/objectPath.d.ts +19 -0
- package/dist/util/objectPath.js +62 -0
- package/dist/util/renamingHandlers/jsonRenamingHandler.d.ts +12 -0
- package/dist/util/renamingHandlers/jsonRenamingHandler.js +34 -0
- package/dist/util/renamingHandlers/manifestRenamingHandler.d.ts +4 -5
- package/dist/util/renamingHandlers/manifestRenamingHandler.js +7 -18
- package/dist/util/requestUtil.d.ts +1 -1
- package/dist/util/requestUtil.js +5 -2
- package/dist/util/resourceUtil.d.ts +0 -7
- package/dist/util/resourceUtil.js +0 -36
- package/package.json +3 -2
- package/dist/util/movingHandler/fileMoveHandler.d.ts +0 -8
- package/dist/util/movingHandler/fileMoveHandler.js +0 -77
- package/scripts/publish.ts +0 -256
- package/scripts/test-integration-prep.sh +0 -4
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export default class JsonRenamingHandler {
|
|
2
|
+
original = new Map();
|
|
3
|
+
before(files) {
|
|
4
|
+
const content = files.get(this.filePath);
|
|
5
|
+
if (content) {
|
|
6
|
+
const json = JSON.parse(content);
|
|
7
|
+
this.jsonPathsToRestore.forEach(path => this.store(json, path));
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
after(files) {
|
|
11
|
+
const content = files.get(this.filePath);
|
|
12
|
+
if (content) {
|
|
13
|
+
const json = JSON.parse(content);
|
|
14
|
+
this.restore(json);
|
|
15
|
+
files.set(this.filePath, JSON.stringify(json));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
store(obj, path) {
|
|
19
|
+
this.original.set(path, this.getByPath(obj, path.split("/")));
|
|
20
|
+
}
|
|
21
|
+
restore(obj) {
|
|
22
|
+
this.original.forEach((value, path) => this.setByPath(obj, value, path.split("/")));
|
|
23
|
+
}
|
|
24
|
+
getByPath(obj, path) {
|
|
25
|
+
return path.reduce((o, p) => (o && o[p]) || undefined, obj);
|
|
26
|
+
}
|
|
27
|
+
setByPath(obj, value, path) {
|
|
28
|
+
const target = this.getByPath(obj, path.slice(0, -1));
|
|
29
|
+
if (target) {
|
|
30
|
+
target[path[path.length - 1]] = value;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=jsonRenamingHandler.js.map
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
export default class ManifestRenamingHandler
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
after(files: Map<string, string>): void;
|
|
1
|
+
import JsonRenamingHandler from "./jsonRenamingHandler.js";
|
|
2
|
+
export default class ManifestRenamingHandler extends JsonRenamingHandler {
|
|
3
|
+
protected readonly filePath = "manifest.json";
|
|
4
|
+
protected readonly jsonPathsToRestore: string[];
|
|
6
5
|
}
|
|
@@ -1,20 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
after(files) {
|
|
11
|
-
const manifest = files.get("manifest.json");
|
|
12
|
-
if (manifest) {
|
|
13
|
-
const manifestJson = JSON.parse(manifest);
|
|
14
|
-
manifestJson["sap.ui5"].appVariantIdHierarchy = this.appVariantIdHierarchy;
|
|
15
|
-
files.set("manifest.json", JSON.stringify(manifestJson));
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
;
|
|
1
|
+
import JsonRenamingHandler from "./jsonRenamingHandler.js";
|
|
2
|
+
export default class ManifestRenamingHandler extends JsonRenamingHandler {
|
|
3
|
+
filePath = "manifest.json";
|
|
4
|
+
// path to the JSON properties, forward slash separated, e.g. "sap.ui5/appVariantIdHierarchy"
|
|
5
|
+
jsonPathsToRestore = [
|
|
6
|
+
"sap.ui5/appVariantIdHierarchy"
|
|
7
|
+
];
|
|
19
8
|
}
|
|
20
9
|
//# sourceMappingURL=manifestRenamingHandler.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from "axios";
|
|
2
2
|
export default class RequestUtil {
|
|
3
3
|
static head(url: string): Promise<any>;
|
|
4
|
-
static get(url: string, options?:
|
|
4
|
+
static get(url: string, options: any, expectedStatus?: number): Promise<any>;
|
|
5
5
|
static request(url: string, method: (url: string, config?: AxiosRequestConfig) => any, options?: any): Promise<any>;
|
|
6
6
|
private static handleError;
|
|
7
7
|
}
|
package/dist/util/requestUtil.js
CHANGED
|
@@ -4,8 +4,11 @@ export default class RequestUtil {
|
|
|
4
4
|
static async head(url) {
|
|
5
5
|
return this.request(url, axios.head);
|
|
6
6
|
}
|
|
7
|
-
static async get(url, options) {
|
|
8
|
-
return this.request(url, axios.get,
|
|
7
|
+
static async get(url, options, expectedStatus = 200) {
|
|
8
|
+
return this.request(url, axios.get, {
|
|
9
|
+
...options,
|
|
10
|
+
validateStatus: (status) => status === expectedStatus
|
|
11
|
+
}).then(response => response.data);
|
|
9
12
|
}
|
|
10
13
|
static async request(url, method, options) {
|
|
11
14
|
try {
|
|
@@ -6,16 +6,9 @@ export default class ResourceUtil {
|
|
|
6
6
|
static writeInProject(dir: string, files: Map<string, string>): Promise<void[]>;
|
|
7
7
|
static byGlob(dir: string, pattern: string, excludes?: string[]): Promise<Map<string, string>>;
|
|
8
8
|
static byGlobInProject(pattern: string, excludes?: string[]): Promise<Map<string, string>>;
|
|
9
|
-
static readInProject(filepath: string): Promise<string>;
|
|
10
9
|
static getString(resource: any): Promise<string>;
|
|
11
10
|
static getJson(resource: any): Promise<any>;
|
|
12
11
|
static setString(resource: any, str: string): void;
|
|
13
|
-
/**
|
|
14
|
-
* Check whether a file or directory exists (non-throwing).
|
|
15
|
-
* @param filePath Absolute or relative path
|
|
16
|
-
* @returns true if the path exists, false if not
|
|
17
|
-
*/
|
|
18
|
-
private static fileExists;
|
|
19
12
|
static createResource(filename: string, projectNamespace: string, content: string): any;
|
|
20
13
|
static toFileMap(resources: ReadonlyArray<Resource>, projectNamespace?: string): Promise<Map<string, string>>;
|
|
21
14
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as resourceFactory from "@ui5/fs/resourceFactory";
|
|
2
2
|
import { posix as path } from "path";
|
|
3
|
-
import * as fs from "fs/promises";
|
|
4
3
|
const UTF8 = "utf8";
|
|
5
4
|
export default class ResourceUtil {
|
|
6
5
|
static getRootFolder(projectNamespace) {
|
|
@@ -78,24 +77,6 @@ export default class ResourceUtil {
|
|
|
78
77
|
"/.adp/reuse"
|
|
79
78
|
].concat(excludes));
|
|
80
79
|
}
|
|
81
|
-
/*
|
|
82
|
-
* Read the file by filepath from the project root (folder where 'webapp',
|
|
83
|
-
* 'package.json', 'ui5.yaml' located).
|
|
84
|
-
* @param filepath The relative file path from the project root (e.g. 'ui5AppInfo.json').
|
|
85
|
-
* @returns A promise that resolves to the file content as a string.
|
|
86
|
-
*/
|
|
87
|
-
static async readInProject(filepath) {
|
|
88
|
-
try {
|
|
89
|
-
return await fs.readFile(path.resolve(process.cwd(), filepath), UTF8);
|
|
90
|
-
}
|
|
91
|
-
catch (error) {
|
|
92
|
-
const isProjectRoot = await ResourceUtil.fileExists(path.join(process.cwd(), "ui5.yaml"));
|
|
93
|
-
if (!isProjectRoot) {
|
|
94
|
-
throw new Error(`Please make sure that build has been started from the project root: ${error?.message ?? ""}`);
|
|
95
|
-
}
|
|
96
|
-
throw error;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
80
|
static getString(resource) {
|
|
100
81
|
return resource.getBuffer().then((buffer) => buffer.toString(UTF8));
|
|
101
82
|
}
|
|
@@ -105,23 +86,6 @@ export default class ResourceUtil {
|
|
|
105
86
|
static setString(resource, str) {
|
|
106
87
|
resource.setBuffer(Buffer.from(str, UTF8));
|
|
107
88
|
}
|
|
108
|
-
/**
|
|
109
|
-
* Check whether a file or directory exists (non-throwing).
|
|
110
|
-
* @param filePath Absolute or relative path
|
|
111
|
-
* @returns true if the path exists, false if not
|
|
112
|
-
*/
|
|
113
|
-
static async fileExists(filePath) {
|
|
114
|
-
try {
|
|
115
|
-
await fs.access(filePath);
|
|
116
|
-
return true;
|
|
117
|
-
}
|
|
118
|
-
catch (e) {
|
|
119
|
-
if (e?.code === "ENOENT") {
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
throw e;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
89
|
static createResource(filename, projectNamespace, content) {
|
|
126
90
|
return resourceFactory.createResource({
|
|
127
91
|
path: this.getResourcePath(projectNamespace, filename),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ui5/task-adaptation",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "Custom task for ui5-builder which allows building UI5 Flexibility Adaptation Projects for SAP BTP, Cloud Foundry environment",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -114,7 +114,8 @@
|
|
|
114
114
|
"src/annotations/comparator/diffCase.ts",
|
|
115
115
|
"src/annotations/transformers/transformer.ts",
|
|
116
116
|
"src/model/configuration.ts",
|
|
117
|
-
"src/model/appVariantIdHierarchyItem.ts"
|
|
117
|
+
"src/model/appVariantIdHierarchyItem.ts",
|
|
118
|
+
"src/adapters/adapter.ts"
|
|
118
119
|
],
|
|
119
120
|
"check-coverage": true,
|
|
120
121
|
"statements": 85,
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export declare const moveFiles: (inputFiles: ReadonlyMap<string, string>, prefix: string, id: string) => {
|
|
2
|
-
files: Map<string, string>;
|
|
3
|
-
renamingPaths: Map<string, string>;
|
|
4
|
-
};
|
|
5
|
-
export declare const moveFile: (filename: string, content: string, prefix: string, id: string) => {
|
|
6
|
-
newFilename: string;
|
|
7
|
-
renamingPath: Map<string, string>;
|
|
8
|
-
};
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import { isManifestChange } from "../commonUtil.js";
|
|
3
|
-
const EXT_DIR = "ext/";
|
|
4
|
-
const CHANGES_DIR = "changes/";
|
|
5
|
-
const nameSpaceRegex = new RegExp(`(?<=ControllerExtension.extend\\(")([^"]*)(?=")`);
|
|
6
|
-
/**
|
|
7
|
-
* 2p. We move to appVariantFolder (prefix) only files that go along the
|
|
8
|
-
* change files, like js or fragments. Changes are renamed in resources,
|
|
9
|
-
* packed in flexibility-bundle and removed.
|
|
10
|
-
* @param filename - The filename relative to the root
|
|
11
|
-
*/
|
|
12
|
-
function shouldMove(filename, content) {
|
|
13
|
-
//TODO: is it more reliable to check change/fileType?
|
|
14
|
-
if (isManifestChange(filename, content)) {
|
|
15
|
-
return true;
|
|
16
|
-
}
|
|
17
|
-
return filename.startsWith(CHANGES_DIR) && [".change", ".variant", ".ctrl_variant", ".ctrl_variant_change", ".ctrl_variant_management_change"].every(ext => !filename.endsWith(ext))
|
|
18
|
-
|| filename.startsWith(EXT_DIR);
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* For controller extension the namespace needs a prefix
|
|
22
|
-
* The namespace needs to be unique for clear identification
|
|
23
|
-
* If controller extension have the same namespace the last one will be used
|
|
24
|
-
* @param filename - The filename relative to the root
|
|
25
|
-
* @returns
|
|
26
|
-
*/
|
|
27
|
-
function shouldNamespaceRenamed(filename) {
|
|
28
|
-
return filename.startsWith(CHANGES_DIR) && filename.endsWith(".js");
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Returns path without first directory (which is usually "changes" or
|
|
32
|
-
* "ext") and without file extension. For example, for
|
|
33
|
-
* "changes/coding/FixingDay.js" it returns "coding/FixingDay", for
|
|
34
|
-
* "changes/customer_app_variant5/fragments/hello_world_fixing_day.fragment.xml"
|
|
35
|
-
* it returns
|
|
36
|
-
* "changes/customer_app_variant5/fragments/hello_world_fixing_day". We
|
|
37
|
-
* remove all extensions not to rename it with slashes instead of dots. And
|
|
38
|
-
* we also exclude "changes" or "ext" include the prefix after them and then
|
|
39
|
-
* the filename. Without 'changes' or 'ext' directory, we need to replace
|
|
40
|
-
* only rest: coding/FixingDay.js to app_var_id1/coding/FixingDay.js
|
|
41
|
-
* @param filename
|
|
42
|
-
* @returns
|
|
43
|
-
*/
|
|
44
|
-
function getPathWithoutExtensions(filename) {
|
|
45
|
-
const [_dir, ...rest] = filename.split("/");
|
|
46
|
-
const restWOExt = [...rest];
|
|
47
|
-
restWOExt[restWOExt.length - 1] = restWOExt[restWOExt.length - 1].split(".")[0];
|
|
48
|
-
return restWOExt.join("/");
|
|
49
|
-
}
|
|
50
|
-
export const moveFiles = (inputFiles, prefix, id) => {
|
|
51
|
-
const files = new Map();
|
|
52
|
-
let renamingPaths = new Map();
|
|
53
|
-
inputFiles.forEach((content, filename) => {
|
|
54
|
-
const { newFilename, renamingPath } = moveFile(filename, content, prefix, id);
|
|
55
|
-
files.set(newFilename, content);
|
|
56
|
-
renamingPaths = new Map([...renamingPaths, ...renamingPath]);
|
|
57
|
-
});
|
|
58
|
-
return { files, renamingPaths };
|
|
59
|
-
};
|
|
60
|
-
export const moveFile = (filename, content, prefix, id) => {
|
|
61
|
-
let newFilename = filename;
|
|
62
|
-
let renamingPath = new Map();
|
|
63
|
-
if (shouldMove(filename, content)) {
|
|
64
|
-
const [dir, ...rest] = filename.split("/");
|
|
65
|
-
newFilename = path.join(dir, prefix, rest.join("/"));
|
|
66
|
-
const restWOExtPath = getPathWithoutExtensions(filename);
|
|
67
|
-
renamingPath.set(restWOExtPath, path.join(prefix, restWOExtPath));
|
|
68
|
-
}
|
|
69
|
-
if (shouldNamespaceRenamed(filename)) {
|
|
70
|
-
const namespaceMatch = nameSpaceRegex.exec(content.trim());
|
|
71
|
-
const controllerExtensionPath = namespaceMatch ? namespaceMatch[0] : "";
|
|
72
|
-
const fileName = controllerExtensionPath.replace(id, "");
|
|
73
|
-
renamingPath.set(controllerExtensionPath, `${id}.${prefix}${fileName}`);
|
|
74
|
-
}
|
|
75
|
-
return { newFilename, renamingPath };
|
|
76
|
-
};
|
|
77
|
-
//# sourceMappingURL=fileMoveHandler.js.map
|
package/scripts/publish.ts
DELETED
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import { promises as fs } from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import yargs from "yargs";
|
|
4
|
-
import { hideBin } from "yargs/helpers";
|
|
5
|
-
import { Octokit } from "@octokit/rest";
|
|
6
|
-
import { retry } from "@octokit/plugin-retry";
|
|
7
|
-
|
|
8
|
-
const OctokitClass = Octokit.plugin(retry);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Recursively get all file paths in the workspace root, excluding:
|
|
13
|
-
* - test/lib/integration
|
|
14
|
-
* - test/fixtures
|
|
15
|
-
* - test/expected
|
|
16
|
-
* - test/lib/index.perf.ts
|
|
17
|
-
* Returns relative paths from the root.
|
|
18
|
-
*/
|
|
19
|
-
async function getAllRootFilesExceptTestExclusions(root: string): Promise<string[]> {
|
|
20
|
-
const excludeDirs = [
|
|
21
|
-
"test/lib/integration",
|
|
22
|
-
"test/fixtures",
|
|
23
|
-
"test/expected",
|
|
24
|
-
".git",
|
|
25
|
-
"coverage",
|
|
26
|
-
".DS_Store",
|
|
27
|
-
"node_modules",
|
|
28
|
-
".nyc_output",
|
|
29
|
-
"coverage",
|
|
30
|
-
"dist",
|
|
31
|
-
"dist-debug",
|
|
32
|
-
"dist.zip",
|
|
33
|
-
".env",
|
|
34
|
-
"test/resources/metadata/download"
|
|
35
|
-
];
|
|
36
|
-
const excludeFiles = [
|
|
37
|
-
"test/lib/index.perf.ts",
|
|
38
|
-
"scripts/test-integration-prep.sh",
|
|
39
|
-
"Jenkinsfile"
|
|
40
|
-
];
|
|
41
|
-
|
|
42
|
-
async function walk(dir: string): Promise<string[]> {
|
|
43
|
-
const dirents = await fs.readdir(dir, { withFileTypes: true });
|
|
44
|
-
const files: string[] = [];
|
|
45
|
-
for (const dirent of dirents) {
|
|
46
|
-
const relPath = path.relative(root, path.join(dir, dirent.name));
|
|
47
|
-
if (excludeDirs.some(ex => relPath === ex || relPath.startsWith(ex + path.sep))) {
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
if (excludeFiles.includes(relPath)) {
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
if (dirent.isDirectory()) {
|
|
54
|
-
files.push(...await walk(path.join(dir, dirent.name)));
|
|
55
|
-
} else {
|
|
56
|
-
files.push(relPath);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return files;
|
|
60
|
-
}
|
|
61
|
-
return walk(root);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const FILES = await getAllRootFilesExceptTestExclusions(process.cwd());
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
interface PublishArgs {
|
|
68
|
-
p?: string;
|
|
69
|
-
dryRun?: boolean;
|
|
70
|
-
tag?: string;
|
|
71
|
-
branch?: string;
|
|
72
|
-
[key: string]: unknown;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
async function publish() {
|
|
76
|
-
const argv = yargs(hideBin(process.argv))
|
|
77
|
-
.option("p", {
|
|
78
|
-
type: "string",
|
|
79
|
-
description: "GitHub token (-p)",
|
|
80
|
-
alias: "p"
|
|
81
|
-
})
|
|
82
|
-
.option("dryRun", {
|
|
83
|
-
type: "boolean",
|
|
84
|
-
description: "Run without publishing",
|
|
85
|
-
default: false
|
|
86
|
-
})
|
|
87
|
-
.option("tag", {
|
|
88
|
-
type: "string",
|
|
89
|
-
description: "Publish with a specific tag"
|
|
90
|
-
})
|
|
91
|
-
.option("branch", {
|
|
92
|
-
type: "string",
|
|
93
|
-
description: "Branch to update (default: main)",
|
|
94
|
-
default: "main",
|
|
95
|
-
alias: "b"
|
|
96
|
-
})
|
|
97
|
-
.help()
|
|
98
|
-
.alias("h", "help")
|
|
99
|
-
.parseSync() as PublishArgs;
|
|
100
|
-
|
|
101
|
-
if (argv.dryRun) {
|
|
102
|
-
console.log("Dry run: no publishing will be performed.");
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
const auth = argv.p;
|
|
106
|
-
if (auth) {
|
|
107
|
-
const octokit = new OctokitClass({ auth });
|
|
108
|
-
const ORGANIZATION = "SAP";
|
|
109
|
-
const REPO = "ui5-task-adaptation";
|
|
110
|
-
await uploadToRepo(octokit, ORGANIZATION, REPO, argv.branch);
|
|
111
|
-
if (argv.tag) {
|
|
112
|
-
console.log(`Published with tag: ${argv.tag}`);
|
|
113
|
-
}
|
|
114
|
-
} else {
|
|
115
|
-
console.log("Github token is not provided.");
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
async function getLatestVersion(): Promise<string> {
|
|
121
|
-
const pkg = await fs.readFile(path.join(process.cwd(), "package.json"), { encoding: "utf-8" });
|
|
122
|
-
const pkgJson = JSON.parse(pkg);
|
|
123
|
-
return pkgJson.version;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
async function uploadToRepo(
|
|
128
|
-
octokit: InstanceType<typeof OctokitClass>,
|
|
129
|
-
org: string,
|
|
130
|
-
repo: string,
|
|
131
|
-
branch: string = "main"
|
|
132
|
-
): Promise<void> {
|
|
133
|
-
const fileBlobs = await Promise.all(Object.values(FILES).map(file => toBlob(octokit, org, repo, path.join(process.cwd(), file))));
|
|
134
|
-
const currentCommit = await getCurrentCommit(octokit, org, repo, branch);
|
|
135
|
-
const newTree = await createNewTree(
|
|
136
|
-
octokit,
|
|
137
|
-
org,
|
|
138
|
-
repo,
|
|
139
|
-
fileBlobs,
|
|
140
|
-
FILES,
|
|
141
|
-
currentCommit.treeSha
|
|
142
|
-
);
|
|
143
|
-
const currentVersion = await getLatestVersion();
|
|
144
|
-
const commitMessage = `Release ${currentVersion}`;
|
|
145
|
-
const newCommit = await createNewCommit(
|
|
146
|
-
octokit,
|
|
147
|
-
org,
|
|
148
|
-
repo,
|
|
149
|
-
commitMessage,
|
|
150
|
-
newTree.sha,
|
|
151
|
-
currentCommit.commitSha
|
|
152
|
-
);
|
|
153
|
-
await setBranchToCommit(octokit, org, repo, branch, newCommit.sha);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
async function getCurrentCommit(
|
|
158
|
-
octokit: InstanceType<typeof OctokitClass>,
|
|
159
|
-
org: string,
|
|
160
|
-
repo: string,
|
|
161
|
-
branch: string = "main"
|
|
162
|
-
): Promise<{ commitSha: string; treeSha: string }> {
|
|
163
|
-
const { data: refData } = await octokit.git.getRef({
|
|
164
|
-
owner: org,
|
|
165
|
-
repo,
|
|
166
|
-
ref: `heads/${branch}`,
|
|
167
|
-
});
|
|
168
|
-
const commitSha = refData.object.sha
|
|
169
|
-
const { data: commitData } = await octokit.git.getCommit({
|
|
170
|
-
owner: org,
|
|
171
|
-
repo,
|
|
172
|
-
commit_sha: commitSha,
|
|
173
|
-
});
|
|
174
|
-
return {
|
|
175
|
-
commitSha,
|
|
176
|
-
treeSha: commitData.tree.sha,
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
async function toBlob(
|
|
182
|
-
octokit: InstanceType<typeof OctokitClass>,
|
|
183
|
-
org: string,
|
|
184
|
-
repo: string,
|
|
185
|
-
filePath: string
|
|
186
|
-
): Promise<{ sha: string }> {
|
|
187
|
-
const content = await fs.readFile(filePath, { encoding: "utf8" });
|
|
188
|
-
const blobData = await octokit.git.createBlob({
|
|
189
|
-
owner: org,
|
|
190
|
-
repo,
|
|
191
|
-
content,
|
|
192
|
-
encoding: "utf-8",
|
|
193
|
-
})
|
|
194
|
-
return blobData.data;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
async function createNewTree(
|
|
199
|
-
octokit: InstanceType<typeof OctokitClass>,
|
|
200
|
-
owner: string,
|
|
201
|
-
repo: string,
|
|
202
|
-
blobs: { sha: string }[],
|
|
203
|
-
paths: string[],
|
|
204
|
-
parentTreeSha: string
|
|
205
|
-
): Promise<any> {
|
|
206
|
-
const tree = blobs.map(({ sha }, i) => ({
|
|
207
|
-
path: paths[i],
|
|
208
|
-
mode: "100644" as const,
|
|
209
|
-
type: "blob" as const,
|
|
210
|
-
sha,
|
|
211
|
-
}));
|
|
212
|
-
const { data } = await octokit.git.createTree({
|
|
213
|
-
owner,
|
|
214
|
-
repo,
|
|
215
|
-
tree,
|
|
216
|
-
base_tree: parentTreeSha,
|
|
217
|
-
})
|
|
218
|
-
return data;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
async function createNewCommit(
|
|
223
|
-
octokit: InstanceType<typeof OctokitClass>,
|
|
224
|
-
org: string,
|
|
225
|
-
repo: string,
|
|
226
|
-
message: string,
|
|
227
|
-
currentTreeSha: string,
|
|
228
|
-
currentCommitSha: string
|
|
229
|
-
): Promise<any> {
|
|
230
|
-
const commit = await octokit.git.createCommit({
|
|
231
|
-
owner: org,
|
|
232
|
-
repo,
|
|
233
|
-
message,
|
|
234
|
-
tree: currentTreeSha,
|
|
235
|
-
parents: [currentCommitSha],
|
|
236
|
-
});
|
|
237
|
-
return commit.data;
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
async function setBranchToCommit(
|
|
242
|
-
octokit: InstanceType<typeof OctokitClass>,
|
|
243
|
-
org: string,
|
|
244
|
-
repo: string,
|
|
245
|
-
branch: string = "main",
|
|
246
|
-
commitSha: string
|
|
247
|
-
): Promise<any> {
|
|
248
|
-
return octokit.git.updateRef({
|
|
249
|
-
owner: org,
|
|
250
|
-
repo,
|
|
251
|
-
ref: `heads/${branch}`,
|
|
252
|
-
sha: commitSha,
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
publish();
|