@datapos/datapos-development 0.3.39 â 0.3.41
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/index.js +122 -0
- package/dist/types/src/index.d.ts +9 -0
- package/dist/types/vite.config.d.ts +5 -0
- package/package.json +31 -11
- package/.prettierrc.json +0 -23
- package/.vscode/settings.json +0 -7
- package/LICENSES.json +0 -1
- package/eslint.config.js +0 -15
- package/index.js +0 -182
package/dist/index.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { exec as exec$1 } from "child_process";
|
|
2
|
+
import { promises } from "fs";
|
|
3
|
+
import { promisify } from "util";
|
|
4
|
+
import { CONNECTOR_DESTINATION_OPERATIONS, CONNECTOR_SOURCE_OPERATIONS } from "@datapos/datapos-shared";
|
|
5
|
+
const exec = promisify(exec$1);
|
|
6
|
+
async function buildConnectorConfig() {
|
|
7
|
+
try {
|
|
8
|
+
console.log("đ Building connector configuration...");
|
|
9
|
+
const packageJSON = JSON.parse(await promises.readFile("package.json", "utf8"));
|
|
10
|
+
const configJSON = JSON.parse(await promises.readFile("config.json", "utf8"));
|
|
11
|
+
const indexCode = await promises.readFile("src/index.ts", "utf8");
|
|
12
|
+
let destinationOperations = false;
|
|
13
|
+
let sourceOperations = false;
|
|
14
|
+
const regex = /^\s{4}(?:async\s+)?(private\s+)?(?:public\s+|protected\s+)?([A-Za-z_]\w*)\s*\(/gm;
|
|
15
|
+
const operations = [...indexCode.matchAll(regex)].filter((m) => !m[1] && m[2] !== "constructor").map((m) => {
|
|
16
|
+
const operation = m[2];
|
|
17
|
+
destinationOperations = destinationOperations || CONNECTOR_DESTINATION_OPERATIONS.includes(operation);
|
|
18
|
+
sourceOperations = sourceOperations || CONNECTOR_SOURCE_OPERATIONS.includes(operation);
|
|
19
|
+
return operation;
|
|
20
|
+
});
|
|
21
|
+
if (operations.length > 0) console.log(`âšī¸ Implements ${operations.length} operations.`);
|
|
22
|
+
else console.log("â ī¸ Implements no operations.");
|
|
23
|
+
const usageId = sourceOperations && destinationOperations ? "bidirectional" : sourceOperations ? "source" : destinationOperations ? "destination" : null;
|
|
24
|
+
if (usageId) console.log(`âšī¸ Supports ${usageId} usage.`);
|
|
25
|
+
else console.log("â ī¸ No usage identified.");
|
|
26
|
+
if (packageJSON.name) configJSON.id = packageJSON.name;
|
|
27
|
+
configJSON.operations = operations;
|
|
28
|
+
configJSON.usageId = usageId;
|
|
29
|
+
if (packageJSON.version) configJSON.version = packageJSON.version;
|
|
30
|
+
await promises.writeFile("config.json", JSON.stringify(configJSON, void 0, 4), "utf8");
|
|
31
|
+
console.log("â
Connector configuration built.");
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.warn("â Error building connector configuration.", error);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function buildContextConfig() {
|
|
37
|
+
try {
|
|
38
|
+
console.log("đ Building context configuration...");
|
|
39
|
+
const packageJSON = JSON.parse(await promises.readFile("package.json", "utf8"));
|
|
40
|
+
const configJSON = JSON.parse(await promises.readFile("config.json", "utf8"));
|
|
41
|
+
const indexCode = await promises.readFile("src/index.ts", "utf8");
|
|
42
|
+
const regex = /^\s{4}(?:async\s+)?(private\s+)?(?:public\s+|protected\s+)?([A-Za-z_]\w*)\s*\(/gm;
|
|
43
|
+
const operations = [...indexCode.matchAll(regex)].filter((m) => !m[1] && m[2] !== "constructor").map((m) => m[2]);
|
|
44
|
+
if (packageJSON.name) configJSON.id = packageJSON.name;
|
|
45
|
+
configJSON.operations = operations;
|
|
46
|
+
if (packageJSON.version) configJSON.version = packageJSON.version;
|
|
47
|
+
await promises.writeFile("config.json", JSON.stringify(configJSON, void 0, 4), "utf8");
|
|
48
|
+
} catch (error) {
|
|
49
|
+
console.warn("â Error building context configuration.", error);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async function buildInformerConfig() {
|
|
53
|
+
try {
|
|
54
|
+
console.log("đ Building informer configuration...");
|
|
55
|
+
const packageJSON = JSON.parse(await promises.readFile("package.json", "utf8"));
|
|
56
|
+
const configJSON = JSON.parse(await promises.readFile("config.json", "utf8"));
|
|
57
|
+
const indexCode = await promises.readFile("src/index.ts", "utf8");
|
|
58
|
+
const regex = /^\s{4}(?:async\s+)?(private\s+)?(?:public\s+|protected\s+)?([A-Za-z_]\w*)\s*\(/gm;
|
|
59
|
+
const operations = [...indexCode.matchAll(regex)].filter((m) => !m[1] && m[2] !== "constructor").map((m) => m[2]);
|
|
60
|
+
if (packageJSON.name) configJSON.id = packageJSON.name;
|
|
61
|
+
configJSON.operations = operations;
|
|
62
|
+
if (packageJSON.version) configJSON.version = packageJSON.version;
|
|
63
|
+
await promises.writeFile("config.json", JSON.stringify(configJSON, void 0, 4), "utf8");
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.warn("â Error building informer configuration.", error);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async function buildPresenterConfig() {
|
|
69
|
+
try {
|
|
70
|
+
console.log("đ Building presenter configuration...");
|
|
71
|
+
const packageJSON = JSON.parse(await promises.readFile("package.json", "utf8"));
|
|
72
|
+
const configJSON = JSON.parse(await promises.readFile("config.json", "utf8"));
|
|
73
|
+
const indexCode = await promises.readFile("src/index.ts", "utf8");
|
|
74
|
+
const regex = /^\s{4}(?:async\s+)?(private\s+)?(?:public\s+|protected\s+)?([A-Za-z_]\w*)\s*\(/gm;
|
|
75
|
+
const operations = [...indexCode.matchAll(regex)].filter((m) => !m[1] && m[2] !== "constructor").map((m) => m[2]);
|
|
76
|
+
if (packageJSON.name) configJSON.id = packageJSON.name;
|
|
77
|
+
configJSON.operations = operations;
|
|
78
|
+
if (packageJSON.version) configJSON.version = packageJSON.version;
|
|
79
|
+
await promises.writeFile("config.json", JSON.stringify(configJSON, void 0, 4), "utf8");
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.warn("â Error building context configuration.", error);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
async function bumpVersion() {
|
|
85
|
+
try {
|
|
86
|
+
console.log("đ Bumping version...");
|
|
87
|
+
const packageJSON = JSON.parse(await promises.readFile("package.json", "utf8"));
|
|
88
|
+
if (packageJSON.version) {
|
|
89
|
+
const oldVersion = packageJSON.version;
|
|
90
|
+
const versionSegments = packageJSON.version.split(".");
|
|
91
|
+
packageJSON.version = `${versionSegments[0]}.${versionSegments[1]}.${Number(versionSegments[2]) + 1}`;
|
|
92
|
+
await promises.writeFile("package.json", JSON.stringify(packageJSON, void 0, 4), "utf8");
|
|
93
|
+
console.log(`â
Version bumped from ${oldVersion} to ${packageJSON.version}.`);
|
|
94
|
+
} else {
|
|
95
|
+
packageJSON.version = "0.0.001";
|
|
96
|
+
await promises.writeFile("package.json", JSON.stringify(packageJSON, void 0, 4), "utf8");
|
|
97
|
+
console.log(`â ī¸ Version initialised to ${packageJSON.version}.`);
|
|
98
|
+
}
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.warn("â Error bumping package version.", error);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async function syncWithGitHub() {
|
|
104
|
+
try {
|
|
105
|
+
console.log("đ Synchronising with GitHub....");
|
|
106
|
+
const packageJSON = JSON.parse(await promises.readFile("package.json", "utf8"));
|
|
107
|
+
await exec("git add .");
|
|
108
|
+
await exec(`git commit -m "v${packageJSON.version}"`);
|
|
109
|
+
await exec("git push origin main:main");
|
|
110
|
+
console.log(`â
Synchronised version ${packageJSON.version} with GitHub.`);
|
|
111
|
+
} catch (error) {
|
|
112
|
+
console.warn("â Error synchronising with GitHub.", error);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
export {
|
|
116
|
+
buildConnectorConfig,
|
|
117
|
+
buildContextConfig,
|
|
118
|
+
buildInformerConfig,
|
|
119
|
+
buildPresenterConfig,
|
|
120
|
+
bumpVersion,
|
|
121
|
+
syncWithGitHub
|
|
122
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Development utilities.
|
|
3
|
+
*/
|
|
4
|
+
export declare function buildConnectorConfig(): Promise<void>;
|
|
5
|
+
export declare function buildContextConfig(): Promise<void>;
|
|
6
|
+
export declare function buildInformerConfig(): Promise<void>;
|
|
7
|
+
export declare function buildPresenterConfig(): Promise<void>;
|
|
8
|
+
export declare function bumpVersion(): Promise<void>;
|
|
9
|
+
export declare function syncWithGitHub(): Promise<void>;
|
package/package.json
CHANGED
|
@@ -3,26 +3,46 @@
|
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
6
|
+
"version": "0.3.41",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"module": "./dist/datapos-development.es.js",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/datapos-development.es.js",
|
|
14
|
+
"types": "./dist/types/src/index.d.ts"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"types": "./dist/types/src/index.d.ts",
|
|
8
18
|
"devDependencies": {
|
|
9
|
-
"
|
|
10
|
-
"
|
|
19
|
+
"@datapos/datapos-shared": "^0.3.139",
|
|
20
|
+
"@types/node": "^24.10.0",
|
|
21
|
+
"@typescript-eslint/eslint-plugin": "^8.46.3",
|
|
22
|
+
"@typescript-eslint/parser": "^8.46.3",
|
|
23
|
+
"eslint": "^9.39.1",
|
|
24
|
+
"eslint-plugin-import": "^2.32.0",
|
|
25
|
+
"jiti": "^2.6.1",
|
|
26
|
+
"license-report": "^6.8.1",
|
|
11
27
|
"license-report-check": "^0.1.2",
|
|
12
|
-
"nanoid": "^5.1.
|
|
13
|
-
"npm-check-updates": "^
|
|
28
|
+
"nanoid": "^5.1.6",
|
|
29
|
+
"npm-check-updates": "^19.1.2",
|
|
14
30
|
"prettier": "^3.6.2",
|
|
15
31
|
"retire": "^5.3.0",
|
|
16
|
-
"run": "^1.5.0"
|
|
32
|
+
"run": "^1.5.0",
|
|
33
|
+
"type-fest": "^5.2.0",
|
|
34
|
+
"typescript": "^5.9.3",
|
|
35
|
+
"vite": "^7.2.2",
|
|
36
|
+
"vite-plugin-dts": "^4.5.4"
|
|
17
37
|
},
|
|
18
38
|
"scripts": {
|
|
19
39
|
"audit": "npm audit",
|
|
20
|
-
"build": "
|
|
21
|
-
"bumpVersion": "node -e \"import('./index.js').then(m => m.bumpVersion())\"",
|
|
40
|
+
"build": "vite build",
|
|
41
|
+
"bumpVersion": "node -e \"import('./dist/index.js').then(m => m.bumpVersion())\"",
|
|
22
42
|
"check": "npm outdated; npm-check-updates -i && retire",
|
|
23
43
|
"document": "license-report --only=prod,peer > LICENSES.json && license-report-check --source ./LICENSES.json --allowed 'MIT' --allowed 'n/a' --allowed 'Apache-2.0' --output=table",
|
|
24
|
-
"format": "prettier --write *.
|
|
25
|
-
"lint": "eslint
|
|
44
|
+
"format": "prettier --write *.ts",
|
|
45
|
+
"lint": "eslint src/",
|
|
26
46
|
"publishToNPM": "npm publish --access public",
|
|
27
47
|
"release": "npm run syncWithGitHub && npm run publishToNPM",
|
|
28
48
|
"syncWithGitHub": "npm run bumpVersion && node -e \"import('./index.js').then(m => m.syncWithGitHub())\"",
|
package/.prettierrc.json
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://json.schemastore.org/prettierrc",
|
|
3
|
-
"arrowParens": "always",
|
|
4
|
-
"bracketSameLine": false,
|
|
5
|
-
"bracketSpacing": true,
|
|
6
|
-
"cursorOffset": -1,
|
|
7
|
-
"embeddedLanguageFormatting": "auto",
|
|
8
|
-
"endOfLine": "lf",
|
|
9
|
-
"htmlWhitespaceSensitivity": "css",
|
|
10
|
-
"insertPragma": false,
|
|
11
|
-
"jsxSingleQuote": false,
|
|
12
|
-
"plugins": [],
|
|
13
|
-
"printWidth": 180,
|
|
14
|
-
"proseWrap": "preserve",
|
|
15
|
-
"quoteProps": "as-needed",
|
|
16
|
-
"semi": true,
|
|
17
|
-
"singleAttributePerLine": false,
|
|
18
|
-
"singleQuote": true,
|
|
19
|
-
"tabWidth": 4,
|
|
20
|
-
"trailingComma": "none",
|
|
21
|
-
"useTabs": false,
|
|
22
|
-
"vueIndentScriptAndStyle": false
|
|
23
|
-
}
|
package/.vscode/settings.json
DELETED
package/LICENSES.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
[]
|
package/eslint.config.js
DELETED
package/index.js
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
// Dependencies
|
|
2
|
-
const fs = require('fs').promises;
|
|
3
|
-
const { nanoid } = require('nanoid');
|
|
4
|
-
|
|
5
|
-
// Dependencies - Promisify exec.
|
|
6
|
-
const util = require('util');
|
|
7
|
-
const exec = util.promisify(require('child_process').exec);
|
|
8
|
-
|
|
9
|
-
// Operations - Build configuration.
|
|
10
|
-
async function buildConfig(directoryPath) {
|
|
11
|
-
const configJSON = await readJSONFile(`${directoryPath || ''}config.json`);
|
|
12
|
-
const packageJSON = await readJSONFile('package.json');
|
|
13
|
-
await fs.writeFile(`${directoryPath || ''}config.json`, JSON.stringify({ ...configJSON, id: packageJSON.name, version: packageJSON.version }, undefined, 4));
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Operations - Document interface.
|
|
17
|
-
async function documentInterface(moduleTypeId) {
|
|
18
|
-
const configJSON = await readJSONFile('config.json');
|
|
19
|
-
const indexCode = await fs.readFile('src/index.ts', 'utf8');
|
|
20
|
-
const regex = /^\s{4}(?:async\s+)?(private\s+)?(?:public\s+|protected\s+)?([A-Za-z_]\w*)\s*\(/gm;
|
|
21
|
-
const matches = [...indexCode.matchAll(regex)]
|
|
22
|
-
.filter((m) => !m[1] && m[2] !== 'constructor') // m[1] is 'private ' if present
|
|
23
|
-
.map((m) => m[2]);
|
|
24
|
-
configJSON.interface = matches;
|
|
25
|
-
await fs.writeFile('config.json', JSON.stringify(configJSON, undefined, 4));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Operations - Build public directory index.
|
|
29
|
-
async function buildPublicDirectoryIndex(id) {
|
|
30
|
-
const index = {};
|
|
31
|
-
|
|
32
|
-
async function listDirectoryEntriesRecursively(directoryPath, names) {
|
|
33
|
-
const entries = [];
|
|
34
|
-
const localDirectoryPath = directoryPath.substring(`public/${id}`.length);
|
|
35
|
-
index[localDirectoryPath] = entries;
|
|
36
|
-
for (const name of names) {
|
|
37
|
-
const itemPath = `${directoryPath}/${name}`;
|
|
38
|
-
try {
|
|
39
|
-
const stats = await fs.stat(itemPath);
|
|
40
|
-
if (stats.isDirectory()) {
|
|
41
|
-
const nextLevelChildren = await fs.readdir(itemPath);
|
|
42
|
-
entries.push({ childCount: nextLevelChildren.length, name: `${name}`, typeId: 'folder' });
|
|
43
|
-
await listDirectoryEntriesRecursively(itemPath, nextLevelChildren);
|
|
44
|
-
} else {
|
|
45
|
-
entries.push({ id: nanoid(), lastModifiedAt: stats.mtimeMs, name, size: stats.size, typeId: 'object' });
|
|
46
|
-
}
|
|
47
|
-
} catch (error) {
|
|
48
|
-
console.error(`Unable to get information for '${name}' in 'buildPublicDirectoryIndex'.`, error);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
// TODO: Prior version: entries.sort((left, right) => right.typeId.localeCompare(left.typeId) || left.name.localeCompare(right.name));
|
|
52
|
-
entries.sort((left, right) => {
|
|
53
|
-
const typeComparison = left.typeId.localeCompare(right.typeId);
|
|
54
|
-
return typeComparison !== 0 ? typeComparison : left.name.localeCompare(right.name);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const toplevelNames = await fs.readdir(`public/${id}`);
|
|
59
|
-
await listDirectoryEntriesRecursively(`public/${id}`, toplevelNames);
|
|
60
|
-
await fs.writeFile(`./public/${id}Index.json`, JSON.stringify(index), (error) => {
|
|
61
|
-
if (error) return console.error(error);
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Operations - Bump version.
|
|
66
|
-
async function bumpVersion() {
|
|
67
|
-
const packageJSON = await readJSONFile('package.json');
|
|
68
|
-
const versionSegments = packageJSON.version.split('.');
|
|
69
|
-
packageJSON.version = `${versionSegments[0]}.${versionSegments[1]}.${Number(versionSegments[2]) + 1}`;
|
|
70
|
-
await fs.writeFile('package.json', JSON.stringify(packageJSON, undefined, 4));
|
|
71
|
-
console.log(`Bumped to version ${packageJSON.version}.`);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Operations - Clear directory.
|
|
75
|
-
async function clearDirectory(directoryPath) {
|
|
76
|
-
for (const itemName of await fs.readdir(directoryPath)) {
|
|
77
|
-
const itemPath = `${directoryPath}/${itemName}`;
|
|
78
|
-
try {
|
|
79
|
-
const stats = await fs.stat(itemPath);
|
|
80
|
-
if (stats.isDirectory()) {
|
|
81
|
-
await fs.rm(itemPath, { recursive: true, force: true });
|
|
82
|
-
} else {
|
|
83
|
-
await fs.unlink(itemPath);
|
|
84
|
-
}
|
|
85
|
-
} catch (error) {
|
|
86
|
-
console.error(`Unable to get information for '${itemPath}' in 'clearDirectory'.`, error);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Operations - Send deployment notice.
|
|
92
|
-
async function sendDeploymentNotice() {
|
|
93
|
-
const configJSON = await readJSONFile('config.json');
|
|
94
|
-
const options = {
|
|
95
|
-
body: JSON.stringify(configJSON),
|
|
96
|
-
headers: { 'Content-Type': 'application/json' },
|
|
97
|
-
method: 'PUT'
|
|
98
|
-
};
|
|
99
|
-
const response = await fetch(`https://api.datapos.app/states/${configJSON.id}`, options);
|
|
100
|
-
if (!response.ok) console.log(await response.text());
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// UtilitiesOperations - Sync with GitHub.
|
|
104
|
-
async function syncWithGitHub() {
|
|
105
|
-
const packageJSON = await readJSONFile('package.json');
|
|
106
|
-
await exec('git add .');
|
|
107
|
-
await exec(`git commit -m v${packageJSON.version}`);
|
|
108
|
-
await exec('git push origin main:main');
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// Operations - Upload directory to Cloudflare R2.
|
|
112
|
-
async function uploadDirectoryToR2(sourceDirectory, uploadDirectory) {
|
|
113
|
-
async function listDirectoryEntriesRecursively(currentSourceDirectory, currentDestinationDirectory, names) {
|
|
114
|
-
for (const name of names) {
|
|
115
|
-
const sourceItemPath = `${currentSourceDirectory}/${name}`;
|
|
116
|
-
const destinationItemPath = `${currentDestinationDirectory}/${name}`;
|
|
117
|
-
try {
|
|
118
|
-
const stats = await fs.stat(sourceItemPath);
|
|
119
|
-
if (stats.isDirectory()) {
|
|
120
|
-
const nextLevelChildren = await fs.readdir(sourceItemPath);
|
|
121
|
-
await listDirectoryEntriesRecursively(sourceItemPath, destinationItemPath, nextLevelChildren);
|
|
122
|
-
} else {
|
|
123
|
-
const command = `wrangler r2 object put "datapos-sample-data-eu/${currentDestinationDirectory}/${name}" --file="${currentSourceDirectory}/${name}" --jurisdiction=eu --remote`;
|
|
124
|
-
const response = await exec(command);
|
|
125
|
-
console.log('Uploading:', `${currentSourceDirectory}/${name}`);
|
|
126
|
-
if (response.stderr) {
|
|
127
|
-
console.log('Command___:', command);
|
|
128
|
-
console.log('Error_____:', response.stderr);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
} catch (error) {
|
|
132
|
-
console.error(`Unable to get information for '${name}' in 'uploadDirectoryToR2'.`, error);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
const toplevelNames = await fs.readdir(`${sourceDirectory}/${uploadDirectory}/`);
|
|
137
|
-
await listDirectoryEntriesRecursively(`${sourceDirectory}/${uploadDirectory}`, uploadDirectory, toplevelNames);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// Operations - Upload module configuration.
|
|
141
|
-
async function uploadModuleConfig() {
|
|
142
|
-
const configJSON = await readJSONFile('config.json');
|
|
143
|
-
const stateId = configJSON.id;
|
|
144
|
-
const options = {
|
|
145
|
-
body: JSON.stringify(configJSON),
|
|
146
|
-
headers: { 'Content-Type': 'application/json' },
|
|
147
|
-
method: 'PUT'
|
|
148
|
-
};
|
|
149
|
-
const response = await fetch(`https://api.datapos.app/states/${stateId}`, options);
|
|
150
|
-
if (!response.ok) console.log(await response.text());
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Operations - Upload module to Cloudflare R2.
|
|
154
|
-
async function uploadModuleToR2(fromPath, toPath) {
|
|
155
|
-
const packageJSON = await readJSONFile('package.json');
|
|
156
|
-
const toPathWithVersion = toPath.replace(/^(.*?\.)/, `$1v${packageJSON.version}.`);
|
|
157
|
-
await exec(`wrangler r2 object put ${toPathWithVersion} --file=dist/${fromPath} --content-type application/javascript --jurisdiction=eu --remote`, { stdio: 'inherit' });
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Utilities - Read JSON file.
|
|
161
|
-
async function readJSONFile(path) {
|
|
162
|
-
try {
|
|
163
|
-
return JSON.parse(await fs.readFile(path, 'utf8'));
|
|
164
|
-
} catch (error) {
|
|
165
|
-
console.warn(`WARN: JSON file '${path}' not found or invalid.`, error);
|
|
166
|
-
return {};
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// Exposures
|
|
171
|
-
export {
|
|
172
|
-
buildConfig,
|
|
173
|
-
buildPublicDirectoryIndex,
|
|
174
|
-
bumpVersion,
|
|
175
|
-
clearDirectory,
|
|
176
|
-
documentInterface,
|
|
177
|
-
sendDeploymentNotice,
|
|
178
|
-
syncWithGitHub,
|
|
179
|
-
uploadDirectoryToR2,
|
|
180
|
-
uploadModuleConfig,
|
|
181
|
-
uploadModuleToR2
|
|
182
|
-
};
|