@cocreate/file 1.6.3 → 1.7.0
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/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/server.js +53 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [1.7.0](https://github.com/CoCreate-app/CoCreate-file/compare/v1.6.3...v1.7.0) (2023-09-07)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* support match param. An array of files to match with config. if match found upload or save source ([30e6d57](https://github.com/CoCreate-app/CoCreate-file/commit/30e6d57da184f9533a0b75e8acc3a09e68b48629))
|
|
7
|
+
|
|
1
8
|
## [1.6.3](https://github.com/CoCreate-app/CoCreate-file/compare/v1.6.2...v1.6.3) (2023-08-21)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
package/src/server.js
CHANGED
|
@@ -77,9 +77,15 @@ const mimeTypes = {
|
|
|
77
77
|
".7z": "application/x-7z-compressed"
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
module.exports = async function file(CoCreateConfig, configPath) {
|
|
80
|
+
module.exports = async function file(CoCreateConfig, configPath, match) {
|
|
81
81
|
let directories = CoCreateConfig.directories
|
|
82
82
|
let sources = CoCreateConfig.sources
|
|
83
|
+
let configDirectoryPath = path.dirname(configPath)
|
|
84
|
+
|
|
85
|
+
if (match && !Array.isArray(match))
|
|
86
|
+
match = [match]
|
|
87
|
+
else if (!match)
|
|
88
|
+
match = []
|
|
83
89
|
|
|
84
90
|
let config = await Config({
|
|
85
91
|
organization_id: {
|
|
@@ -143,7 +149,7 @@ module.exports = async function file(CoCreateConfig, configPath) {
|
|
|
143
149
|
|
|
144
150
|
}
|
|
145
151
|
|
|
146
|
-
console.log('Uploading files...')
|
|
152
|
+
// console.log('Uploading files...')
|
|
147
153
|
|
|
148
154
|
/**
|
|
149
155
|
* Store files by config directories
|
|
@@ -153,14 +159,15 @@ module.exports = async function file(CoCreateConfig, configPath) {
|
|
|
153
159
|
async function runDirectories() {
|
|
154
160
|
for (const directory of directories) {
|
|
155
161
|
const entry = directory.entry
|
|
156
|
-
const exclude = directory.exclude
|
|
162
|
+
const exclude = directory.exclude || []
|
|
157
163
|
await runFiles(directory, entry, exclude)
|
|
158
164
|
}
|
|
159
165
|
return
|
|
160
166
|
}
|
|
161
167
|
|
|
162
168
|
async function runFiles(directory, entry, exclude, parentDirectory = '') {
|
|
163
|
-
|
|
169
|
+
const entryPath = path.resolve(configDirectoryPath, entry)
|
|
170
|
+
let files = fs.readdirSync(entryPath);
|
|
164
171
|
|
|
165
172
|
for (let file of files) {
|
|
166
173
|
let skip = false
|
|
@@ -172,8 +179,19 @@ module.exports = async function file(CoCreateConfig, configPath) {
|
|
|
172
179
|
}
|
|
173
180
|
if (skip) continue
|
|
174
181
|
|
|
182
|
+
for (let i = 0; i < match.length; i++) {
|
|
183
|
+
skip = true
|
|
184
|
+
const filePath = path.resolve(entryPath, file);
|
|
185
|
+
if (filePath.startsWith(match[i])) {
|
|
186
|
+
skip = false
|
|
187
|
+
console.log('Uploaded: ', filePath)
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
175
191
|
|
|
176
|
-
|
|
192
|
+
if (skip) continue
|
|
193
|
+
|
|
194
|
+
let isDirectory = fs.existsSync(`${entryPath}/${file}`) && fs.lstatSync(`${entryPath}/${file}`).isDirectory();
|
|
177
195
|
let name = file
|
|
178
196
|
let source = ''
|
|
179
197
|
let directoryName = parentDirectory || '';
|
|
@@ -203,7 +221,7 @@ module.exports = async function file(CoCreateConfig, configPath) {
|
|
|
203
221
|
if (isDirectory)
|
|
204
222
|
mimeType = "text/directory"
|
|
205
223
|
else
|
|
206
|
-
source = getSource(`${
|
|
224
|
+
source = getSource(`${entryPath}/${file}`, mimeType)
|
|
207
225
|
|
|
208
226
|
let values = {
|
|
209
227
|
'{{name}}': name,
|
|
@@ -304,6 +322,7 @@ module.exports = async function file(CoCreateConfig, configPath) {
|
|
|
304
322
|
let source = { ...sources[i] };
|
|
305
323
|
let keys = new Map()
|
|
306
324
|
let response = {};
|
|
325
|
+
let isMatch = false
|
|
307
326
|
|
|
308
327
|
try {
|
|
309
328
|
if (array) {
|
|
@@ -316,7 +335,8 @@ module.exports = async function file(CoCreateConfig, configPath) {
|
|
|
316
335
|
|
|
317
336
|
let variables = object[key].match(/{{([A-Za-z0-9_.,\[\]\-\/ ]*)}}/g);
|
|
318
337
|
if (variables) {
|
|
319
|
-
|
|
338
|
+
let originalValue = object[key]
|
|
339
|
+
keys.set(key, originalValue)
|
|
320
340
|
let value = ""
|
|
321
341
|
for (let variable of variables) {
|
|
322
342
|
let entry = /{{\s*([\w\W]+)\s*}}/g.exec(variable);
|
|
@@ -325,6 +345,17 @@ module.exports = async function file(CoCreateConfig, configPath) {
|
|
|
325
345
|
if (!fs.existsSync(entry))
|
|
326
346
|
continue
|
|
327
347
|
|
|
348
|
+
if (!isMatch) {
|
|
349
|
+
const filePath = path.resolve(configDirectoryPath, entry);
|
|
350
|
+
for (let i = 0; i < match.length; i++) {
|
|
351
|
+
if (filePath.startsWith(match[i])) {
|
|
352
|
+
console.log('Source saved', sources[i])
|
|
353
|
+
isMatch = true
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
328
359
|
let read_type = 'utf8'
|
|
329
360
|
const fileExtension = path.extname(entry);
|
|
330
361
|
let mime_type = mimeTypes[fileExtension] || 'text/html'
|
|
@@ -351,20 +382,20 @@ module.exports = async function file(CoCreateConfig, configPath) {
|
|
|
351
382
|
query: [{ key: 'path', value: object.path, operator: '$eq' }]
|
|
352
383
|
}
|
|
353
384
|
|
|
354
|
-
|
|
385
|
+
if (match.length && isMatch)
|
|
386
|
+
response = await runStore(data);
|
|
355
387
|
}
|
|
356
388
|
} catch (err) {
|
|
357
389
|
console.log(err)
|
|
358
390
|
process.exit()
|
|
359
391
|
}
|
|
392
|
+
|
|
360
393
|
if (response.object && response.object[0] && response.object[0]._id) {
|
|
361
|
-
for (const [key, value] of keys) {
|
|
362
|
-
source.object[key] = value
|
|
363
|
-
}
|
|
364
394
|
source.object._id = response.object[0]._id
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
for (const [key, value] of keys) {
|
|
398
|
+
source.object[key] = value
|
|
368
399
|
}
|
|
369
400
|
|
|
370
401
|
updatedSources.push(source)
|
|
@@ -404,10 +435,10 @@ module.exports = async function file(CoCreateConfig, configPath) {
|
|
|
404
435
|
if (directories)
|
|
405
436
|
await runDirectories()
|
|
406
437
|
|
|
407
|
-
if (sources) {
|
|
438
|
+
if (sources && sources.length) {
|
|
408
439
|
let sources = await runSources()
|
|
409
440
|
let newConfig = { ...CoCreateConfig }
|
|
410
|
-
if (directories)
|
|
441
|
+
if (directories && directories.length)
|
|
411
442
|
newConfig.directories = directories
|
|
412
443
|
|
|
413
444
|
newConfig.sources = sources
|
|
@@ -427,11 +458,13 @@ module.exports = async function file(CoCreateConfig, configPath) {
|
|
|
427
458
|
fs.writeFileSync(configPath, `module.exports = ${JSON.stringify(newConfig, null, 4)};`);
|
|
428
459
|
}
|
|
429
460
|
|
|
430
|
-
|
|
461
|
+
if (!match.length) {
|
|
462
|
+
console.log('upload complete!');
|
|
431
463
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
464
|
+
setTimeout(function () {
|
|
465
|
+
process.exit()
|
|
466
|
+
}, 2000)
|
|
467
|
+
}
|
|
435
468
|
}
|
|
436
469
|
|
|
437
470
|
run()
|