Skip to content

Commit

Permalink
Add publish:npm script
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesus89 committed Dec 11, 2017
1 parent ad4ccd6 commit 24a3f54
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ before_script:
script:
- npm test
after_success:
- bash scripts/deploy-dist-docs-examples.sh
- bash scripts/deploy-docs-examples.sh
notifications:
email:
on_success: never
Expand Down
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ module.exports = function (grunt) {
// when registering the actual tasks _.uniq is used to discard duplicate tasks from begin run
var allDeps = [
'set_current_version',
'clean:dist',
'clean:dist_internal',
'replace',
'gitinfo',
'copy:fonts'
Expand Down
33 changes: 28 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ Carto.js is a JavaScript library to create custom location intelligence applicat
## Getting Started

The best way to get started is to navigate through the Carto.js documentation site:

- [Guide](https://cartodb.github.io/full-reference-api/) will give you a good overview of the library.
- [Examples](https://cartodb.github.io/full-reference-api/examples/) will demo some specific features.
- [API Reference](https://cartodb.github.io/full-reference-api/docs/) will help you use a particular class or method.
- [Frequently asked questions](https://cartodb.github.io/full-reference-api/faqs/) might answer some of your questions.

## Versioning

We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/CartoDB/cartodb.js/tags).
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/CartoDB/cartodb.js/tags).

## Submitting Contributions

Expand All @@ -23,10 +23,33 @@ You will need to sign a Contributor License Agreement (CLA) before making a subm

This project is licensed under the BSD 3-clause "New" or "Revised" License - see the [LICENSE.txt](LICENSE.txt) file for details.

## Building the library
## Development

### Building the library

npm run build
```
npm run build
```

To watch the files

npm run build:watch
```
npm run build:watch
```

### Generating the docs

```
npm run docs
```

### Release and publish

```
npm run release
```

```
npm run publish:npm
npm run publish:cdn
```
4 changes: 2 additions & 2 deletions grunt/tasks/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
module.exports = {
task: function() {
return {
dist: {
dist_internal: {
files: [{
dot: true,
src: [
'.sass-cache',
'.tmp',
'<%= config.dist %>',
'<%= config.dist %>/internal',
'!<%= config.dist %>/.git*'
]
}]
Expand Down
2 changes: 1 addition & 1 deletion grunt/tasks/s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,4 @@ module.exports = {
function isVersionPrerelease(v) {
var v = v.split('.');
return !/^[0-9]+$/.test(v[v.length - 1]);
}
}
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,16 @@
"test": "grunt test",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"docs": "rm -rf docs/public && jsdoc --configure config/jsdoc/public-conf.json",
"docs:internal": "rm -rf docs/internal && jsdoc --configure config/jsdoc/internal-conf.json",
"postversion": "git push origin v4 --follow-tags",
"dist": "grunt build",
"build": "rm -rf dist/public && webpack && webpack --config webpack.config.min.js && node scripts/publish.js",
"docs": "rm -rf docs/public; jsdoc --configure config/jsdoc/public-conf.json",
"docs:internal": "rm -rf docs/internal; jsdoc --configure config/jsdoc/internal-conf.json",
"build": "rm -rf dist/public; webpack && webpack --config webpack.config.min.js && node scripts/generate-package-json.js",
"build:internal": "grunt build",
"build:watch": "webpack -w",
"deploy": "cd dist/public && npm publish",
"watch": "npm-watch"
"postversion": "git push origin HEAD --follow-tags",
"release": "npm version prerelease",
"release:minor": "npm version minor",
"release:patch": "npm version patch",
"publish:npm": "./scripts/publish.sh"
},
"watch": {
"docs": "src/**/*.js"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

SEMVER_PATTERN="^v(0|[1-9]+)\.(0|[1-9]+)\.(0|[1-9]+)(-[a-z]+(\.[0-9a-z]+)?)?$"

DIST_DIR="dist"
DOCS_DIR="docs"
EXAMPLES_DIR="examples"
TMP_DIST_DIR="tmp_dist"
TMP_DOCS_DIR="tmp_docs"
TMP_EXAMPLES_DIR="tmp_examples"

Expand All @@ -22,53 +20,21 @@ fi

# - Generation

echo "Generating dist"
npm run dist

echo "Generating docs"
npm run docs
npm run docs:internal

echo "Move dist to tmp file"
mv $DIST_DIR $TMP_DIST_DIR

echo "Move docs to tmp file"
echo "Moving docs to tmp file"
mv $DOCS_DIR $TMP_DOCS_DIR

echo "Move examples to tmp file"
echo "Moving examples to tmp file"
mv $EXAMPLES_DIR $TMP_EXAMPLES_DIR

echo "Copy index.html"
echo "Copying index.html"
cp config/jsdoc/index.html $TMP_DOCS_DIR/index.html || exit 1

# - Deployment

echo "Starting dist deployment"
echo "Target: dist branch"

echo "Fetching dist branch"
git fetch origin dist:refs/remotes/origin/dist || exit 1

echo "Checking out dist branch"
git checkout -- . || exit 1
git checkout -b dist origin/dist || exit 1

echo "Copying source content to root"
rm -rf *.js *.map || exit 1
cp $TMP_DIST_DIR/public/* . || exit 1

echo "Pushing new content to $ORIGIN_URL"
git config user.name "Cartofante" || exit 1
git config user.email "systems@cartodb.com" || exit 1

git add *.js *.map || exit 1
git commit --allow-empty -m "Update dist for $TRAVIS_BRANCH $CURRENT_COMMIT" || exit 1
git push --force --quiet "$ORIGIN_URL_WITH_CREDENTIALS" dist > /dev/null 2>&1
git tag "@${TRAVIS_BRANCH:1}"
git push "$ORIGIN_URL_WITH_CREDENTIALS" "@${TRAVIS_BRANCH:1}"

echo "Dist deployed successfully."

echo "Starting docs/examples deployment"
echo "Target: gh-pages branch"

Expand All @@ -91,14 +57,14 @@ mv $TMP_EXAMPLES_DIR/categories.json $EXAMPLES_DIR/v4/categories.json || exit 1
mv $TMP_EXAMPLES_DIR/index.html $EXAMPLES_DIR/v4/index.html || exit 1
mv $TMP_DOCS_DIR/index.html index.html || exit 1

echo "Add version in index.html"
echo "Adding version in index.html"
sed -i "s|%VERSION|$TRAVIS_BRANCH|g" index.html

echo "Use CDN carto.js in the v4 examples"
CDN="https://cdn.rawgit.com/CartoDB/cartodb.js/@${TRAVIS_BRANCH:1}/carto.js"
OLD="../../../dist/public/carto.uncompressed.js"
echo "Using unpkg CDN carto.js in the v4 examples"
CDN="https://unpkg.com/carto.js/carto.min.js"
OLD="../../../dist/public/carto.js"
sed -i "s|$OLD|$CDN|g" $EXAMPLES_DIR/v4/public/**/*.html
OLD="../dist/public/carto.uncompressed.js"
OLD="../dist/public/carto.js"
sed -i "s|$OLD|$CDN|g" $EXAMPLES_DIR/v4/index.html

echo "Pushing new content to $ORIGIN_URL"
Expand Down
File renamed without changes.
21 changes: 21 additions & 0 deletions scripts/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

npm update

VERSION=$(node --eval "console.log(require('./package.json').version);")

npm test || exit 1

echo "Ready to publish Carto.js version $VERSION."
echo "Has the version number been bumped?"
read -n1 -r -p "Press Ctrl+C to cancel, or any other key to continue." key

npm run build

echo "Uploading to NPM..."

cd dist/public

npm publish

echo "All done."

0 comments on commit 24a3f54

Please sign in to comment.