@dynamicweb/cli 1.0.4 → 1.0.6
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.
- package/bin/commands/files.js +10 -31
- package/package.json +1 -1
package/bin/commands/files.js
CHANGED
|
@@ -101,17 +101,11 @@ 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,
|
|
105
|
+
await processDirectory(env, user, resolvedPath, argv.outPath, resolvedPath, argv.createEmpty, true, argv.overwrite);
|
|
110
106
|
} else {
|
|
111
107
|
let filesInDir = getFilesInDirectory(resolvedPath);
|
|
112
|
-
|
|
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
|
}
|
|
@@ -122,36 +116,22 @@ function convertToDataFormat(filePath, resolvedPath) {
|
|
|
122
116
|
return path.format(path.parse(relativePath)).replace(/\\/g, '/');
|
|
123
117
|
}
|
|
124
118
|
|
|
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
119
|
function getFilesInDirectory(dirPath) {
|
|
134
120
|
return fs.readdirSync(dirPath)
|
|
135
121
|
.map(file => path.join(dirPath, file))
|
|
136
122
|
.filter(file => fs.statSync(file).isFile());
|
|
137
123
|
}
|
|
138
124
|
|
|
139
|
-
async function processDirectory(env, user, dirPath, outPath,
|
|
125
|
+
async function processDirectory(env, user, dirPath, outPath, originalDir, createEmpty, isRoot = false, overwrite = false) {
|
|
140
126
|
let filesInDir = getFilesInDirectory(dirPath);
|
|
141
|
-
|
|
142
|
-
|
|
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);
|
|
127
|
+
if (filesInDir.length > 0)
|
|
128
|
+
await uploadFiles(env, user, filesInDir, isRoot ? outPath : path.join(outPath, path.basename(dirPath)), createEmpty, overwrite);
|
|
148
129
|
|
|
149
130
|
const subDirectories = fs.readdirSync(dirPath)
|
|
150
131
|
.map(subDir => path.join(dirPath, subDir))
|
|
151
132
|
.filter(subDir => fs.statSync(subDir).isDirectory());
|
|
152
133
|
for (let subDir of subDirectories) {
|
|
153
|
-
|
|
154
|
-
await processDirectory(env, user, subDir, isRoot ? outPath : path.join(outPath, path.basename(dirPath)), remoteSubDir, originalDir, createEmpty);
|
|
134
|
+
await processDirectory(env, user, subDir, isRoot ? outPath : path.join(outPath, path.basename(dirPath)), originalDir, createEmpty, overwrite);
|
|
155
135
|
}
|
|
156
136
|
}
|
|
157
137
|
|
|
@@ -194,7 +174,6 @@ async function download(env, user, dirPath, outPath, recursive, outname, raw, ia
|
|
|
194
174
|
let excludeDirectories = '';
|
|
195
175
|
if (!iamstupid) {
|
|
196
176
|
excludeDirectories = 'system/log';
|
|
197
|
-
console.log(dirPath)
|
|
198
177
|
if (dirPath === 'cache.net') {
|
|
199
178
|
return;
|
|
200
179
|
}
|
|
@@ -214,8 +193,6 @@ async function download(env, user, dirPath, outPath, recursive, outname, raw, ia
|
|
|
214
193
|
console.log('Downloading', dirPath === '/.' ? 'Base' : dirPath, 'Recursive=' + recursive);
|
|
215
194
|
|
|
216
195
|
let filename;
|
|
217
|
-
console.log(data)
|
|
218
|
-
console.log(`${env.protocol}://${env.host}/Admin/Api/${endpoint}`)
|
|
219
196
|
fetch(`${env.protocol}://${env.host}/Admin/Api/${endpoint}`, {
|
|
220
197
|
method: 'POST',
|
|
221
198
|
body: JSON.stringify(data),
|
|
@@ -268,10 +245,12 @@ async function getFilesStructure(env, user, dirPath, recursive, includeFiles) {
|
|
|
268
245
|
}
|
|
269
246
|
}
|
|
270
247
|
|
|
271
|
-
export async function uploadFiles(env, user, localFilePaths, destinationPath, createEmpty = false) {
|
|
248
|
+
export async function uploadFiles(env, user, localFilePaths, destinationPath, createEmpty = false, overwrite = false) {
|
|
272
249
|
console.log('Uploading files')
|
|
273
250
|
let form = new FormData();
|
|
274
251
|
form.append('path', destinationPath);
|
|
252
|
+
form.append('skipExistingFiles', String(!overwrite));
|
|
253
|
+
form.append('allowOverwrite', String(overwrite));
|
|
275
254
|
localFilePaths.forEach((localPath, index) => {
|
|
276
255
|
console.log(localPath)
|
|
277
256
|
form.append('files', fs.createReadStream(path.resolve(localPath)));
|
|
@@ -285,7 +264,7 @@ export async function uploadFiles(env, user, localFilePaths, destinationPath, cr
|
|
|
285
264
|
agent: getAgent(env.protocol)
|
|
286
265
|
});
|
|
287
266
|
if (res.ok) {
|
|
288
|
-
|
|
267
|
+
console.log(await res.json())
|
|
289
268
|
console.log(`Files uploaded`)
|
|
290
269
|
}
|
|
291
270
|
else {
|
package/package.json
CHANGED