@dynamicweb/cli
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -79,6 +79,4 @@ import { updateConfig, getConfig } from './config.js' | ||
}, | ||
protocol: { | ||
type: 'input' | ||
}, | ||
host: { | ||
describe: 'Enter your host including protocol, i.e "https://yourHost.com":', | ||
type: 'input' | ||
@@ -100,5 +98,15 @@ }, | ||
getConfig().env[result.environment] = getConfig().env[result.environment] || {}; | ||
getConfig().env[result.environment].protocol = result.protocol || 'https'; | ||
if (result.host) | ||
getConfig().env[result.environment].host = result.host; | ||
if (result.host) { | ||
var hostSplit = result.host.split("://"); | ||
if (hostSplit.length == 1) { | ||
getConfig().env[result.environment].protocol = 'https'; | ||
getConfig().env[result.environment].host = hostSplit[0]; | ||
} else if (hostSplit.length == 2) { | ||
getConfig().env[result.environment].protocol = hostSplit[0]; | ||
getConfig().env[result.environment].host = hostSplit[1]; | ||
} else { | ||
console.log(`Issues resolving host ${result.host}`); | ||
return; | ||
} | ||
} | ||
if (result.environment) { | ||
@@ -110,2 +118,3 @@ getConfig().current = getConfig().current || {}; | ||
console.log(`Your current environment is now ${getConfig().current.env}`); | ||
console.log(`To change the host of your environment, use the command 'dw env'`) | ||
}); | ||
@@ -124,2 +133,3 @@ } | ||
host: { | ||
describe: 'Enter your host including protocol, i.e "https://yourHost.com":', | ||
type: 'input', | ||
@@ -126,0 +136,0 @@ prompt: 'always' |
@@ -31,3 +31,3 @@ import fetch from 'node-fetch'; | ||
type: 'boolean', | ||
describe: 'Exports the directory at [dirPath] to [outPath]' | ||
describe: 'Exports the specified directory and all subdirectories at [dirPath] to [outPath]' | ||
}) | ||
@@ -79,7 +79,7 @@ .option('import', { | ||
if (argv.dirPath) { | ||
await download(env, user, argv.dirPath, argv.outPath, argv.recursive, null, argv.raw, []); | ||
await download(env, user, argv.dirPath, argv.outPath, true, null, argv.raw, argv.iamstupid, []); | ||
} else { | ||
await interactiveConfirm('Are you sure you want a full export of files?', async () => { | ||
console.log('Full export is starting') | ||
let filesStructure = (await getFilesStructure(env, user, '/', false, argv.includeFiles)).model; | ||
let filesStructure = (await getFilesStructure(env, user, '/', false, true)).model; | ||
let dirs = filesStructure.directories; | ||
@@ -86,0 +86,0 @@ for (let id = 0; id < dirs.length; id++) { |
@@ -34,5 +34,7 @@ import fetch from 'node-fetch'; | ||
console.log('Installing addin') | ||
let filename = path.basename(resolvedPath); | ||
let data = { | ||
'AddinProvider': 'Dynamicweb.Marketplace.Providers.LocalAddinProvider', | ||
'Package': path.basename(resolvedPath) | ||
'Ids': [ | ||
`${filename.substring(0, filename.lastIndexOf('.')) || filename}|${path.extname(resolvedPath)}` | ||
] | ||
} | ||
@@ -54,4 +56,5 @@ let res = await fetch(`${env.protocol}://${env.host}/Admin/Api/AddinInstall`, { | ||
else { | ||
console.log(res) | ||
console.log('Request failed, returned error:') | ||
console.log(await res.json()) | ||
} | ||
} |
@@ -73,3 +73,3 @@ import fetch from 'node-fetch'; | ||
if (!getConfig().env || !getConfig().env[result.environment] || !getConfig().env[result.environment].host || !getConfig().env[result.environment].protocol) { | ||
if (!argv.host || !argv.protocol) | ||
if (!argv.host) | ||
console.log(`The environment specified is missing parameters, please specify them`) | ||
@@ -82,7 +82,4 @@ await interactiveEnv(argv, { | ||
}, | ||
protocol: { | ||
type: 'input', | ||
prompt: 'if-no-arg' | ||
}, | ||
host: { | ||
describe: 'Enter your host including protocol, i.e "https://yourHost.com":', | ||
type: 'input', | ||
@@ -96,10 +93,12 @@ prompt: 'if-no-arg' | ||
} | ||
await loginInteractive(result); | ||
await loginInteractive(result, argv.verbose); | ||
}); | ||
} | ||
async function loginInteractive(result) { | ||
async function loginInteractive(result, verbose) { | ||
var protocol = getConfig().env[result.environment].protocol; | ||
var token = await login(result.username, result.password, result.environment, protocol); | ||
var apiKey = await getApiKey(token, result.environment, protocol) | ||
var token = await login(result.username, result.password, result.environment, protocol, verbose); | ||
if (!token) return; | ||
var apiKey = await getApiKey(token, result.environment, protocol, verbose) | ||
if (!apiKey) return; | ||
getConfig().env = getConfig().env || {}; | ||
@@ -114,3 +113,3 @@ getConfig().env[result.environment].users = getConfig().env[result.environment].users || {}; | ||
async function login(username, password, env, protocol) { | ||
async function login(username, password, env, protocol, verbose) { | ||
let data = new URLSearchParams(); | ||
@@ -130,6 +129,8 @@ data.append('Username', username); | ||
let user = parseCookies(res.headers.get('set-cookie')).user; | ||
return await getToken(user, env, protocol) | ||
if (!user) return; | ||
return await getToken(user, env, protocol, verbose) | ||
} | ||
else { | ||
console.log(res) | ||
if (verbose) console.info(res) | ||
console.log(`Login attempt failed with username ${username}, please verify its a valid user in your Dynamicweb solution.`) | ||
} | ||
@@ -140,3 +141,6 @@ } | ||
const list = {}; | ||
if (!cookieHeader) return list; | ||
if (!cookieHeader) { | ||
console.log(`Could not get the necessary information from the login request, please verify its a valid user in your Dynamicweb solution.`) | ||
return list; | ||
} | ||
@@ -152,7 +156,11 @@ cookieHeader.replace('httponly, ', '').replace('Dynamicweb.Admin', 'user').split(`;`).forEach(cookie => { | ||
if (!list.user) { | ||
console.log(`Could not get the necessary information from the login request, please verify its a valid user in your Dynamicweb solution.`) | ||
} | ||
return list; | ||
} | ||
async function getToken(user, env, protocol) { | ||
var res = await fetch(`${getConfig().env[env].protocol}://${getConfig().env[env].host}/Admin/Authentication/Token`, { | ||
async function getToken(user, env, protocol, verbose) { | ||
var res = await fetch(`${protocol}://${getConfig().env[env].host}/Admin/Authentication/Token`, { | ||
method: 'GET', | ||
@@ -167,8 +175,12 @@ headers: { | ||
} | ||
else { | ||
if (verbose) console.info(res) | ||
console.log(`Could not fetch the token for the logged in user ${user}, please verify its a valid user in your Dynamicweb solution.`) | ||
} | ||
} | ||
async function getApiKey(token, env, protocol) { | ||
async function getApiKey(token, env, protocol, verbose) { | ||
let data = { | ||
'Name': 'addin', | ||
'Prefix': 'addin', | ||
'Name': 'DW CLI', | ||
'Prefix': 'CLI', | ||
'Description': 'Auto-generated ApiKey by DW CLI' | ||
@@ -190,3 +202,4 @@ }; | ||
else { | ||
console.log(await res.json()) | ||
if (verbose) console.info(res) | ||
console.log(`Could not create an API Key for the logged in user, please verify its a valid user in your Dynamicweb solution.`) | ||
} | ||
@@ -193,0 +206,0 @@ } |
@@ -42,2 +42,6 @@ #! /usr/bin/env node | ||
handler: () => { | ||
if (Object.keys(getConfig()).length === 0) { | ||
console.log('To login to a solution use `dw login`') | ||
return; | ||
} | ||
console.log(`Environment: ${getConfig()?.current?.env}`) | ||
@@ -44,0 +48,0 @@ console.log(`User: ${getConfig()?.env[getConfig()?.current?.env]?.current?.user}`) |
@@ -8,3 +8,3 @@ import yargsInteractive from 'yargs-interactive'; | ||
type: 'confirm', | ||
default: false, | ||
default: true, | ||
describe: question, | ||
@@ -11,0 +11,0 @@ prompt: 'always' |
@@ -5,3 +5,3 @@ { | ||
"description": "Dynamicweb CLI is a commandline tool for interacting with Dynamicweb 10 solutions.", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"main": "bin/index.js", | ||
@@ -8,0 +8,0 @@ "files": [ |
46791
1011