@dotcom-tool-kit/upload-assets-to-s3
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -1,3 +0,3 @@ | ||
import { Command } from '@oclif/command'; | ||
export interface UploadAssetsToS3Options { | ||
import { Command } from '@dotcom-tool-kit/command'; | ||
export declare type UploadAssetsToS3Options = { | ||
accessKeyId: string; | ||
@@ -10,8 +10,8 @@ secretAccessKey: string; | ||
cacheControl: string; | ||
} | ||
}; | ||
export default class UploadAssetsToS3 extends Command { | ||
static description: string; | ||
options: UploadAssetsToS3Options; | ||
run(): Promise<void[]>; | ||
run(): Promise<void>; | ||
} | ||
//# sourceMappingURL=upload-assets-to-s3.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const command_1 = require("@oclif/command"); | ||
const command_1 = require("@dotcom-tool-kit/command"); | ||
const fs = tslib_1.__importStar(require("fs")); | ||
@@ -24,3 +24,3 @@ const aws_sdk_1 = tslib_1.__importDefault(require("aws-sdk")); | ||
async run() { | ||
return uploadAssetsToS3(this.options); | ||
await uploadAssetsToS3(this.options); | ||
} | ||
@@ -59,17 +59,16 @@ } | ||
}; | ||
return new Promise((resolve, reject) => { | ||
return s3.upload(params, (error, data) => { | ||
if (error) { | ||
console.error(`Upload of ${basename} to ${options.bucket} failed`); | ||
reject(error); | ||
} | ||
else { | ||
console.log(`Uploaded ${basename} to ${data.Location}`); | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
try { | ||
const data = await s3.upload(params).promise(); | ||
console.log(`Uploaded ${basename} to ${data.Location}`); | ||
} | ||
catch (error) { | ||
console.error(`Upload of ${basename} to ${options.bucket} failed`); | ||
throw error; | ||
} | ||
}; | ||
async function uploadAssetsToS3(options) { | ||
const files = glob_1.glob.sync(`${options.directory}/**/*{${options.extensions}}`); | ||
// Wrap extensions in braces if there are multiple | ||
const extensions = options.extensions.includes(',') ? `{${options.extensions}}` : options.extensions; | ||
const globFile = `${options.directory}/**/*${extensions}`; | ||
const files = glob_1.glob.sync(globFile); | ||
const s3 = new aws_sdk_1.default.S3({ | ||
@@ -76,0 +75,0 @@ accessKeyId: options.accessKeyId, |
{ | ||
"name": "@dotcom-tool-kit/upload-assets-to-s3", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "", | ||
"main": "lib", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "jest --silent" | ||
}, | ||
@@ -13,3 +13,3 @@ "keywords": [], | ||
"dependencies": { | ||
"@oclif/command": "^1.8.0", | ||
"@dotcom-tool-kit/command": "^0.2.0", | ||
"aws-sdk": "^2.901.0", | ||
@@ -29,4 +29,7 @@ "glob": "^7.1.6", | ||
"@types/glob": "^7.1.3", | ||
"@types/mime": "^2.0.3" | ||
"@types/jest": "^26.0.23", | ||
"@types/mime": "^2.0.3", | ||
"jest": "^26.6.3", | ||
"ts-jest": "^26.5.6" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import { Command } from '@oclif/command' | ||
import { Command } from '@dotcom-tool-kit/command' | ||
import * as fs from 'fs' | ||
@@ -8,3 +8,3 @@ import aws from 'aws-sdk' | ||
export interface UploadAssetsToS3Options { | ||
export type UploadAssetsToS3Options = { | ||
accessKeyId: string | ||
@@ -32,4 +32,4 @@ secretAccessKey: string | ||
async run(): Promise<void[]> { | ||
return uploadAssetsToS3(this.options) | ||
async run(): Promise<void> { | ||
await uploadAssetsToS3(this.options) | ||
} | ||
@@ -73,17 +73,16 @@ } | ||
return new Promise<void>((resolve, reject) => { | ||
return s3.upload(params, (error: Error, data: { Location: string }) => { | ||
if (error) { | ||
console.error(`Upload of ${basename} to ${options.bucket} failed`) | ||
reject(error) | ||
} else { | ||
console.log(`Uploaded ${basename} to ${data.Location}`) | ||
resolve() | ||
} | ||
}) | ||
}) | ||
try { | ||
const data = await s3.upload(params).promise() | ||
console.log(`Uploaded ${basename} to ${data.Location}`) | ||
} catch (error) { | ||
console.error(`Upload of ${basename} to ${options.bucket} failed`) | ||
throw error | ||
} | ||
} | ||
async function uploadAssetsToS3(options: UploadAssetsToS3Options) { | ||
const files = glob.sync(`${options.directory}/**/*{${options.extensions}}`) | ||
// Wrap extensions in braces if there are multiple | ||
const extensions = options.extensions.includes(',') ? `{${options.extensions}}` : options.extensions | ||
const globFile = `${options.directory}/**/*${extensions}` | ||
const files = glob.sync(globFile) | ||
@@ -90,0 +89,0 @@ const s3 = new aws.S3({ |
{ | ||
"extends": "../../tsconfig.settings.json", | ||
"include": ["src/**/*"], | ||
"compilerOptions": { | ||
"outDir": "lib", | ||
"rootDir": "src" | ||
} | ||
}, | ||
"references": [ | ||
{ | ||
"path": "../command" | ||
} | ||
] | ||
} |
Sorry, the diff of this file is not supported yet
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
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 tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
73949
19
252
2
6
1
+ Added@dotcom-tool-kit/command@0.2.17(transitive)
- Removed@oclif/command@^1.8.0
- Removed@nodelib/fs.scandir@2.1.5(transitive)
- Removed@nodelib/fs.stat@2.0.5(transitive)
- Removed@nodelib/fs.walk@1.2.8(transitive)
- Removed@oclif/command@1.8.36(transitive)
- Removed@oclif/config@1.18.161.18.17(transitive)
- Removed@oclif/errors@1.3.6(transitive)
- Removed@oclif/help@1.0.15(transitive)
- Removed@oclif/linewrap@1.0.0(transitive)
- Removed@oclif/parser@3.8.17(transitive)
- Removedansi-regex@5.0.1(transitive)
- Removedansi-styles@4.3.0(transitive)
- Removedarray-union@2.1.0(transitive)
- Removedbraces@3.0.3(transitive)
- Removedchalk@4.1.2(transitive)
- Removedclean-stack@3.0.1(transitive)
- Removedcolor-convert@2.0.1(transitive)
- Removedcolor-name@1.1.4(transitive)
- Removeddebug@4.4.0(transitive)
- Removeddir-glob@3.0.1(transitive)
- Removedemoji-regex@8.0.0(transitive)
- Removedescape-string-regexp@4.0.0(transitive)
- Removedfast-glob@3.3.2(transitive)
- Removedfastq@1.18.0(transitive)
- Removedfill-range@7.1.1(transitive)
- Removedfs-extra@8.1.0(transitive)
- Removedglob-parent@5.1.2(transitive)
- Removedglobby@11.1.0(transitive)
- Removedgraceful-fs@4.2.11(transitive)
- Removedhas-flag@4.0.0(transitive)
- Removedignore@5.3.2(transitive)
- Removedindent-string@4.0.0(transitive)
- Removedis-docker@2.2.1(transitive)
- Removedis-extglob@2.1.1(transitive)
- Removedis-fullwidth-code-point@3.0.0(transitive)
- Removedis-glob@4.0.3(transitive)
- Removedis-number@7.0.0(transitive)
- Removedis-wsl@2.2.0(transitive)
- Removedjsonfile@4.0.0(transitive)
- Removedlodash@4.17.21(transitive)
- Removedmerge2@1.4.1(transitive)
- Removedmicromatch@4.0.8(transitive)
- Removedms@2.1.3(transitive)
- Removedpath-type@4.0.0(transitive)
- Removedpicomatch@2.3.1(transitive)
- Removedqueue-microtask@1.2.3(transitive)
- Removedreusify@1.0.4(transitive)
- Removedrun-parallel@1.2.0(transitive)
- Removedsemver@7.6.3(transitive)
- Removedslash@3.0.0(transitive)
- Removedstring-width@4.2.3(transitive)
- Removedstrip-ansi@6.0.1(transitive)
- Removedsupports-color@7.2.0(transitive)
- Removedto-regex-range@5.0.1(transitive)
- Removedtslib@2.8.1(transitive)
- Removeduniversalify@0.1.2(transitive)
- Removedwidest-line@3.1.0(transitive)
- Removedwrap-ansi@6.2.07.0.0(transitive)