@flownet/lib-upload-files-to-gcs
Advanced tools
Comparing version 0.3.2 to 0.3.3
@@ -51,71 +51,71 @@ #!/usr/bin/env node | ||
var Node = async ({ | ||
projectId, | ||
keyFilename, | ||
bucketName, | ||
dir, | ||
pattern, | ||
destDir = "/", | ||
dryRun = false, | ||
metadata = {}, | ||
domain, | ||
verbose = false | ||
projectId, | ||
keyFilename, | ||
bucketName, | ||
dir, | ||
pattern, | ||
destDir = "/", | ||
dryRun = false, | ||
metadata = {}, | ||
domain, | ||
verbose = false | ||
}) => { | ||
if (!projectId) throw new Error('projectId is required.'); | ||
if (!projectId) throw new Error('projectId is required.'); | ||
if (!keyFilename) throw new Error('keyFilename is required.'); | ||
if (!keyFilename) throw new Error('keyFilename is required.'); | ||
if (!bucketName) throw new Error('bucketName is required.'); | ||
if (!bucketName) throw new Error('bucketName is required.'); | ||
if (!pattern) throw new Error('pattern is required.'); | ||
const storage = new Storage({ | ||
projectId, | ||
keyFilename | ||
}); | ||
if (!pattern) throw new Error('pattern is required.'); | ||
const bucket = storage.bucket(bucketName); | ||
const storage = new Storage({ | ||
projectId, | ||
keyFilename | ||
}); | ||
// source files | ||
dir = dir || process.cwd(); | ||
const bucket = storage.bucket(bucketName); | ||
const files = await listFiles({ pattern, dir, nodir: true }); | ||
// source files | ||
dir = dir || process.cwd(); | ||
destDir = destDir || "/"; | ||
const files = await listFiles({ pattern, dir, nodir: true }); | ||
const uploadedFiles = []; | ||
destDir = destDir || "/"; | ||
for await (const file of files) { | ||
const uploadedFiles = []; | ||
const srcFile = path.resolve(dir, file); | ||
const destFile = path.join(destDir, file); | ||
for await (const file of files) { | ||
let defaultUrl = `https://${bucketName}.storage.googleapis.com/${destFile}`; | ||
if (domain) defaultUrl = `https://${domain}/${destFile}`; | ||
const srcFile = path.resolve(dir, file); | ||
const destFile = path.join(destDir, file); | ||
const uploadedFile = { from: srcFile, to: destFile, url: defaultUrl }; | ||
uploadedFiles.push(uploadedFile); | ||
let defaultUrl = `https://${bucketName}.storage.googleapis.com/${destFile}`; | ||
if (domain) defaultUrl = `https://${domain}/${destFile}`; | ||
const metadataFinal = { | ||
"surrogate-key": "gcs", | ||
contentType: mime.contentType(path.extname(file)) || 'application/octet-stream', | ||
...metadata | ||
}; | ||
const uploadedFile = { from: srcFile, to: destFile, url: defaultUrl }; | ||
uploadedFiles.push(uploadedFile); | ||
dryRun = dryRun === true; | ||
const metadataFinal = { | ||
"surrogate-key": "gcs", | ||
contentType: mime.contentType(path.extname(file)) || 'application/octet-stream', | ||
...metadata | ||
}; | ||
if (!dryRun) { | ||
await bucket.upload(srcFile, { | ||
destination: destFile, | ||
gzip: true, | ||
metadata:metadataFinal, | ||
}); | ||
} | ||
dryRun = (dryRun === true); | ||
if (verbose) console.log(uploadedFile); | ||
if (!dryRun) { | ||
await bucket.upload(srcFile, { | ||
destination: destFile, | ||
gzip: true, | ||
metadata: metadataFinal, | ||
}); | ||
} | ||
return { | ||
files: uploadedFiles | ||
}; | ||
if (verbose) console.log(uploadedFile); | ||
} | ||
return { | ||
files: uploadedFiles | ||
}; | ||
}; | ||
@@ -128,3 +128,7 @@ | ||
.then((result) => { | ||
if (typeof result !== "undefined") console.log(result); | ||
if (typeof result !== "undefined") { | ||
if (argv.stdout_format === "json") | ||
console.log(JSON.stringify(result, null, 2)); | ||
else console.log(result); | ||
} | ||
process.exit(0); | ||
@@ -131,0 +135,0 @@ }) |
@@ -7,73 +7,73 @@ import { Storage } from '@google-cloud/storage'; | ||
var index = async ({ | ||
projectId, | ||
keyFilename, | ||
bucketName, | ||
dir, | ||
pattern, | ||
destDir = "/", | ||
dryRun = false, | ||
metadata = {}, | ||
domain, | ||
verbose = false | ||
projectId, | ||
keyFilename, | ||
bucketName, | ||
dir, | ||
pattern, | ||
destDir = "/", | ||
dryRun = false, | ||
metadata = {}, | ||
domain, | ||
verbose = false | ||
}) => { | ||
if (!projectId) throw new Error('projectId is required.'); | ||
if (!projectId) throw new Error('projectId is required.'); | ||
if (!keyFilename) throw new Error('keyFilename is required.'); | ||
if (!keyFilename) throw new Error('keyFilename is required.'); | ||
if (!bucketName) throw new Error('bucketName is required.'); | ||
if (!bucketName) throw new Error('bucketName is required.'); | ||
if (!pattern) throw new Error('pattern is required.'); | ||
const storage = new Storage({ | ||
projectId, | ||
keyFilename | ||
}); | ||
if (!pattern) throw new Error('pattern is required.'); | ||
const bucket = storage.bucket(bucketName); | ||
const storage = new Storage({ | ||
projectId, | ||
keyFilename | ||
}); | ||
// source files | ||
dir = dir || process.cwd(); | ||
const bucket = storage.bucket(bucketName); | ||
const files = await listFiles({ pattern, dir, nodir: true }); | ||
// source files | ||
dir = dir || process.cwd(); | ||
destDir = destDir || "/"; | ||
const files = await listFiles({ pattern, dir, nodir: true }); | ||
const uploadedFiles = []; | ||
destDir = destDir || "/"; | ||
for await (const file of files) { | ||
const uploadedFiles = []; | ||
const srcFile = path.resolve(dir, file); | ||
const destFile = path.join(destDir, file); | ||
for await (const file of files) { | ||
let defaultUrl = `https://${bucketName}.storage.googleapis.com/${destFile}`; | ||
if (domain) defaultUrl = `https://${domain}/${destFile}`; | ||
const srcFile = path.resolve(dir, file); | ||
const destFile = path.join(destDir, file); | ||
const uploadedFile = { from: srcFile, to: destFile, url: defaultUrl }; | ||
uploadedFiles.push(uploadedFile); | ||
let defaultUrl = `https://${bucketName}.storage.googleapis.com/${destFile}`; | ||
if (domain) defaultUrl = `https://${domain}/${destFile}`; | ||
const metadataFinal = { | ||
"surrogate-key": "gcs", | ||
contentType: mime.contentType(path.extname(file)) || 'application/octet-stream', | ||
...metadata | ||
}; | ||
const uploadedFile = { from: srcFile, to: destFile, url: defaultUrl }; | ||
uploadedFiles.push(uploadedFile); | ||
dryRun = dryRun === true; | ||
const metadataFinal = { | ||
"surrogate-key": "gcs", | ||
contentType: mime.contentType(path.extname(file)) || 'application/octet-stream', | ||
...metadata | ||
}; | ||
if (!dryRun) { | ||
await bucket.upload(srcFile, { | ||
destination: destFile, | ||
gzip: true, | ||
metadata:metadataFinal, | ||
}); | ||
} | ||
dryRun = (dryRun === true); | ||
if (verbose) console.log(uploadedFile); | ||
if (!dryRun) { | ||
await bucket.upload(srcFile, { | ||
destination: destFile, | ||
gzip: true, | ||
metadata: metadataFinal, | ||
}); | ||
} | ||
return { | ||
files: uploadedFiles | ||
}; | ||
if (verbose) console.log(uploadedFile); | ||
} | ||
return { | ||
files: uploadedFiles | ||
}; | ||
}; | ||
export { index as default }; |
{ | ||
"name": "@flownet/lib-upload-files-to-gcs", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"files": [ | ||
@@ -16,2 +16,6 @@ "dist/*" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://gitlab.com/fnetai/files-to-gcs.git" | ||
}, | ||
"license": "MIT", | ||
@@ -21,3 +25,2 @@ "dependencies": { | ||
"@google-cloud/storage": "^7.7", | ||
"chalk": "^4", | ||
"mime-types": "^2.1", | ||
@@ -28,3 +31,3 @@ "yargs": "^17" | ||
"fnet-upload-files-to-gcs": "dist/cli/esm/index.js", | ||
"lib-upload-files-to-gcs": "dist/cli/esm/index.js" | ||
"files-to-gcs": "dist/cli/esm/index.js" | ||
}, | ||
@@ -31,0 +34,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
10651
4
7
248
1
17
0
- Removedchalk@^4
- Removedchalk@4.1.2(transitive)
- Removedhas-flag@4.0.0(transitive)
- Removedsupports-color@7.2.0(transitive)