New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

viewar-cli

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

viewar-cli - npm Package Compare versions

Comparing version 0.2.5 to 0.3.0

common/exit-with-error.js

4

commands/activate.js
const path = require('path')
const request = require('request-promise')
const { readJson } = require('../common/json')
const { getAppConfigUrl, getActivateUrl } = require('../common/urls')
const { cliConfigPath } = require('../common/constants')
module.exports = ({request, readJson}) => async (appId, version) => {
module.exports = async (appId, version) => {

@@ -8,0 +10,0 @@ const info = await request(getAppConfigUrl(appId, version)).then(JSON.parse)

const chalk = require('chalk')
const path = require('path')
const fs = require('fs')
const shell = require('shelljs')
const request = require('request-promise')
const zipDirectory = require('../common/zip-dir')
const { readJson, writeJson } = require('../common/json')
const { getAppConfigUrl, getActivateUrl, getUploadBundleUrl } = require('../common/urls')
const { cliConfigPath } = require('../common/constants')
module.exports = ({fs, shell, zipDirectory, readJson, writeJson, request}) => async (appId, version, tags) => {
module.exports = async (appId, version, tags) => {
const appRoot = process.cwd()

@@ -9,0 +14,0 @@ const buildDir = path.resolve(appRoot, 'build') + '/'

@@ -1,27 +0,9 @@

const fs = require('fs')
const shell = require('shelljs')
const request = require('request-promise')
const archiver = require('archiver')
const zipDirectory = require('../common/zip-dir')({fs, archiver})
const {readJson, updateJson, writeJson} = require('../common/json')
const activate = require('./activate')({request, readJson})
const deploy = require('./deploy')({fs, shell, zipDirectory, readJson, writeJson, request})
const init = require('./init')({shell, updateJson, writeJson, fs})
const initSample = require('./init-sample')({shell, updateJson, writeJson, fs})
const list = require('./list')({request, readJson})
const login = require('./login')({request, updateJson})
const logout = require('./logout')({request, updateJson})
const whoami = require('./whoami')({readJson})
module.exports = {
activate,
deploy,
init,
initSample,
list,
login,
logout,
whoami,
activate: require('./activate'),
deploy: require('./deploy'),
init: require('./init'),
list: require('./list'),
login: require('./login'),
logout: require('./logout'),
whoami: require('./whoami'),
}
const chalk = require('chalk')
const path = require('path')
const shell = require('shelljs')
const inquirer = require('inquirer')
const request = require('request-promise')
const exitWithError = require('../common/exit-with-error')
const generateToken = require('../common/generate-token')
const { readJson, updateJson, writeJson } = require('../common/json')
const { createAppUrl, getRepositoryUrl } = require('../common/urls')
const { cliConfigPath: cliConfigFile, repositoryUrl } = require('../common/constants')
const {repositoryUrl} = require('../common/constants')
const projectTypes = {
'Vanilla Javascript': 'vanilla',
'React': 'react',
'Sample project': 'sample',
}
module.exports = ({shell, updateJson, writeJson}) => async (projectName = '.', type = 'vanilla') => {
const projectDir = path.resolve(process.cwd(), projectName)
const sampleProjects = {
'Base6': 'base6',
'Other...': 'other',
}
module.exports = async (userEmail, projectType) => {
const projectDir = path.resolve(process.cwd())
const packageInfoPath = path.resolve(projectDir, 'package.json')
const cliConfigPath = path.resolve(projectDir, '.viewar-config')
if (shell.mkdir('-p', projectDir).code !== 0) {
if (!shell.test('-d', projectDir)) {
throw new Error(`${projectDir} exists and is not a directory!`)
const dirEmpty = shell.ls(projectDir).length === 0;
if (!dirEmpty) {
exitWithError('Directory not empty!')
}
const projectName = process.cwd().split(path.sep).pop()
const userList = Object.values(readJson(cliConfigFile).users || {})
if (userList.length === 0) {
exitWithError('There are no users logged in! Run viewar-api login first!')
}
const enteredUser = userEmail && userList.find(user => user.email === userEmail)
if (userEmail && !enteredUser) {
exitWithError(`User with email ${userEmail} is not logged in! Run viewar-api whoami to see which user accounts are logged in!`)
}
console.log(chalk`\nWelcome to ViewAR app initialization process!\n`);
const user = enteredUser ? enteredUser : (userList.length === 1 ? userList[0] : null);
if (user) {
if (enteredUser) {
console.log(`Logged in as: ${user.name} <${user.email}>`)
} else {
console.log(`Only one user account found, using this one: ${user.name} <${user.email}>`)
}
}
shell.cd(projectDir)
const answers = await inquirer.prompt([
{
name: 'token',
type: 'list',
message: 'Select the user account for this app:',
choices: userList.map(({name, email}) => `${name} <${email}>`),
filter: (choice) => userList.find(({name, email}) => `${name} <${email}>` === choice).token,
when: () => !user,
},
{
name: 'type',
type: 'list',
message: 'Select a project type:',
choices: Object.keys(projectTypes),
filter: (value) => projectTypes[value],
when: () => !projectType,
},
{
name: 'sample',
type: 'list',
message: 'Select a sample project',
choices: Object.keys(sampleProjects),
filter: (value) => sampleProjects[value],
when: ({type}) => projectType === projectTypes['Sample project'] || type === projectTypes['Sample project'],
},
{
name: 'sampleUrl',
type: 'input',
message: 'Repository URL',
when: ({sample}) => sample === sampleProjects['Other...'],
},
{
name: 'appId',
type: 'input',
message: 'Enter the app bundle ID:',
validate: (value) => /^[a-zA-Z0-9]+(?:\.[a-zA-Z0-9]+)+$/.test(value),
},
{
name: 'version',
type: 'input',
message: 'Enter the app version:',
default: '1.0',
//validate: (value) => /\d+(?:\.\d+(?:\.\d+)?)?/.test(value),
validate: (value) => /\d+(?:\.\d+)?/.test(value),
},
{
name: 'trackers',
type: 'checkbox',
message: 'Choose trackers',
choices: [
{
name: 'ARKit',
},
{
name: 'Vuforia',
},
{
name: 'Wikitude',
},
],
},
])
const dirEmpty = shell.ls(projectDir).length === 0;
const {token, type, appId, version, trackers, sample, sampleUrl} = Object.assign({
token: user && user.token,
type: projectType,
}, answers)
if (shell.ls(projectDir).length === 0) {
const formData = {
bundleIdentifier: appId,
version,
token,
tracker: trackers.join(','),
}
console.log(chalk`\nCreating app...`)
await request.post({uri: createAppUrl(), formData})
if (sampleUrl || sample) {
console.log(chalk`\nChecking out sample project...`)
shell.exec(`git clone -b master ${sampleUrl || getRepositoryUrl(sample)} .`, {silent: true})
} else {
console.log(chalk`\nDownloading boilerplate project...`)

@@ -29,26 +151,20 @@

shell.rm('-rf', 'temp')
}
console.log(chalk`\nInstalling dependencies...`)
console.log(chalk`\nInstalling dependencies...`)
if (shell.exec('npm install', {silent: true}).code !== 0) {
throw new Error(`Failed installing npm dependencies! Check if npm is installed and up-to-date.`)
}
if (shell.exec('npm install', {silent: true}).code !== 0) {
exitWithError(`Failed installing npm dependencies! Check if npm is installed and up-to-date.`)
}
console.log(chalk`\nInitializing git repository...`)
console.log(chalk`\nInitializing git repository...`)
if (shell.exec('git init', {silent: true}).code !== 0) {
throw new Error(`Git repository initialization failed! Check if git is installed.`)
}
updateJson(packageInfoPath, (object) => Object.assign(object, {
name: projectName,
description: '',
}))
} else {
console.log(chalk`\nExisting files detected in directory ${projectDir}, writing .viewar-config`)
if (shell.exec('git init', {silent: true}).code !== 0) {
exitWithError(`Git repository initialization failed! Check if git is installed.`)
}
if (shell.test('-f', '.viewar-config')) {
shell.mv('.viewar-config', `.viewar-config.old.${generateToken()}`)
}
updateJson(packageInfoPath, (object) => Object.assign(object, {
name: projectName,
description: '',
}))

@@ -58,9 +174,7 @@ writeJson(cliConfigPath, {

token: generateToken(),
appId,
version,
})
if (dirEmpty) {
console.log(chalk`\n{bold Done!}\n Enter the new project directory by running {green cd ${projectName}}\n Run {green npm start} to start the development server (defaults to {green localhost:8080 })\n Open {green /src/index.js} to begin editing your app.`)
} else {
console.log(chalk`\n{bold Done!}`)
}
console.log(chalk`\n{bold Done!}\n Run {green npm start} to start the development server (defaults to {green localhost:8080 })\n Open {green /src/index.js} to begin editing your app.`)
}

@@ -0,11 +1,14 @@

const request = require('request-promise')
const { readJson } = require('../common/json')
const { getListAppsUrl } = require('../common/urls')
const { cliConfigPath } = require('../common/constants')
module.exports = ({request, readJson}) => async (username) => {
module.exports = async (email) => {
const data = readJson(cliConfigPath)
const entry = Object.values(data.users || {}).find((user) => user.name === username)
const entry = Object.values(data.users || {}).find((user) => user.email === email)
if (!entry) {
return new Error(`User ${username} is not logged in!`)
return new Error(`User ${email} is not logged in!`)
}

@@ -12,0 +15,0 @@

const crypto = require('crypto')
const hash = crypto.createHash('md5')
const prompt = require('prompt')
const inquirer = require('inquirer')
const request = require('request-promise')
const {cliConfigPath} = require('../common/constants')
const {getLoginUrl} = require('../common/urls')
const exitWithError = require('../common/exit-with-error')
const { updateJson } = require('../common/json')
const { cliConfigPath } = require('../common/constants')
const { getLoginUrl } = require('../common/urls')
module.exports = ({request, updateJson}) => async () => {
module.exports = async (userEmail) => {
const validateEmail = (value) => /.+@.+\..+/.test(value)
try {
const {username, password} = await (new Promise((resolve, reject) => {
prompt.start()
prompt.message = ''
prompt.delimiter = ':'
const {email = userEmail, password} = await inquirer.prompt([
{
type: 'input',
message: 'Enter email:',
name: 'email',
validate: validateEmail,
when: () => !validateEmail(userEmail)
},
{
type: 'password',
message: 'Enter password:',
name: 'password',
},
])
prompt.get([{
name: 'username',
description: 'Username',
pattern: /.+@.+\..+/,
required: true,
}, {
name: 'password',
description: 'Password',
hidden: true,
}], function (error, result) {
if (!error) {
resolve(result)
} else {
reject(error)
}
})
}))
const passwordHash = hash.update(password).digest('hex')
const passwordHash = hash.update(password).digest('hex')
const response = await request.post(getLoginUrl(email, passwordHash)).then(JSON.parse)
const response = await request.post(getLoginUrl(username, passwordHash)).then(JSON.parse)
const {status, userId, fullname: userName, token} = response
const {status, message, userId, token} = response
if (status === 'ok') {
updateJson(cliConfigPath, (config) => {
config.users = config.users || {}
config.users[userId] = {
id: userId,
name: userName,
email: email,
token,
}
if (status === 'ok') {
updateJson(cliConfigPath, (config) => {
config.users = config.users || {}
config.users[userId] = {
id: userId,
name: username,
token,
}
return config
})
console.log(`User ${username} logged in.`)
} else {
throw new Error(message)
}
} catch (error) {
return config
})
console.log(`User ${userName} <${email}> logged in.`)
} else {
exitWithError('Authentication failed! Wrong email or password!')
}
}

@@ -1,8 +0,5 @@

const os = require('os')
const { updateJson } = require('../common/json')
const { cliConfigPath } = require('../common/constants')
const cliConfigPath = `${os.homedir()}/.viewar-cli`
module.exports = () => async (username) => {
module.exports = async (username) => {
updateJson(cliConfigPath, (config) => {

@@ -9,0 +6,0 @@ config.users = config.users || {}

const { cliConfigPath } = require('../common/constants')
const { readJson } = require('../common/json')
module.exports = ({readJson}) => () => {
module.exports = () => {
const data = readJson(cliConfigPath)
console.log(Object.values(data.users).map(user => user.name).join('\n'))
}

@@ -6,2 +6,3 @@ const getLoginUrl = (username, passwordHash) => `http://dev2.viewar.com/api40/getUserToken/user:${username}/password:${passwordHash}`

const getAppConfigUrl = (appId, version) => `http://api.viewar.com/api20/configuration/bundleidentifier:${appId}/version:${version}`
const createAppUrl = () => `https://dev2.viewar.com/api40/createApp`

@@ -11,2 +12,3 @@ const getRepositoryUrl = (templateName) => `https://github.com/viewar/viewar-template-${templateName}.git`

module.exports = {
createAppUrl,
getActivateUrl,

@@ -13,0 +15,0 @@ getAppConfigUrl,

@@ -1,2 +0,5 @@

module.exports = ({fs, archiver}) => (dirPath, zipPath) => {
const fs = require('fs')
const archiver = require('archiver')
module.exports = (dirPath, zipPath) => {
return new Promise((resolve, reject) => {

@@ -3,0 +6,0 @@ const output = fs.createWriteStream(zipPath)

@@ -7,6 +7,6 @@ #!/usr/bin/env node

const currentVersion = require('./package.json').version
const { deploy, init, initSample, list, login, logout, whoami } = require('./commands')
const { deploy, init, list, login, logout, whoami } = require('./commands')
if (!shell.test('-f', '~/.viewar-cli')) {
shell.exec('echo "{}" > ~/.viewar-cli')
shell.exec('echo "{\n "users": {}\n}" > ~/.viewar-cli')
}

@@ -17,3 +17,3 @@

program
.command('init [project-name] [type]')
.command('init [user-email] [type]')
.description('Prepares a new ViewAR project')

@@ -23,8 +23,3 @@ .action(init)

program
.command('init-sample <sample-name> [dir]')
.description('Prepares a new ViewAR sample')
.action(initSample)
program
.command('login')
.command('login [user-email]')
.description('Logs in user')

@@ -34,3 +29,3 @@ .action(login)

program
.command('logout <username>')
.command('logout <user-email>')
.description('Logs out user')

@@ -45,3 +40,3 @@ .action(logout)

program
.command('list <username>')
.command('list <user-email>')
.description('List available apps')

@@ -48,0 +43,0 @@ .action(list)

{
"name": "viewar-cli",
"version": "0.2.5",
"version": "0.3.0",
"description": "ViewAR SDK Command Line Interface",

@@ -29,2 +29,3 @@ "main": "index.js",

"commander": "^2.13.0",
"inquirer": "^5.1.0",
"prompt": "^1.0.0",

@@ -31,0 +32,0 @@ "request": "^2.83.0",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc