Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@
"prepush": "npm run lint && npm run test:unit",
"prepublish": "npm run build",
"build": "npx babel src -d lib/ --copy-files --ignore *.test.js,*.test-e2e.js --source-maps",
"build:watch": "npm run build -w",
"build:watch": "npm run build -- -w",
"clean": "rm -rf lib/",
"unit": "mocha 'tests/unit/*.test.js' --require babel-register",
"unit:watch": "npm run unit -w",
"unit:watch": "npm run unit -- -w",
"test": "npm-run-all --parallel test:unit test:e2e:group:*",
"test:e2e:init": "npm run test:e2e-single tests/e2e/init.test-e2e.js",
"test:e2e:anonymous": "npm run test:e2e-single tests/e2e/anonymous.test-e2e.js",
Expand Down
6 changes: 5 additions & 1 deletion packages/cli/src/commands/socket-submit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import format from 'chalk'
import { CompatibilityError } from '../utils/errors'
import { error, echo, echon } from '../utils/print-tools'

export default class SocketSubmitCmd {
Expand Down Expand Up @@ -44,7 +45,10 @@ export default class SocketSubmitCmd {
echo(`Type ${publishCommand} to make it available for everyone!`)
echo()
} catch (err) {
if (err.response && err.response.data) {
if (err instanceof CompatibilityError) {
error(4)(err.message)
echo()
} else if (err.response && err.response.data) {
error(4)(err.response.data.message)
echo()
} else {
Expand Down
8 changes: 8 additions & 0 deletions packages/cli/src/utils/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ class CompileError {
}
}

class CompatibilityError {
constructor (socketVersion, envVersion) {
this.message = `Socket major version (${socketVersion}) is not\
comaptible with this Syncano environment major version (${envVersion}).`
}
}

export {
CompatibilityError,
CompileError
}
3 changes: 3 additions & 0 deletions packages/cli/src/utils/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import walkUp from 'node-walkup'
import Promise from 'bluebird'

import logger from './debug'
import pjson from '../../package.json'
import getSettings from '../settings'
import genUniqueName from './unique-instance'
import Socket from './sockets'
Expand All @@ -26,6 +27,8 @@ export class Session {
this.userId = null
this.walkup = Promise.promisify(walkUp)

this.majorVersion = pjson.version.split('.')[0]

this.HOST = process.env.SYNCANO_HOST || 'api.syncano.io'
this.ENDPOINT_HOST = this.HOST === 'api.syncano.io' ? 'syncano.space' : 'syncano.link'
}
Expand Down
11 changes: 10 additions & 1 deletion packages/cli/src/utils/sockets/sockets.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Hosting from '../hosting'
import Registry from '../registry'
import { p, echo } from '../print-tools'
import { getTemplate } from '../templates'
import { CompileError } from '../errors'
import { CompileError, CompatibilityError } from '../errors'

const { debug } = logger('utils-sockets')

Expand Down Expand Up @@ -1284,6 +1284,7 @@ class Socket {

submit () {
debug('submit')
this.isCompatible()
const registry = new Registry()
return registry.submitSocket(this)
}
Expand Down Expand Up @@ -1369,6 +1370,14 @@ class Socket {
return checksums
}

isCompatible () {
const socketMajorVersion = this.spec.version.split('.')[0]
if (socketMajorVersion !== session.majorVersion) {
throw new CompatibilityError(socketMajorVersion, session.majorVersion)
}
return true
}

shouldBeUpdated () {
debug('shouldBeUpdated')
if (this.existLocally && this.existRemotely) {
Expand Down
23 changes: 20 additions & 3 deletions packages/cli/tests/e2e/registry.test-e2e.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* global describe it before after */
import replace from 'replace'
import path from 'path'
import {
nixt,
Expand Down Expand Up @@ -41,7 +42,7 @@ describe('[E2E] CLI Registry', function () {
.end(done)
})

it('can submit created socket to registry', function (done) {
it('can submit created socket to the registry', function (done) {
testNixt()
.run(`${cliLocation} submit ${createdSocketName}`)
.stdout(/to make it available for everyone/)
Expand All @@ -50,8 +51,24 @@ describe('[E2E] CLI Registry', function () {

it('can bump version of submited socket', function (done) {
testNixt()
.run(`${cliLocation} submit ${createdSocketName} -b major`)
.stdout(/\(1\.0\.0\)\.\.\. Done/)
.run(`${cliLocation} submit ${createdSocketName} -b minor`)
.stdout(/\(0\.1\.0\)\.\.\. Done/)
.end(done)
})

it('can submit socket with wrong version to the registry', function (done) {
testNixt()
.before(() => {
replace({
regex: 'version: 0.1.0',
replacement: 'version: 25.0.1',
paths: [path.join(testsLocation, testInstance, 'syncano', createdSocketName)],
recursive: true,
silent: true
})
})
.run(`${cliLocation} submit ${createdSocketName}`)
.stdout(/is not comaptible with this Syncano environment/)
.end(done)
})

Expand Down
5 changes: 4 additions & 1 deletion packages/lib-js-core/src/query-builder.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logger from 'debug'
import pjson from '../package.json'
import nodeFetch from 'node-fetch'
import {checkStatus, parseJSON} from './utils'

Expand All @@ -20,8 +21,10 @@ export default class QueryBuilder {
_getSyncanoRegistryURL () {
const {host} = this.instance
const endpointHost = host === 'api.syncano.io' ? 'syncano.space' : 'syncano.link'
const registryInstance = process.env.SYNCANO_SOCKET_REGISTRY_INSTANCE || 'socket-registry'
const majorVersion = pjson.version.split('.')[0]
const registryInstance = process.env.SYNCANO_SOCKET_REGISTRY_INSTANCE || `registry-${majorVersion}`
this.registryHost = `${registryInstance}.${endpointHost}`
debug('registryHost', this.registryHost)
return `https://${this.registryHost}`
}

Expand Down
4 changes: 4 additions & 0 deletions packages/lib-js-core/src/server.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import pjson from '../package.json'
import Data from './data'
import Users from './users'
import Account from './account'
Expand All @@ -20,6 +21,9 @@ class Server {
const getConfig = className => Object.assign({className}, settings)
const config = getConfig()

this.version = pjson.version
this.majorVersion = pjson.version.split('.')[0]

this._class = new Class(config)
this.event = new Event(config)
this.endpoint = new Endpoint(config)
Expand Down
1 change: 1 addition & 0 deletions packages/lib-js-core/test/e2e/event.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* global it describe before after */
import {expect} from 'chai'
import Server from '../../src'
import {getRandomString, createTestInstance, deleteTestInstance} from '../utils'
Expand Down
11 changes: 11 additions & 0 deletions packages/lib-js-core/test/e2e/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* global it describe */
import {expect} from 'chai'
import pjson from '../../package.json'
import Server from '../../src'

describe('Server', function () {
it('get major version', async () => {
const majorVersion = new Server().majorVersion
expect(majorVersion).to.be.equal(pjson.version.split('.')[0])
})
})