@dynamicweb/cli 1.0.5 → 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 -28
- 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
|
|
|
@@ -265,10 +245,12 @@ async function getFilesStructure(env, user, dirPath, recursive, includeFiles) {
|
|
|
265
245
|
}
|
|
266
246
|
}
|
|
267
247
|
|
|
268
|
-
export async function uploadFiles(env, user, localFilePaths, destinationPath, createEmpty = false) {
|
|
248
|
+
export async function uploadFiles(env, user, localFilePaths, destinationPath, createEmpty = false, overwrite = false) {
|
|
269
249
|
console.log('Uploading files')
|
|
270
250
|
let form = new FormData();
|
|
271
251
|
form.append('path', destinationPath);
|
|
252
|
+
form.append('skipExistingFiles', String(!overwrite));
|
|
253
|
+
form.append('allowOverwrite', String(overwrite));
|
|
272
254
|
localFilePaths.forEach((localPath, index) => {
|
|
273
255
|
console.log(localPath)
|
|
274
256
|
form.append('files', fs.createReadStream(path.resolve(localPath)));
|
|
@@ -282,7 +264,7 @@ export async function uploadFiles(env, user, localFilePaths, destinationPath, cr
|
|
|
282
264
|
agent: getAgent(env.protocol)
|
|
283
265
|
});
|
|
284
266
|
if (res.ok) {
|
|
285
|
-
|
|
267
|
+
console.log(await res.json())
|
|
286
268
|
console.log(`Files uploaded`)
|
|
287
269
|
}
|
|
288
270
|
else {
|
package/package.json
CHANGED