-
Notifications
You must be signed in to change notification settings - Fork 0
Implement new library to retrieve static assets URL #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
71b9a64
initial commit
philippemiguet 0b68c2f
Add travis file
philippemiguet 46b87d5
Add empty readme
philippemiguet a7828b8
Add Travis status to README
philippemiguet 959121e
Add .md extension
philippemiguet b85f307
Update name of npm package
philippemiguet 0ad9728
Simplify lib usage
philippemiguet 236641b
Add synchronous version of function
djfarrelly 5406207
Version bump
djfarrelly 81e96a2
Use console.warn() instead of console.warning()
ssvmvss a5a7771
Version bump
ssvmvss d029ead
Update readme
philippemiguet b48e1d4
Promote to stable version
philippemiguet f7fd71e
Add test for initializeStaticAssetsManagerSync
philippemiguet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "airbnb", | ||
"env": { | ||
"jest": true | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
coverage | ||
lib |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
language: node_js | ||
node_js: | ||
- "8" | ||
notifications: | ||
email: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# buffer-js-static-assets | ||
|
||
[](https://travis-ci.org/bufferapp/buffer-js-static-assets) | ||
|
||
## Installation | ||
|
||
Install the package | ||
|
||
``` | ||
npm install @bufferapp/static-assets | ||
``` | ||
|
||
## Usage | ||
|
||
To utilize the `staticUrl` function, you'll need to first initialize the | ||
static assets manager: | ||
|
||
```js | ||
const { initStaticAssets } = require('@bufferapp/static-assets') | ||
|
||
initStaticAssets() | ||
.then(() => { | ||
// Now that we have loaded the static assets we can serve requests | ||
app.listen(8080, () => console.log('Server started!')) | ||
}) | ||
``` | ||
|
||
Alternatively, you can call the `initStaticAssetsSync` function to perform | ||
a synchronous load of the static assets file which is blocking: | ||
|
||
```js | ||
initStaticAssetsSync() | ||
app.listen(8080, () => console.log('Server started!')) | ||
``` | ||
|
||
Once the library is initialized, using the exported `staticUrl` function: | ||
|
||
```js | ||
const { staticUrl } = require('@bufferapp/static-assets') | ||
|
||
app.get('/sweet', (req, res) => { | ||
res.render('sweet-template', { | ||
headerImage: staticUrl('img/sweet-header4.png'), | ||
script: staticUrl('js/sweet-bundle.js'), | ||
}) | ||
}) | ||
``` | ||
|
||
### Options | ||
|
||
We have a few configuration options that can be passed to `initStaticAssets` in | ||
a single object argument (ex. `initStaticAssets({ path: '/static' })`): | ||
|
||
* `staticAssetVersionsFilename` - The name of the static asset manifest file. | ||
* `staticAssetDirLocal` - The relative path where static assets are served during local dev. Usually via express-static. | ||
* `staticAssetDirCDN` - This is the directory relative to your working directory where your static assets are saved. This is used to look up static files in the manifest (See manifest section below). | ||
|
||
### Static Asset Manifest | ||
|
||
The format of the static asset manifest should be the same as default JSON | ||
format that [`buffer-static-upload`](https://github.com/bufferapp/buffer-static-upload) | ||
outputs. | ||
|
||
This format is a key-value pair of: | ||
|
||
```json | ||
"relative path to local file from working directory": "remote URL for that file" | ||
``` | ||
|
||
Here's an example: | ||
|
||
```json | ||
{ | ||
"public/css/style.css": "https://static.buffer.com/my-app/public/css/style.1234567890.css", | ||
"public/img/brand.png": "https://static.buffer.com/my-app/public/img/brand.png" | ||
} | ||
``` | ||
|
||
## License | ||
|
||
MIT |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want "stable" or 10 also since that's the current version in development, not important, but it crossed my mind when I saw this :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@djfarrelly shall we use then
node
orlts/*
instead of8
? https://docs.travis-ci.com/user/languages/javascript-with-nodejs/#specifying-nodejs-versionsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@philippemiguet I think just
lts/*
should work which is now node 10 and we should be using only LTS releases for our production services 😄 . If this ends up using language features that only exist in node 10 and we need to polyfill for node 8 or below we can add8
. I think this repo should use pretty standard/stable language features so running the tests against 10 😄