@dynamicweb/cli 1.0.8 → 1.0.10

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) => {
@@ -104,6 +104,7 @@ async function handleFiles(argv) {
104
104
  if (argv.recursive) {
105
105
  await processDirectory(env, user, resolvedPath, argv.outPath, resolvedPath, argv.createEmpty, true, argv.overwrite);
106
106
  } else {
107
+ console.log(resolvedPath)
107
108
  let filesInDir = getFilesInDirectory(resolvedPath);
108
109
  await uploadFiles(env, user, filesInDir, argv.outPath, argv.createEmpty, argv.overwrite);
109
110
  }
@@ -112,7 +113,7 @@ async function handleFiles(argv) {
112
113
  }
113
114
 
114
115
  function getFilesInDirectory(dirPath) {
115
- return fs.readdirSync(dirPath)
116
+ return fs.statSync(dirPath).isFile() ? [ dirPath ] : fs.readdirSync(dirPath)
116
117
  .map(file => path.join(dirPath, file))
117
118
  .filter(file => fs.statSync(file).isFile());
118
119
  }
@@ -237,6 +238,8 @@ async function getFilesStructure(env, user, dirPath, recursive, includeFiles) {
237
238
  return await res.json();
238
239
  } else {
239
240
  console.log(res);
241
+ console.log(res.json());
242
+ process.exit(1);
240
243
  }
241
244
  }
242
245
 
@@ -247,8 +250,11 @@ export async function uploadFiles(env, user, localFilePaths, destinationPath, cr
247
250
  form.append('skipExistingFiles', String(!overwrite));
248
251
  form.append('allowOverwrite', String(overwrite));
249
252
  localFilePaths.forEach((localPath, index) => {
250
- console.log(localPath)
251
- form.append('files', fs.createReadStream(path.resolve(localPath)));
253
+ let fileToUpload = resolveFilePath(localPath)
254
+ console.log(fileToUpload)
255
+ if (fileToUpload === undefined)
256
+ return;
257
+ form.append('files', fs.createReadStream(path.resolve(fileToUpload)));
252
258
  });
253
259
  let res = await fetch(`${env.protocol}://${env.host}/Admin/Api/Upload?` + new URLSearchParams({"createEmptyFiles": createEmpty, "createMissingDirectories": true}), {
254
260
  method: 'POST',
@@ -265,6 +271,26 @@ export async function uploadFiles(env, user, localFilePaths, destinationPath, cr
265
271
  else {
266
272
  console.log(res)
267
273
  console.log(res.json())
268
- return;
274
+ process.exit(1);
275
+ }
276
+ }
277
+
278
+ export function resolveFilePath(filePath) {
279
+ let p = path.parse(path.resolve(filePath))
280
+ let regex = wildcardToRegExp(p.base);
281
+ let resolvedPath = fs.readdirSync(p.dir).filter((allFilesPaths) => allFilesPaths.match(regex) !== null)[0]
282
+ if (resolvedPath === undefined)
283
+ {
284
+ console.log('Could not find any files with the name ' + filePath);
285
+ process.exit(1);
269
286
  }
287
+ return path.join(p.dir, resolvedPath);
288
+ }
289
+
290
+ function wildcardToRegExp(wildcard) {
291
+ return new RegExp('^' + wildcard
292
+ .replace(/\./g, '\\.')
293
+ .replace(/\*/g, '.*')
294
+ .replace(/\?/g, '.')
295
+ + '$');
270
296
  }
@@ -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', false, true);
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.8",
5
+ "version": "1.0.10",
6
6
  "main": "bin/index.js",
7
7
  "files": [
8
8
  "bin/*"