@cocreate/cli 1.46.1 → 1.47.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 CHANGED
@@ -1,3 +1,19 @@
1
+ ## [1.47.1](https://github.com/CoCreate-app/CoCreate-cli/compare/v1.47.0...v1.47.1) (2024-01-11)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * TODO handle getting closest config ([e7aae1b](https://github.com/CoCreate-app/CoCreate-cli/commit/e7aae1bfe33952b6c5f27db1f3679ad2a65438cd))
7
+ * added TODO use crud to clone storage, database, array, index, object to a new or existing storage, database, array, index, object ([c157b0b](https://github.com/CoCreate-app/CoCreate-cli/commit/c157b0bdb5690801c0f8d5d7e5aaadaa97c868c4))
8
+
9
+ # [1.47.0](https://github.com/CoCreate-app/CoCreate-cli/compare/v1.46.1...v1.47.0) (2024-01-08)
10
+
11
+
12
+ ### Features
13
+
14
+ * bumped CoCreate dependencies to their latest versions ([ae609a8](https://github.com/CoCreate-app/CoCreate-cli/commit/ae609a859ef5620acfa998292feea25d37262534))
15
+ * nfs.js to mount disk ([69efc0a](https://github.com/CoCreate-app/CoCreate-cli/commit/69efc0a97cb1d0c5ec670c02295e8975cec4bd22))
16
+
1
17
  ## [1.46.1](https://github.com/CoCreate-app/CoCreate-cli/compare/v1.46.0...v1.46.1) (2024-01-03)
2
18
 
3
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/cli",
3
- "version": "1.46.1",
3
+ "version": "1.47.1",
4
4
  "description": "Polyrepo management bash CLI tool. Run all git commands and yarn commands on multiple repositories. Also includes a few custom macros for cloning, installing, etc.",
5
5
  "keywords": [
6
6
  "cli",
@@ -55,10 +55,10 @@
55
55
  "coc": "src/coc.js"
56
56
  },
57
57
  "dependencies": {
58
- "@cocreate/acme": "^1.0.0",
59
- "@cocreate/config": "^1.8.0",
58
+ "@cocreate/acme": "^1.1.3",
59
+ "@cocreate/config": "^1.10.0",
60
60
  "@cocreate/file": "^1.13.0",
61
- "@cocreate/nginx": "^1.0.0",
61
+ "@cocreate/nginx": "^1.2.0",
62
62
  "glob": "^7.1.7",
63
63
  "prettier": "^2.3.2"
64
64
  }
package/src/coc.js CHANGED
@@ -37,6 +37,38 @@ function getRepositories(path) {
37
37
  }
38
38
  }
39
39
 
40
+ // TODO: handle getting closest config
41
+ async function getConfig(directory, filename = '') {
42
+ const filePath = path.resolve(directory, filename);
43
+ if (!filePath.includes('node_modules')) {
44
+ const configPath = findClosestConfig(filePath)
45
+ if (configPath) {
46
+ return { config: require(configPath), configPath, filePath };
47
+
48
+ } else {
49
+ console.log('No CoCreate.config file found in parent directories.');
50
+ }
51
+ }
52
+
53
+ }
54
+
55
+ function findClosestConfig(filePath) {
56
+ let currentDir = filePath;
57
+
58
+ while (currentDir !== '/' && currentDir !== '.') {
59
+ let configFile = path.join(currentDir, 'CoCreate.config.js');
60
+
61
+ if (fs.existsSync(configFile)) {
62
+ return configFile;
63
+ }
64
+
65
+ currentDir = path.dirname(currentDir);
66
+ }
67
+
68
+ return null;
69
+ }
70
+
71
+
40
72
  const currentRepoPath = path.resolve(process.cwd(), "CoCreate.config.js");
41
73
  let packageJsonPath = path.resolve(process.cwd(), 'package.json');
42
74
  let directory
@@ -0,0 +1,120 @@
1
+ const file = require('@cocreate/file')
2
+ const path = require('path');
3
+ const fs = require('fs');
4
+
5
+ module.exports = async function branch(directory, args) {
6
+ return
7
+ // TODO: use crud to clone storage, database, array, index, object to a new or existing storage, database, array, index, object
8
+ const { MongoClient } = require("mongodb");
9
+
10
+ const fromDB = 'dbUrl';
11
+ const fromDBName = '652c8d62679eca03e0b116a7'
12
+
13
+ const toDB = 'dbUrl';
14
+ const toDBName = 'dev'
15
+
16
+ const array = ["organizations", "users", "keys"];
17
+ // const exclude = ["organizations", "users", "keys", "files", "crdt", "metrics", "industries", "industry_objects"];
18
+
19
+
20
+ async function migrateDb() {
21
+ try {
22
+ const newDb = await MongoClient.connect(toDB, { useNewUrlParser: true, useUnifiedTopology: true });
23
+ const newDatabase = newDb.db(toDBName);
24
+
25
+ const previousDb = await MongoClient.connect(fromDB, { useNewUrlParser: true, useUnifiedTopology: true });
26
+ const previousDatabase = previousDb.db(fromDBName);
27
+
28
+ previousDatabase.listCollections().toArray(function (error, results) {
29
+ if (!error && results && results.length > 0) {
30
+ for (let result of results) {
31
+ // if (array.includes(result.name))
32
+ migrate(previousDatabase, newDatabase, result.name)
33
+ }
34
+ }
35
+ })
36
+
37
+ } catch (err) {
38
+ console.error("An error occurred:", err);
39
+ }
40
+ }
41
+
42
+ function migrate(previousDatabase, newDatabase, arrayName) {
43
+ try {
44
+ const previousArray = previousDatabase.collection(arrayName);
45
+ const newArray = newDatabase.collection(arrayName); // Moved outside of the forEach
46
+ const cursor = previousArray.find();
47
+
48
+ let batch = [];
49
+ let batchSize = 0; // Keep track of the batch size in memory
50
+ const maxBatchSize = 16000000; // Adjust based on MongoDB's BSON Document Size limit (16MB)
51
+ const maxCount = 1000; // Maximum count of documents
52
+
53
+ cursor.forEach(
54
+ function (doc) {
55
+ if (doc) {
56
+ let docSize = JSON.stringify(doc).length; // Approximation of document size
57
+ if (batchSize + docSize < maxBatchSize && batch.length < maxCount) {
58
+ batch.push(doc);
59
+ batchSize += docSize;
60
+ } else {
61
+ // Batch is full, insert it
62
+ newArray.insertMany(batch);
63
+ batch = [doc]; // Start a new batch with the current document
64
+ batchSize = docSize; // Reset batch size to current document's size
65
+ }
66
+ }
67
+ },
68
+ function (err) {
69
+ if (err) {
70
+ console.log('Cursor processing error:', err);
71
+ } else {
72
+ // Insert any remaining documents in the batch
73
+ if (batch.length > 0) {
74
+ newArray.insertMany(batch);
75
+ }
76
+ console.log('Migration completed successfully');
77
+ }
78
+ }
79
+ );
80
+
81
+ } catch (error) {
82
+ console.log('Migration error', error);
83
+ }
84
+ }
85
+
86
+ migrateDb();
87
+
88
+ if (args && !Array.isArray(args))
89
+ args = [args]
90
+
91
+ if (!args.length) {
92
+ directory = process.cwd()
93
+ const { config, configPath, filePath } = await getConfig(directory);
94
+ if (config) {
95
+ await file(config, configPath, filePath)
96
+ } else {
97
+ console.log('Failed to read or parse CoCreate.config.js.');
98
+ }
99
+
100
+ } else {
101
+ for (let arg of args) {
102
+ let CoCreateConfig
103
+
104
+ try {
105
+ CoCreateConfig = JSON.parse(arg)
106
+ } catch (error) { }
107
+
108
+
109
+ if (!CoCreateConfig) {
110
+ const { config, configPath, filePath } = await getConfig(arg);
111
+ if (config) {
112
+ await file(config, configPath, filePath)
113
+ } else {
114
+ console.log('Failed to read or parse CoCreate.config.js.');
115
+ }
116
+ }
117
+ }
118
+ }
119
+
120
+ }
@@ -0,0 +1,40 @@
1
+ const { exec } = require("child_process");
2
+
3
+ // Define the commands
4
+ const commands = [
5
+ "sudo apt-get update",
6
+ "sudo apt-get install -y nfs-common",
7
+ `sudo mkdir /mnt/efs`,
8
+ // Replace fs-12345678 with your actual file system ID and us-west-2 with your EFS region
9
+ "sudo mount -t nfs4 -o nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2 fs-060287caeafac2302.efs.us-east-1.amazonaws.com:/ /mnt/efs"
10
+ ];
11
+
12
+ // Function to execute each command
13
+ const executeCommand = (command) => {
14
+ return new Promise((resolve, reject) => {
15
+ exec(command, (error, stdout, stderr) => {
16
+ if (error) {
17
+ console.warn(error);
18
+ reject();
19
+ }
20
+ console.log(stdout);
21
+ resolve();
22
+ });
23
+ });
24
+ };
25
+
26
+ // Execute all commands in sequence
27
+ const runCommands = async () => {
28
+ for (const command of commands) {
29
+ console.log(`Running: ${command}`);
30
+ try {
31
+ await executeCommand(command);
32
+ } catch (error) {
33
+ console.error(`Error executing ${command}`);
34
+ break; // Exit if any command fails
35
+ }
36
+ }
37
+ console.log("All commands executed successfully.");
38
+ };
39
+
40
+ runCommands();