@datapos/datapos-development 0.2.28

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.
@@ -0,0 +1,23 @@
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/LICENSE.md ADDED
@@ -0,0 +1,7 @@
1
+ ISC License (ISC)
2
+
3
+ Copyright 2013 Jonathan Terrell
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/LICENSES.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "dotenv@16.4.5": {
3
+ "licenses": "BSD-2-Clause",
4
+ "repository": "https://github.com/motdotla/dotenv",
5
+ "licenseFile": "node_modules/dotenv/LICENSE",
6
+ "licenseUrl": "https://github.com/motdotla/dotenv/raw/master/LICENSE",
7
+ "parents": "@datapos/datapos-dev-operations"
8
+ },
9
+ "run@1.5.0": {
10
+ "licenses": "UNKNOWN",
11
+ "repository": "https://github.com/DTrejo/run.js",
12
+ "licenseFile": "node_modules/run/LICENSE",
13
+ "licenseUrl": "https://github.com/DTrejo/run.js/raw/master/LICENSE",
14
+ "parents": "@datapos/datapos-dev-operations"
15
+ }
16
+ }
package/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # DataPos - Development Operations Library
2
+
3
+ A Javascript library of functions used to manage Data Positioning repositories.
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ npm install --save-dev @datapos-development
9
+ ```
10
+
11
+ ## Production Dependencies
12
+
13
+ The following packages are included in the production release. Please refer to 'package.json' and 'LICENSES.json' for version and license details.
14
+
15
+ | Name | References |
16
+ | ------ | ---------------------------------------------------------------------------------------- |
17
+ | dotenv | [GitHub](https://github.com/motdotla/dotenv) [NPM](https://www.npmjs.com/package/dotenv) |
18
+
19
+ ## Helpers
20
+
21
+ The 'scriptHelpers.js' file exports the following helper functions.
22
+
23
+ | Name | Notes |
24
+ | ------------------------- | ----- |
25
+ | buildConfig | |
26
+ | buildPublicDirectoryIndex | |
27
+ | bumpVersion | |
28
+ | clearDirectory | |
29
+ | compilePresenter | |
30
+ | syncWithGitHub | |
31
+ | uploadPlugin | |
32
+
33
+ ## Repository Management Commands
34
+
35
+ The following list details the repository management commands implementation by this project. For more details, please refer to the scripts section of the 'package.json' file in this project.
36
+
37
+ | Name | Key Code | Notes |
38
+ | ------------------ | ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
39
+ | audit | alt+ctrl+shift+a | Use [npm audit](https://docs.npmjs.com/cli/v8/commands/npm-audit) to audit the project's dependencies for known security vulnerabilities. |
40
+ | build | alt+ctrl+shift+b | NOT implemented. The JavaScript is compatible with the latest ECMA version. |
41
+ | bumpVersion | | |
42
+ | check | alt+ctrl+shift+c | Use [npx npm-check-updates](https://github.com/raineorshine/npm-check-updates) and [npm outdated](https://docs.npmjs.com/cli/v8/commands/npm-audit) to list the dependencies in the project that are outdated. They return different results. |
43
+ | document | alt+ctrl+shift+d | Use [npm-license-crawler](https://www.npmjs.com/package/npm-license-crawler) to identify the licenses of the project's direct production dependencies. |
44
+ | format | alt+ctrl+shift+f | Use [prettier](https://prettier.io/) to format the code. |
45
+ | lint | alt+ctrl+shift+l | Use [eslint](https://eslint.org/) to check the code for potential errors and enforces coding styles. |
46
+ | publishToNPM | alt+ctrl+shift+n | Use [npm publish](https://docs.npmjs.com/cli/v8/commands/npm-publish) to publish the package to the [npm](https://www.npmjs.com/) registry. This action will publish the last synchronised version. Use the command line command 'npm publish' when publishing for the first time. |
47
+ | release | alt+ctrl+shift+r | Synchronise the local repository with the main GitHub repository and publish the package to the [npm](https://www.npmjs.com/) registry. |
48
+ | syncWithGitHub | alt+ctrl+shift+s | Synchronise the local repository with the main GitHub repository. |
49
+ | test | alt+ctrl+shift+l | NOT implemented. |
50
+ | updateDependencies | alt+ctrl+shift+l | NOT implemented. |
51
+
52
+ ## The 'cors.json' File
53
+
54
+ Set CORS Policy on Firebase Storage Bucket (No-longer publishing to Firebase Storage)
55
+
56
+ See: https://firebase.google.com/docs/storage/web/download-files#cors_configuration
57
+ See: https://stackoverflow.com/questions/37760695/firebase-storage-and-access-control-allow-origin/37765371
58
+
59
+ ```
60
+ gsutil cors set cors.json gs://datapos-prod.appspot.com
61
+ ```
62
+
63
+ To list:
64
+
65
+ ```
66
+ gsutil cors get gs://datapos-prod.appspot.com
67
+ ```
package/cors.json ADDED
@@ -0,0 +1,23 @@
1
+ [
2
+ {
3
+ "origin": [
4
+ "https://datapos.app",
5
+ "https://support.datapos.app/",
6
+ "https://workbench.datapos.app/",
7
+ "https://www.datapos.app/",
8
+ "https://datapos-prod-firebaseapp.com",
9
+ "https://datapos-prod-web.app",
10
+ "https://datapos-prod-support.firebaseapp.com",
11
+ "https://datapos-prod-support.web.app",
12
+ "https://datapos-prod-workbench.firebaseapp.com",
13
+ "https://datapos-prod-workbench.web.app",
14
+ "http://localhost:5173",
15
+ "http://localhost:5174",
16
+ "http://localhost:5175",
17
+ "https://springbrook.static.observableusercontent.com",
18
+ "https://workbench.datapositioning.app"
19
+ ],
20
+ "method": ["GET"],
21
+ "maxAgeSeconds": 3600
22
+ }
23
+ ]
@@ -0,0 +1,15 @@
1
+ export default [
2
+ {
3
+ languageOptions: {
4
+ ecmaVersion: 'latest'
5
+ },
6
+ linterOptions: {
7
+ reportUnusedDisableDirectives: true
8
+ },
9
+ rules: {
10
+ 'no-empty': 'warn',
11
+ 'no-unused-vars': 'warn',
12
+ 'prefer-const': 'warn'
13
+ }
14
+ }
15
+ ];
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@datapos/datapos-development",
3
+ "license": "ISC",
4
+ "private": false,
5
+ "type": "module",
6
+ "version": "0.2.28",
7
+ "devDependencies": {
8
+ "eslint": "^9.28.0",
9
+ "nanoid": "^5.1.5",
10
+ "prettier": "^3.5.3",
11
+ "run": "^1.5.0"
12
+ },
13
+ "scripts": {
14
+ "audit": "npm audit",
15
+ "build": "echo \"***** BUILD SCRIPT NOT IMPLEMENTED. *****\"",
16
+ "bumpVersion": "node -e \"import('./scriptHelpers.js').then(m => m.bumpVersion())\"",
17
+ "check": "npx npm-check-updates && npm outdated",
18
+ "document": "npx npm-license-crawler --onlyDirectDependencies --production --relativeLicensePath --json LICENSES.json",
19
+ "format": "prettier --write *.js",
20
+ "lint": "npx eslint *.js",
21
+ "publishToNPM": "npm publish --access public",
22
+ "release": "npm run syncWithGitHub && npm run publishToNPM",
23
+ "syncWithGitHub": "npm run bumpVersion && node -e \"import('./scriptHelpers.js').then(m => m.syncWithGitHub())\"",
24
+ "test": "echo \"***** TEST SCRIPT NOT IMPLEMENTED. *****\"",
25
+ "updateDependencies": "echo \"***** UPDATE DEPENDENCIES SCRIPT NOT IMPLEMENTED. *****\""
26
+ }
27
+ }
@@ -0,0 +1,154 @@
1
+ // Dependencies - Vendor
2
+ const fs = require('fs').promises;
3
+ const { nanoid } = require('nanoid');
4
+
5
+ // Dependencies - Vendor (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() {
11
+ const configJSON = await readJSONFile('src/config.json');
12
+ const packageJSON = await readJSONFile('package.json');
13
+ fs.writeFile('src/config.json', JSON.stringify({ ...configJSON, id: packageJSON.name, version: packageJSON.version }, undefined, 4));
14
+ }
15
+
16
+ // Operations - Build Public Directory Index
17
+ async function buildPublicDirectoryIndex(id) {
18
+ async function listDirectoryEntriesRecursively(directoryPath, names) {
19
+ const entries = [];
20
+ const localDirectoryPath = directoryPath.substring(`public/${id}`.length);
21
+ index[localDirectoryPath] = entries;
22
+ for (const name of names) {
23
+ const itemPath = `${directoryPath}/${name}`;
24
+ try {
25
+ const stats = await fs.stat(itemPath);
26
+ if (stats.isDirectory()) {
27
+ const nextLevelChildren = await fs.readdir(itemPath);
28
+ entries.push({ childCount: nextLevelChildren.length, name: `${name}`, typeId: 'folder' });
29
+ await listDirectoryEntriesRecursively(itemPath, nextLevelChildren);
30
+ } else {
31
+ entries.push({ id: nanoid(), lastModifiedAt: stats.mtimeMs, name, size: stats.size, typeId: 'object' });
32
+ }
33
+ } catch (error) {
34
+ console.error(`Unable to get information for '${name}' in 'buildPublicDirectoryIndex'.`, error);
35
+ }
36
+ }
37
+ entries.sort((left, right) => right.typeId.localeCompare(left.typeId) || left.name.localeCompare(right.name));
38
+ }
39
+
40
+ const index = {};
41
+ const toplevelNames = await fs.readdir(`public/${id}`);
42
+ await listDirectoryEntriesRecursively(`public/${id}`, toplevelNames);
43
+ fs.writeFile(`./public/${id}Index.json`, JSON.stringify(index), (error) => {
44
+ if (error) return console.error(error);
45
+ });
46
+ }
47
+
48
+ // Operations - Bump Version
49
+ async function bumpVersion() {
50
+ const packageJSON = await readJSONFile('package.json');
51
+ const versionSegments = packageJSON.version.split('.');
52
+ packageJSON.version = `${versionSegments[0]}.${versionSegments[1]}.${Number(versionSegments[2]) + 1}`;
53
+ fs.writeFile('package.json', JSON.stringify(packageJSON, undefined, 4));
54
+ console.log(`Bumped to version ${packageJSON.version}.`);
55
+ }
56
+
57
+ // Operations - Clear Directory
58
+ async function clearDirectory(directoryPath) {
59
+ for (const itemName of await fs.readdir(directoryPath)) {
60
+ const itemPath = `${directoryPath}/${itemName}`;
61
+ try {
62
+ const stats = await fs.stat(itemPath);
63
+ if (stats.isDirectory()) {
64
+ await fs.rm(itemPath, { recursive: true, force: true });
65
+ } else {
66
+ await fs.unlink(itemPath);
67
+ }
68
+ } catch (error) {
69
+ console.error(`Unable to get information for '${itemPath}' in 'clearDirectory'.`, error);
70
+ }
71
+ }
72
+ }
73
+
74
+ // Operations - Send Deployment Notice
75
+ async function sendDeploymentNotice() {
76
+ const configJSON = await readJSONFile('src/config.json');
77
+ const options = {
78
+ body: JSON.stringify(configJSON),
79
+ headers: { 'Content-Type': 'application/json' },
80
+ method: 'PUT'
81
+ };
82
+ const response = await fetch(`https://operations.datapos.app/states/${configJSON.id}`, options);
83
+ if (!response.ok) console.log(await response.text());
84
+ }
85
+
86
+ // UtilitiesOperations - Sync with Github
87
+ async function syncWithGitHub() {
88
+ const packageJSON = await readJSONFile('package.json');
89
+ await exec('git add .');
90
+ await exec(`git commit -m v${packageJSON.version}`);
91
+ await exec('git push origin main:main');
92
+ }
93
+
94
+ // Operations - Upload Directory To R2
95
+ async function uploadDirectoryToR2(sourceDirectory, uploadDirectory) {
96
+ async function listDirectoryEntriesRecursively(currentSourceDirectory, currentDestinationDirectory, names) {
97
+ for (const name of names) {
98
+ const sourceItemPath = `${currentSourceDirectory}/${name}`;
99
+ const destinationItemPath = `${currentDestinationDirectory}/${name}`;
100
+ try {
101
+ const stats = await fs.stat(sourceItemPath);
102
+ if (stats.isDirectory()) {
103
+ const nextLevelChildren = await fs.readdir(sourceItemPath);
104
+ await listDirectoryEntriesRecursively(sourceItemPath, destinationItemPath, nextLevelChildren);
105
+ } else {
106
+ const command = `wrangler r2 object put "datapos-sample-data-eu/${currentDestinationDirectory}/${name}" --file="${currentSourceDirectory}/${name}" --jurisdiction=eu --remote`;
107
+ const response = await exec(command);
108
+ console.log('Uploading:', `${currentSourceDirectory}/${name}`);
109
+ if (response.stderr) {
110
+ console.log('Command___:', command);
111
+ console.log('Error_____:', response.stderr);
112
+ }
113
+ }
114
+ } catch (error) {
115
+ console.error(`Unable to get information for '${name}' in 'uploadDirectoryToR2'.`, error);
116
+ }
117
+ }
118
+ }
119
+ const toplevelNames = await fs.readdir(`${sourceDirectory}/${uploadDirectory}/`);
120
+ await listDirectoryEntriesRecursively(`${sourceDirectory}/${uploadDirectory}`, uploadDirectory, toplevelNames);
121
+ }
122
+
123
+ // Operations - Upload Module Configuration
124
+ async function uploadModuleConfig() {
125
+ const configJSON = await readJSONFile('src/config.json');
126
+ const stateId = configJSON.id;
127
+ const options = {
128
+ body: JSON.stringify(configJSON),
129
+ headers: { 'Content-Type': 'application/json' },
130
+ method: 'PUT'
131
+ };
132
+ const response = await fetch(`https://operations.datapos.app/states/${stateId}`, options);
133
+ if (!response.ok) console.log(await response.text());
134
+ }
135
+
136
+ // Operations - Upload Module To R2
137
+ async function uploadModuleToR2(fromPath, toPath) {
138
+ const packageJSON = await readJSONFile('package.json');
139
+ const toPathWithVersion = toPath.replace(/^(.*?\.)/, `$1v${packageJSON.version}.`);
140
+ exec(`wrangler r2 object put ${toPathWithVersion} --file=dist/${fromPath} --content-type application/javascript --jurisdiction=eu --remote`, { stdio: 'inherit' });
141
+ }
142
+
143
+ // Utilities - Read JSON File
144
+ async function readJSONFile(path) {
145
+ try {
146
+ return JSON.parse(await fs.readFile(path, 'utf8'));
147
+ } catch (error) {
148
+ console.warn(`WARN: JSON file '${path}' not found or invalid.`, error);
149
+ return {};
150
+ }
151
+ }
152
+
153
+ // Exposures
154
+ export { buildConfig, buildPublicDirectoryIndex, bumpVersion, clearDirectory, sendDeploymentNotice, syncWithGitHub, uploadDirectoryToR2, uploadModuleConfig, uploadModuleToR2 };