Skip to content

Commit

Permalink
feat(cli): run init after install
Browse files Browse the repository at this point in the history
  • Loading branch information
mkucharz committed Nov 27, 2018
1 parent 844c580 commit 6221636
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 23 deletions.
23 changes: 12 additions & 11 deletions packages/cli/package.json
@@ -1,7 +1,7 @@
{
"name": "@syncano/cli",
"version": "0.14.0",
"description": "CLI for Syncano",
"description": "Command Line Interface for Syncano",
"author": "Maciej Kucharz",
"license": "MIT",
"keywords": [
Expand All @@ -20,7 +20,7 @@
"node": ">= 8.9.0"
},
"main": "./lib/cli.js",
"homepage": "http://syncano.com",
"homepage": "http://syncano.io",
"repository": {
"type": "git",
"url": "https://github.com/Syncano/syncano-node.git"
Expand Down Expand Up @@ -54,7 +54,7 @@
"cli-table3": "^0.5.1",
"commander": "^2.19.0",
"create-error": "^0.3.1",
"debug": "^3.1.0",
"debug": "^4.1.0",
"es6-template-strings": "^2.0.1",
"find-key": "^2.1.3",
"form-data": "^2.3.3",
Expand All @@ -70,18 +70,18 @@
"node-walkup": "^1.1.1",
"ora": "^1.3.0",
"pretty-bytes": "^4.0.2",
"raven": "^2.2.1",
"readdirp": "^2.1.0",
"raven": "^2.6.4",
"readdirp": "^2.2.1",
"semver": "^5.6.0",
"source-map": "^0.7.0",
"source-map": "^0.7.3",
"stack-trace": "0.0.10",
"strip-ansi": "^4.0.0",
"unzip2": "^0.2.5",
"validator": "^9.1.2",
"walkdir": "0.0.12",
"watchr": "^4.0.1",
"ws": "^4.0.0",
"yauzl": "^2.9.2"
"yauzl": "^2.10.0"
},
"devDependencies": {
"@syncano/test-tools": "0.14.0",
Expand All @@ -98,14 +98,14 @@
"babel-plugin-transform-export-extensions": "^6.22.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-plugin-transform-regenerator": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-env": "^1.7.0",
"babel-register": "^6.26.0",
"chai": "^4.1.2",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"console.mute": "^0.3.0",
"dirty-chai": "^2.0.1",
"mocha": "^5.0.0",
"mock-fs": "^4.4.2",
"mocha": "^5.2.0",
"mock-fs": "^4.7.0",
"npm-cli-login": "^0.0.10",
"prettier": "^1.15.2",
"replace": "^1.0.0",
Expand All @@ -116,6 +116,7 @@
},
"scripts": {
"prepublish": "npm run build",
"postinstall": "cd $INIT_CWD && npx s init",
"build": "npx babel src -d lib/ --copy-files --ignore *.test.js,*.test-e2e.js --source-maps",
"build:watch": "npm run build -- -w",
"clean": "rm -rf lib/",
Expand Down
13 changes: 9 additions & 4 deletions packages/cli/src/commands/init.js
Expand Up @@ -4,6 +4,7 @@ import inquirer from 'inquirer'
import logger from '../utils/debug'
import { createInstance } from './helpers/create-instance'
import { p, echo } from '../utils/print-tools'
import { track } from '../utils/analytics'
import Login from './login'

const { debug } = logger('cmd-init')
Expand All @@ -17,17 +18,21 @@ class InitCmd {
}

async run ([cmd]) {
if (!this.session.settings.account.authenticated()) {
const { project, settings } = this.session
const { instance } = cmd

if (process.env.INIT_CWD) {
track('CLI: install')
}

if (!settings.account.authenticated()) {
echo()
echo(4)(format.red('You have to be logged in to initialize a new project!'))
await new Login(this.context).run([])
}

this.init = new this.Init()

const { project } = this.session
const { instance } = cmd

const questions = [
{
name: 'Template',
Expand Down
5 changes: 1 addition & 4 deletions packages/cli/src/utils/analytics.js
Expand Up @@ -13,10 +13,7 @@ const STG_KEY = 'CCupheBjgV6WI0emy3oRUnDyjQ8ngmgB'
const PROD_KEY = 'fLDtpYXRjFYnHlp1gvzl4I3Gv8gDoQ8m'

const ANALYTICS_WRITE_KEY = process.env.SYNCANO_ENV === 'test' ? STG_KEY : PROD_KEY
const analytics = new Analytics(ANALYTICS_WRITE_KEY, {
flushAt: 5,
flushAfter: 300
})
const analytics = new Analytics(ANALYTICS_WRITE_KEY, {flushAt: 1})

const identify = (details) => {
debug('identify')
Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/utils/debug.js
Expand Up @@ -5,6 +5,7 @@
import Raven from 'raven'
import printDebug from 'debug'


const logTypes = ['debug', 'info', 'warn', 'error']

const logger = (name) => {
Expand Down
5 changes: 3 additions & 2 deletions packages/cli/src/utils/session.js
Expand Up @@ -103,6 +103,7 @@ export class Session {
}

try {
debug('get user details')
const details = await this.connection.account.get(this.settings.account.getAuthKey())
this.userId = details.id
this.userEmail = details.email
Expand Down Expand Up @@ -239,8 +240,8 @@ export class Session {
notAlreadyInitialized () {
if (this.projectPath && this.project) {
echo()
echo(4)('You are fine! Project in this folder is already initiated!')
echo(4)(`It is using ${format.cyan(this.project.instance)} Syncano instance.`)
echo(4)('Project in this folder is already initiated!')
echo(4)(`It is attached to ${format.cyan(this.project.instance)} Syncano instance.`)
echo()
process.exit()
}
Expand Down
2 changes: 1 addition & 1 deletion packages/lib-js-client/package.json
Expand Up @@ -35,7 +35,7 @@
"cross-env": "^5.2.0",
"isparta": "^4.1.0",
"jest": "^23.6.0",
"jsdom": "^12.2.0",
"jsdom": "^13.0.0",
"should": "^13.2.3",
"ts-jest": "^23.10.5",
"tslint": "^5.11.0",
Expand Down
1 change: 0 additions & 1 deletion packages/tests/package.json
Expand Up @@ -40,7 +40,6 @@
"concurrently": "^4.1.0",
"console.mute": "^0.3.0",
"dirty-chai": "^2.0.1",
"husky": "^0.14.3",
"mocha": "^5.0.0",
"mock-fs": "^4.4.2",
"npm-cli-login": "^0.0.10",
Expand Down

0 comments on commit 6221636

Please sign in to comment.