update workspace tooling

Signed-off-by: Andrey Platov <andrey@hardcoreeng.com>
This commit is contained in:
Andrey Platov 2021-08-29 09:47:17 +02:00
parent 959c52a78e
commit 02717f4450
No known key found for this signature in database
GPG Key ID: C8787EFEB4B64AF0
5 changed files with 41 additions and 17 deletions

View File

@ -85,7 +85,6 @@ specifiers:
cross-env: ^7.0.3
css-loader: ^5.2.1
dotenv-webpack: ^7.0.2
esbuild: ^0.12.24
eslint: ^7.32.0
eslint-config-standard-with-typescript: ^20.0.0
eslint-plugin-import: '2'
@ -201,7 +200,6 @@ dependencies:
cross-env: 7.0.3
css-loader: 5.2.7_webpack@5.48.0
dotenv-webpack: 7.0.3_webpack@5.48.0
esbuild: 0.12.24
eslint: 7.32.0
eslint-config-standard-with-typescript: 20.0.0_2e482f375e273d762fe67cbd5e194b49
eslint-plugin-import: 2.23.4_eslint@7.32.0
@ -10000,7 +9998,7 @@ packages:
dev: false
file:projects/workspace.tgz_6c259fadfeb3a4b20890aefe87070b8b:
resolution: {integrity: sha512-Ircelx/9snTrdceAfj7OBTqmR1tZ/cTtPtdf3zcmTJ+EwFh0rhWQJgd80CSeny6I8wMC+UXcKUk5mGHDqcmKcw==, tarball: file:projects/workspace.tgz}
resolution: {integrity: sha512-8vO7UTqdUdxIPbiMIKXV54zDnFD63L75+7Z9mTnVO5Ln6Nb5rf+ZfYloA2pDauRKp0Rf7ItIYPhjmEpp8QE+Ow==, tarball: file:projects/workspace.tgz}
id: file:projects/workspace.tgz
name: '@rush-temp/workspace'
version: 0.0.0
@ -10013,6 +10011,7 @@ packages:
eslint-plugin-import: 2.23.4_eslint@7.32.0
eslint-plugin-node: 11.1.0_eslint@7.32.0
eslint-plugin-promise: 4.3.1
jwt-simple: 0.5.6
mongodb: 4.1.1
ts-node: 10.2.1_typescript@4.3.5
transitivePeerDependencies:

View File

@ -4,5 +4,7 @@ WORKDIR /usr/src/app
COPY bundle.js ./
ENV TRANSACTOR_URL ws://transactor/
EXPOSE 8080
CMD [ "bash" ]

View File

@ -25,6 +25,8 @@
},
"dependencies": {
"@anticrm/core": "~0.6.11",
"mongodb": "^4.1.0"
"mongodb": "^4.1.0",
"@anticrm/contrib": "~0.6.0",
"jwt-simple": "~0.5.6"
}
}

View File

@ -14,14 +14,20 @@
// limitations under the License.
//
import { createModel } from '.'
import { createWorkspace } from '.'
const url = process.env.MONGO_URL
if (url === undefined) {
const mongoUrl = process.env.MONGO_URL
if (mongoUrl === undefined) {
console.error('please provide mongodb url.')
process.exit(1)
}
const transactorUrl = process.env.TRANSACTOR_URL
if (transactorUrl === undefined) {
console.error('please provide transactor url.')
process.exit(1)
}
const db = process.argv[2]
if (db === undefined) {
console.error('Please specify the database.')
@ -29,6 +35,6 @@ if (db === undefined) {
}
console.log('creating model...')
createModel(url, db).then(rows => {
console.log(`done, ${rows} rows inserted.`)
createWorkspace(mongoUrl, db, transactorUrl).then(() => {
console.log(`done.`)
}).catch(error => { console.error(error) })

View File

@ -15,25 +15,40 @@
//
import { MongoClient, Document } from 'mongodb'
import { DOMAIN_TX } from '@anticrm/core'
import core, { DOMAIN_TX, Tx } from '@anticrm/core'
import { createContributingClient } from '@anticrm/contrib'
import { encode } from 'jwt-simple'
import * as txJson from './model.tx.json'
const txes = (txJson as any).default
console.log(txes)
const txes = (txJson as any).default as Tx[]
/**
* @public
*/
export async function createModel (url: string, dbName: string): Promise<number> {
const client = new MongoClient(url)
export async function createWorkspace (mongoUrl: string, dbName: string, clientUrl: string): Promise<void> {
const client = new MongoClient(mongoUrl)
try {
await client.connect()
const db = client.db(dbName)
console.log('dropping database...')
await db.dropDatabase()
const result = await db.collection(DOMAIN_TX).insertMany(txes as Document[])
return result.insertedCount
console.log('creating model...')
const model = txes.filter(tx => tx.objectSpace === core.space.Model)
const result = await db.collection(DOMAIN_TX).insertMany(model as Document[])
console.log(`${result.insertedCount} model transactions inserted.`)
console.log('creating data...')
const data = txes.filter(tx => tx.objectSpace !== core.space.Model)
const token = encode({ email: 'anticrm@hc.engineering', workspace: dbName }, 'secret')
const url = new URL(`/${token}`, clientUrl)
const contrib = await createContributingClient(url.href)
for (const tx of data) {
await contrib.tx(tx)
}
contrib.close()
} finally {
await client.close()
}