eip-particle-cli
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -14,3 +14,3 @@ const {OAuth2Client} = require('google-auth-library'); | ||
try { | ||
const rawdata = fs.readFileSync ( require ( 'path' ).join ( __dirname, 'googleConf.json' ) ); | ||
const rawdata = fs.readFileSync ( './googleConf.json' ); | ||
googleConf = JSON.parse ( rawdata ); | ||
@@ -52,3 +52,3 @@ } catch ( e ) { | ||
googleConf[ environment ] = { ...googleConf[ environment ], ...r.tokens }; | ||
fs.writeFileSync ( require ( 'path' ).join ( __dirname, 'googleConf.json' ), JSON.stringify ( googleConf ) ); | ||
fs.writeFileSync ( './googleConf.json', JSON.stringify ( googleConf ) ); | ||
console.log ( 'Successfully authenticated with Google and the api!' ); | ||
@@ -75,3 +75,3 @@ resolve ( oAuth2Client ); | ||
try { | ||
const rawdata = fs.readFileSync ( require ( 'path' ).join ( __dirname, 'googleConf.json' ) ); | ||
const rawdata = fs.readFileSync ( './googleConf.json' ); | ||
googleConf = JSON.parse ( rawdata ); | ||
@@ -88,3 +88,3 @@ } catch ( e ) { | ||
try { | ||
fs.writeFileSync ( require ( 'path' ).join ( __dirname, 'googleConf.json' ), JSON.stringify ( googleConf ) ); | ||
fs.writeFileSync ( './googleConf.json', JSON.stringify ( googleConf ) ); | ||
console.log ( 'The googleConf.json file has now been saved!' ) | ||
@@ -98,5 +98,5 @@ } catch ( e ) { | ||
let googleConf; | ||
try { | ||
const rawdata = fs.readFileSync ( require ( 'path' ).join ( __dirname, 'googleConf.json' ) ); | ||
const rawdata = fs.readFileSync ( './googleConf.json' ); | ||
googleConf = JSON.parse ( rawdata ); | ||
@@ -109,3 +109,3 @@ } catch ( e ) { | ||
} | ||
return googleConf[ environment ].id_token; | ||
@@ -118,3 +118,3 @@ }; | ||
try { | ||
const rawdata = fs.readFileSync ( require ( 'path' ).join ( __dirname, 'googleConf.json' ) ); | ||
const rawdata = fs.readFileSync ( './googleConf.json' ); | ||
googleConf = JSON.parse ( rawdata ); | ||
@@ -121,0 +121,0 @@ } catch ( e ) { |
{ | ||
"name": "eip-particle-cli", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "A complete CLI to manage particles and atoms and deploy to them from the console", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -26,5 +26,2 @@ const request = require ( 'request' ); | ||
request.get ( `${ config[ environment ].apiUrl }/particles/${ id }${ query }`, ( error, response, body ) => { | ||
if ( error || !response || response.statusCode !== 200 ) { | ||
reject ( `Particle not found in ${ environment } or there was a network error!` ); | ||
} | ||
resolve ( [ response.statusCode, environment, JSON.parse ( body ) ] ); | ||
@@ -38,3 +35,3 @@ } ); | ||
return new Promise ( ( resolve, reject ) => { | ||
const id_token = googleAuth.getIdToken (); | ||
const id_token = googleAuth.getIdToken ( environment ); | ||
const query = environment !== 'local' ? `?id_token=${ id_token }` : ''; | ||
@@ -59,3 +56,3 @@ | ||
const updateData = ( id, environment, data ) => { | ||
const id_token = googleAuth.getIdToken (); | ||
const id_token = googleAuth.getIdToken ( environment ); | ||
const query = environment !== 'local' ? `?id_token=${ id_token }` : ''; | ||
@@ -77,3 +74,3 @@ | ||
try { | ||
rawdata = fs.readFileSync ( require ( 'path' ).join ( __dirname, 'particleConf.json' ) ); | ||
rawdata = fs.readFileSync ( './particleConf.json' ); | ||
particleConf = JSON.parse ( rawdata ); | ||
@@ -94,7 +91,8 @@ if ( !particleConf.targetFile || particleConf.targetFile.length === 0 ) { | ||
const create = () => { | ||
const id_token = googleAuth.getIdToken (); | ||
const env = prompt ( 'What is the environment of the particle you want to create? (local, test, prod) ' ); | ||
const title = prompt ( 'What is the tile of the particle you want to create? ' ); | ||
const fileToDeploy = prompt ( 'What is the path to the file you wish to link? (relative to the project root folder!) ' ); | ||
const id_token = googleAuth.getIdToken ( env ); | ||
const query = env !== 'local' ? `?id_token=${ id_token }` : ''; | ||
@@ -108,3 +106,3 @@ request.post ( `${ config[ env ].apiUrl }/particles${ query }`, { json: { "type": "embed", "version": "0.0.1", "title": title, "space": "editorial" } }, ( error, response, body ) => { | ||
if ( response && response.statusCode === 201 ) { | ||
fs.writeFileSync ( require ( 'path' ).join ( __dirname, 'particleConf.json' ), JSON.stringify ( { "environment": env, "id": body.data.id, targetFile: fileToDeploy } ) ); | ||
fs.writeFileSync ( './particleConf.json', JSON.stringify ( { "environment": env, "id": body.data.id, targetFile: fileToDeploy } ) ); | ||
console.log ( `Particle of type 'embed' was successfuly created with id ${ body.data.id }` ); | ||
@@ -127,2 +125,5 @@ } else { | ||
requests.some ( req => { | ||
if ( req[ 0 ] !== 200 ) { | ||
console.log ( `Particle not found in ${ req[ 1 ] } or there was a network error!` ); | ||
} | ||
if ( req[ 2 ].hasOwnProperty ( 'request' ) ) { | ||
@@ -135,3 +136,3 @@ env = req[ 1 ]; | ||
const fileToDeploy = prompt ( 'What is the path to the file you wish to deploy? (relative to the project root folder!) ' ); | ||
fs.writeFileSync ( require ( 'path' ).join ( __dirname, 'particleConf.json' ), JSON.stringify ( { "environment": env, "id": particleId, "targetFile": fileToDeploy } ) ); | ||
fs.writeFileSync ( './particleConf.json', JSON.stringify ( { "environment": env, "id": particleId, "targetFile": fileToDeploy } ) ); | ||
console.log ( `Particle linked successfully!` ); | ||
@@ -195,2 +196,3 @@ } | ||
if ( e ) { | ||
console.log ( e ); | ||
console.log ( 'targetFile could not be read, make sure it exists and the path is right in particleConf.js!' ); | ||
@@ -197,0 +199,0 @@ return; |
542
25449