Skip to content

Commit

Permalink
closes #129, closes okwolo/website#6
Browse files Browse the repository at this point in the history
  • Loading branch information
g-harel committed Jan 22, 2018
1 parent 2eebf8f commit 882ba5b
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules/
_*.html
coverage/
package-lock.json
secret.json
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<a href="https://www.npmjs.com/package/okwolo"><img src="https://img.shields.io/npm/v/okwolo.svg" alt="NPM version" /></a>
<a href="https://travis-ci.org/okwolo/okwolo"><img src="https://travis-ci.org/okwolo/okwolo.svg?branch=master" alt="Build Status" /></a>
<a href="https://codecov.io/gh/okwolo/okwolo"><img src="https://img.shields.io/codecov/c/github/okwolo/okwolo.svg" alt="Codecov" /></a>
<a href="https://github.com/okwolo/okwolo/blob/master/dist/standard.min.js.gz"><img src="https://img.shields.io/github/size/okwolo/okwolo/dist/standard.min.js.gz.svg" alt="gzipped size" /></a>
<a href="https://github.com/okwolo/okwolo/blob/master/dist/standard.min.js.gz"><img src="https://img.shields.io/github/size/okwolo/okwolo/dist/standard.min.js.gz.svg" alt="GZIP size" /></a>
</p>

---
Expand All @@ -34,10 +34,13 @@ npm install okwolo
const okwolo = require('okwolo/standard');
```

Alternatively, the okwolo function can be loaded using a script tag. It will automatically attach itself to the global window object. All three kits are available transpiled to es5 and minified in the `dist` folder.
Alternatively, the okwolo function can be loaded using a script tag. Transpiled versions of all kits are available from the website.

```html
<script src="/dist/standard.min.js"></script>
<!-- latest -->
<script src="https://dl.okwolo.org/standard.js"></script>
<!-- specific version -->
<script src="https://dl.okwolo.org/3.0.0/lite.min.js"></script>
```

Create your first app.
Expand Down Expand Up @@ -70,4 +73,4 @@ All changes are logged in the [changelog](https://github.com/okwolo/okwolo/blob/

## License

[MIT](https://github.com/okwolo/okwolo/blob/master/LICENSE)
[MIT](https://github.com/okwolo/okwolo/blob/master/LICENSE)
67 changes: 67 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
'use strict';

const AWS = require('aws-sdk');
const del = require('del');
const fs = require('fs');
const globby = require('globby');
const gulp = require('gulp');
const replace = require('gulp-replace');

const {version} = require('./package.json');

const kitPattern = './src/kits/*.js';

// copy ./src/kits/ to ./
Expand All @@ -30,3 +34,66 @@ gulp.task('clean', () => {
'./package-lock.json',
]);
});

// upload new published version to website
gulp.task('publish', async () => {
if (!fs.existsSync('secret.json')) {
console.error('couldn\'t read config file (secret.json)');
return;
}

AWS.config.loadFromPath('secret.json');

const s3 = new AWS.S3({
apiVersion: '2018-1-1',
params: {
Bucket: 'aws-dl-okwolo-cr5ts',
},
});

const kitNames = globby.sync([kitPattern])
.map((path) => path.replace(/.+?(\w+)\.js$/g, '$1'));

const files = [];
kitNames.forEach((kit) => {
const bundle = fs.readFileSync(`./dist/${kit}.js`, 'utf8');
const bundleMin = fs.readFileSync(`./dist/${kit}.min.js`, 'utf8');

files.push({
content: bundle,
path: `${kit}.js`,
});
files.push({
content: bundleMin,
path: `${kit}.min.js`,
});

files.push({
content: bundle,
path: `${version}/${kit}.js`,
});
files.push({
content: bundleMin,
path: `${version}/${kit}.min.js`,
});
});

return Promise.all(files.map(({content, path}) => {
return new Promise((resolve, reject) => {
s3.upload({
Key: path,
Body: content,
ContentEncoding: 'utf8',
ContentType: 'application/javascript',
ACL: 'public-read',
}, (err, data) => {
if (err) {
console.error(`error uploading ${path}`);
reject(err);
}
console.log(`uploaded ${path}`);
resolve(data);
});
});
}));
});
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"license": "MIT",
"scripts": {
"prepack": "webpack && gulp prepublish",
"postpublish": "gulp clean",
"postpublish": "gulp clean && gulp publish",
"test": "run-s test:*",
"test:eslint": "eslint **/*.js",
"test:jest": "jest",
Expand All @@ -38,6 +38,7 @@
"path-to-regexp": "^2.1.0"
},
"devDependencies": {
"aws-sdk": "^2.185.0",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.1",
Expand Down
5 changes: 5 additions & 0 deletions secret.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"region": "AWS_REGION",
"accessKeyId": "AWS_ACCESS_KEY_ID",
"secretAccessKey": "AWS_SECRET_ACCESS_KEY"
}

0 comments on commit 882ba5b

Please sign in to comment.