@cocreate/file 1.6.2 → 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 +14 -0
- package/package.json +1 -1
- package/src/server.js +53 -22
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
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
|
+
|
|
8
|
+
## [1.6.3](https://github.com/CoCreate-app/CoCreate-file/compare/v1.6.2...v1.6.3) (2023-08-21)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* remove unused console.log ([610fc0b](https://github.com/CoCreate-app/CoCreate-file/commit/610fc0b99c344a954b776a610c514c56ec034e1f))
|
|
14
|
+
|
|
1
15
|
## [1.6.2](https://github.com/CoCreate-app/CoCreate-file/compare/v1.6.1...v1.6.2) (2023-08-21)
|
|
2
16
|
|
|
3
17
|
|
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)
|
|
@@ -376,8 +407,6 @@ module.exports = async function file(CoCreateConfig, configPath) {
|
|
|
376
407
|
|
|
377
408
|
async function runStore(data) {
|
|
378
409
|
try {
|
|
379
|
-
if (data.object.name === 'prism-chunk.js')
|
|
380
|
-
console.log('prism-chunk.js')
|
|
381
410
|
let response;
|
|
382
411
|
if (!data.object._id && !data.filter) {
|
|
383
412
|
response = await crud.send({
|
|
@@ -406,10 +435,10 @@ module.exports = async function file(CoCreateConfig, configPath) {
|
|
|
406
435
|
if (directories)
|
|
407
436
|
await runDirectories()
|
|
408
437
|
|
|
409
|
-
if (sources) {
|
|
438
|
+
if (sources && sources.length) {
|
|
410
439
|
let sources = await runSources()
|
|
411
440
|
let newConfig = { ...CoCreateConfig }
|
|
412
|
-
if (directories)
|
|
441
|
+
if (directories && directories.length)
|
|
413
442
|
newConfig.directories = directories
|
|
414
443
|
|
|
415
444
|
newConfig.sources = sources
|
|
@@ -429,11 +458,13 @@ module.exports = async function file(CoCreateConfig, configPath) {
|
|
|
429
458
|
fs.writeFileSync(configPath, `module.exports = ${JSON.stringify(newConfig, null, 4)};`);
|
|
430
459
|
}
|
|
431
460
|
|
|
432
|
-
|
|
461
|
+
if (!match.length) {
|
|
462
|
+
console.log('upload complete!');
|
|
433
463
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
464
|
+
setTimeout(function () {
|
|
465
|
+
process.exit()
|
|
466
|
+
}, 2000)
|
|
467
|
+
}
|
|
437
468
|
}
|
|
438
469
|
|
|
439
470
|
run()
|