Skip to content

Commit

Permalink
New target-dir option (#7)
Browse files Browse the repository at this point in the history
* target dir option

* update deps

* readme

* fix readme

* fix readme again
  • Loading branch information
nulldef authored Sep 29, 2021
1 parent ea8070a commit cafca2f
Show file tree
Hide file tree
Showing 6 changed files with 811 additions and 809 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ All following options except `config` and `config-key` can be configured using t
Available AWS regions can be viewed at https://docs.aws.amazon.com/sns/latest/dg/sns-supported-regions-countries.html.

```
--config, -c path to config file [default: "./ucdn.yml"]
--config-key, -C root config key [default: null]
--region, -r AWS geographical area [default: "eu-west-1"]
--dir, -d assets directory [default: "dist/"]
--bucket, -b AWS bucket for upload [required]
--exclude, -e excluded extenstions [default: ["html","gz"]]
--accessKeyId, --access-key-id AWS access key ID [required]
--secretAccessKey, --secret-access-key AWS secret access key [required]
--config, -c path to config file [default: "./ucdn.yml"]
--config-key, -C root config key [default: null]
--region, -r AWS geographical area [default: "eu-west-1"]
--dir, -d assets directory [default: "dist/"]
--bucket, -b AWS bucket for upload [required]
--exclude, -e excluded extenstions [default: ["html","gz"]]
--accessKeyId, --access-key-id AWS access key ID [required]
--secretAccessKey, --secret-access-key AWS secret access key [required]
--targetDir, --target-dir AWS bucket target directory [default: "/"]
```

## Contributing
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@umbrellio/ucdn",
"version": "0.4.2",
"version": "0.5.0",
"bin": "ucdn",
"main": "index.js",
"repository": "[email protected]:umbrellio/ucdn.git",
Expand All @@ -11,16 +11,16 @@
"lint": "eslint . ucdn"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.19.0",
"js-yaml": "^3.14.0",
"mime-types": "^2.1.27",
"yargs": "^15.3.1"
"@aws-sdk/client-s3": "^3.34.0",
"js-yaml": "^4.1.0",
"mime-types": "^2.1.32",
"yargs": "^17.2.1"
},
"devDependencies": {
"babel-eslint": "^10.1.0",
"eslint": "^7.3.0",
"eslint": "^7.32.0",
"eslint-config-umbrellio": "^5.0.1",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-import": "^2.24.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prefer-object-spread": "^1.2.1",
"eslint-plugin-promise": "^5.1.0"
Expand Down
8 changes: 7 additions & 1 deletion ucdn
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@ const yargsOptions = {
"config-key": {
alias: "C",
describe: "root config key",
}
},
targetDir: {
alias: "target-dir",
describe: "AWS bucket target directory",
type: "string",
default: "/",
},
}

yargs
Expand Down
10 changes: 7 additions & 3 deletions upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const configDefaults = {
exclude: [],
accessKeyId: null,
secretAccessKey: null,
targetDir: null,
}

const getConfig = passedConfig => {
Expand All @@ -27,7 +28,10 @@ const findFiles = directory => {
}, [])
}

const getKey = (file, root) => path.relative(root, file)
const getKey = (file, root, targetDir) => {
const filepath = path.relative(root, file)
return path.join(targetDir, filepath)
}

const uploadFile = (s3, config, file, key) => {
return fs.promises.readFile(file).then(data => {
Expand All @@ -41,7 +45,7 @@ const uploadFile = (s3, config, file, key) => {

const upload = argv => {
const config = getConfig(argv)
const { region, accessKeyId, secretAccessKey, dir, exclude } = config
const { region, accessKeyId, secretAccessKey, dir, exclude, targetDir } = config

const s3 = new S3Client({
region,
Expand All @@ -58,7 +62,7 @@ const upload = argv => {
})

const promises = files.map(file => {
const key = getKey(file, directory)
const key = getKey(file, directory, targetDir)
return uploadFile(s3, config, file, key)
.then(() => console.log("Uploaded", file))
})
Expand Down
2 changes: 1 addition & 1 deletion utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const toDashCase = str => str.replace(/([A-Z])/g, g => `-${g[0].toLowerCase()}`)
const loadYamlFile = filePath => {
const configPath = path.resolve(filePath)
const content = fs.readFileSync(configPath)
return yaml.safeLoad(content)
return yaml.load(content)
}

module.exports = {
Expand Down
Loading

0 comments on commit cafca2f

Please sign in to comment.