@dynamicweb/cli 1.0.5 → 1.0.7

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.
@@ -101,57 +101,32 @@ async function handleFiles(argv) {
101
101
  } else if (argv.import) {
102
102
  if (argv.dirPath && argv.outPath) {
103
103
  let resolvedPath = path.resolve(argv.dirPath);
104
- let files;
105
- if (!argv.overwrite) {
106
- files = (await getFilesStructure(env, user, argv.outPath, argv.recursive, true)).model;
107
- }
108
104
  if (argv.recursive) {
109
- await processDirectory(env, user, resolvedPath, argv.outPath, files, resolvedPath, argv.createEmpty, true);
105
+ await processDirectory(env, user, resolvedPath, argv.outPath, resolvedPath, argv.createEmpty, true, argv.overwrite);
110
106
  } else {
111
107
  let filesInDir = getFilesInDirectory(resolvedPath);
112
- if (files)
113
- filesInDir = getFilesNotInData(filesInDir, files.files.data, resolvedPath);
114
- await uploadFiles(env, user, filesInDir, argv.outPath, argv.createEmpty);
108
+ await uploadFiles(env, user, filesInDir, argv.outPath, argv.createEmpty, argv.overwrite);
115
109
  }
116
110
  }
117
111
  }
118
112
  }
119
113
 
120
- function convertToDataFormat(filePath, resolvedPath) {
121
- const relativePath = `/Files${filePath.substring(resolvedPath.length)}`;
122
- return path.format(path.parse(relativePath)).replace(/\\/g, '/');
123
- }
124
-
125
- function getFilesNotInData(filesInDir, data, resolvedPath) {
126
- const existingPaths = data.map(file => file.filePath);
127
- return filesInDir.filter(filePath => {
128
- const convertedPath = convertToDataFormat(filePath, resolvedPath);
129
- return !existingPaths.includes(convertedPath);
130
- });
131
- }
132
-
133
114
  function getFilesInDirectory(dirPath) {
134
115
  return fs.readdirSync(dirPath)
135
116
  .map(file => path.join(dirPath, file))
136
117
  .filter(file => fs.statSync(file).isFile());
137
118
  }
138
119
 
139
- async function processDirectory(env, user, dirPath, outPath, files, originalDir, createEmpty, isRoot = false) {
120
+ async function processDirectory(env, user, dirPath, outPath, originalDir, createEmpty, isRoot = false, overwrite = false) {
140
121
  let filesInDir = getFilesInDirectory(dirPath);
141
- let missingFiles;
142
- if (files === undefined)
143
- missingFiles = filesInDir;
144
- else
145
- missingFiles = getFilesNotInData(filesInDir, files.files.data, originalDir);
146
- if (missingFiles.length > 0)
147
- await uploadFiles(env, user, missingFiles, isRoot ? outPath : path.join(outPath, path.basename(dirPath)), createEmpty);
122
+ if (filesInDir.length > 0)
123
+ await uploadFiles(env, user, filesInDir, isRoot ? outPath : path.join(outPath, path.basename(dirPath)), createEmpty, overwrite);
148
124
 
149
125
  const subDirectories = fs.readdirSync(dirPath)
150
126
  .map(subDir => path.join(dirPath, subDir))
151
127
  .filter(subDir => fs.statSync(subDir).isDirectory());
152
128
  for (let subDir of subDirectories) {
153
- const remoteSubDir = files?.directories.find(dir => dir.name === path.basename(subDir));
154
- await processDirectory(env, user, subDir, isRoot ? outPath : path.join(outPath, path.basename(dirPath)), remoteSubDir, originalDir, createEmpty);
129
+ await processDirectory(env, user, subDir, isRoot ? outPath : path.join(outPath, path.basename(dirPath)), originalDir, createEmpty, false, overwrite);
155
130
  }
156
131
  }
157
132
 
@@ -265,10 +240,12 @@ async function getFilesStructure(env, user, dirPath, recursive, includeFiles) {
265
240
  }
266
241
  }
267
242
 
268
- export async function uploadFiles(env, user, localFilePaths, destinationPath, createEmpty = false) {
243
+ export async function uploadFiles(env, user, localFilePaths, destinationPath, createEmpty = false, overwrite = false) {
269
244
  console.log('Uploading files')
270
245
  let form = new FormData();
271
246
  form.append('path', destinationPath);
247
+ form.append('skipExistingFiles', String(!overwrite));
248
+ form.append('allowOverwrite', String(overwrite));
272
249
  localFilePaths.forEach((localPath, index) => {
273
250
  console.log(localPath)
274
251
  form.append('files', fs.createReadStream(path.resolve(localPath)));
@@ -282,7 +259,7 @@ export async function uploadFiles(env, user, localFilePaths, destinationPath, cr
282
259
  agent: getAgent(env.protocol)
283
260
  });
284
261
  if (res.ok) {
285
- if (env.verbose) console.log(await res.json())
262
+ console.log(await res.json())
286
263
  console.log(`Files uploaded`)
287
264
  }
288
265
  else {
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.5",
5
+ "version": "1.0.7",
6
6
  "main": "bin/index.js",
7
7
  "files": [
8
8
  "bin/*"