@dynamicweb/cli 1.0.7 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -83,6 +83,7 @@ async function runCommand(env, user, command, queryParams, data) {
83
83
  })
84
84
  if (!res.ok) {
85
85
  console.log(`Error when doing request ${res.url}`)
86
+ process.exit(1);
86
87
  }
87
88
  return await res.json()
88
89
  }
@@ -58,7 +58,7 @@ async function download(env, user, path, verbose) {
58
58
  return res;
59
59
  }).then(async (res) => {
60
60
  if (!res) {
61
- return;
61
+ process.exit(1);
62
62
  }
63
63
  const fileStream = fs.createWriteStream(_path.resolve(`${_path.resolve(path)}/${filename}`));
64
64
  await new Promise((resolve, reject) => {
@@ -237,6 +237,8 @@ async function getFilesStructure(env, user, dirPath, recursive, includeFiles) {
237
237
  return await res.json();
238
238
  } else {
239
239
  console.log(res);
240
+ console.log(res.json());
241
+ process.exit(1);
240
242
  }
241
243
  }
242
244
 
@@ -247,8 +249,11 @@ export async function uploadFiles(env, user, localFilePaths, destinationPath, cr
247
249
  form.append('skipExistingFiles', String(!overwrite));
248
250
  form.append('allowOverwrite', String(overwrite));
249
251
  localFilePaths.forEach((localPath, index) => {
250
- console.log(localPath)
251
- form.append('files', fs.createReadStream(path.resolve(localPath)));
252
+ let fileToUpload = resolveFilePath(localPath)
253
+ console.log(fileToUpload)
254
+ if (fileToUpload === undefined)
255
+ return;
256
+ form.append('files', fs.createReadStream(path.resolve(fileToUpload)));
252
257
  });
253
258
  let res = await fetch(`${env.protocol}://${env.host}/Admin/Api/Upload?` + new URLSearchParams({"createEmptyFiles": createEmpty, "createMissingDirectories": true}), {
254
259
  method: 'POST',
@@ -265,6 +270,26 @@ export async function uploadFiles(env, user, localFilePaths, destinationPath, cr
265
270
  else {
266
271
  console.log(res)
267
272
  console.log(res.json())
268
- return;
273
+ process.exit(1);
274
+ }
275
+ }
276
+
277
+ export function resolveFilePath(filePath) {
278
+ let p = path.parse(path.resolve(filePath))
279
+ let regex = wildcardToRegExp(p.base);
280
+ let resolvedPath = fs.readdirSync(p.dir).filter((allFilesPaths) => allFilesPaths.match(regex) !== null)[0]
281
+ if (resolvedPath === undefined)
282
+ {
283
+ console.log('Could not find any files with the name ' + filePath);
284
+ process.exit(1);
269
285
  }
286
+ return resolvedPath;
287
+ }
288
+
289
+ function wildcardToRegExp(wildcard) {
290
+ return new RegExp('^' + wildcard
291
+ .replace(/\./g, '\\.')
292
+ .replace(/\*/g, '.*')
293
+ .replace(/\?/g, '.')
294
+ + '$');
270
295
  }
@@ -2,7 +2,7 @@ import fetch from 'node-fetch';
2
2
  import path from 'path';
3
3
  import { setupEnv, getAgent } from './env.js';
4
4
  import { setupUser } from './login.js';
5
- import { uploadFiles } from './files.js';
5
+ import { uploadFiles, resolveFilePath } from './files.js';
6
6
 
7
7
  export function installCommand() {
8
8
  return {
@@ -24,9 +24,8 @@ export function installCommand() {
24
24
  async function handleInstall(argv) {
25
25
  let env = await setupEnv(argv);
26
26
  let user = await setupUser(argv, env);
27
- let resolvedPath = path.resolve(argv.filePath)
28
- await uploadFiles(env, user, [resolvedPath], 'System/AddIns/Local');
29
- await installAddin(env, user, resolvedPath)
27
+ await uploadFiles(env, user, [ argv.filePath ], 'System/AddIns/Local', false, true);
28
+ await installAddin(env, user, resolveFilePath(argv.filePath))
30
29
  }
31
30
 
32
31
  async function installAddin(env, user, resolvedPath) {
@@ -54,5 +53,6 @@ async function installAddin(env, user, resolvedPath) {
54
53
  else {
55
54
  console.log('Request failed, returned error:')
56
55
  console.log(await res.json())
56
+ process.exit(1);
57
57
  }
58
58
  }
@@ -135,6 +135,8 @@ async function login(username, password, env, protocol, verbose) {
135
135
  });
136
136
 
137
137
  if (res.ok) {
138
+ console.log(res)
139
+ console.log(res.json())
138
140
  let user = parseCookies(res.headers.get('set-cookie')).user;
139
141
  if (!user) return;
140
142
  return await getToken(user, env, protocol, verbose)
@@ -87,6 +87,7 @@ async function runQuery(env, user, query, params) {
87
87
  })
88
88
  if (!res.ok) {
89
89
  console.log(`Error when doing request ${res.url}`)
90
+ process.exit(1);
90
91
  }
91
92
  return await res.json()
92
93
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@dynamicweb/cli",
3
3
  "type": "module",
4
4
  "description": "Dynamicweb CLI is a commandline tool for interacting with Dynamicweb 10 solutions.",
5
- "version": "1.0.7",
5
+ "version": "1.0.9",
6
6
  "main": "bin/index.js",
7
7
  "files": [
8
8
  "bin/*"