Skip to content

Commit 24a3f54

Browse files
committed
Add publish:npm script
1 parent ad4ccd6 commit 24a3f54

9 files changed

+71
-59
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ before_script:
1111
script:
1212
- npm test
1313
after_success:
14-
- bash scripts/deploy-dist-docs-examples.sh
14+
- bash scripts/deploy-docs-examples.sh
1515
notifications:
1616
email:
1717
on_success: never

Gruntfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ module.exports = function (grunt) {
160160
// when registering the actual tasks _.uniq is used to discard duplicate tasks from begin run
161161
var allDeps = [
162162
'set_current_version',
163-
'clean:dist',
163+
'clean:dist_internal',
164164
'replace',
165165
'gitinfo',
166166
'copy:fonts'

README.md

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ Carto.js is a JavaScript library to create custom location intelligence applicat
55
## Getting Started
66

77
The best way to get started is to navigate through the Carto.js documentation site:
8-
8+
99
- [Guide](https://cartodb.github.io/full-reference-api/) will give you a good overview of the library.
1010
- [Examples](https://cartodb.github.io/full-reference-api/examples/) will demo some specific features.
1111
- [API Reference](https://cartodb.github.io/full-reference-api/docs/) will help you use a particular class or method.
1212
- [Frequently asked questions](https://cartodb.github.io/full-reference-api/faqs/) might answer some of your questions.
1313

1414
## Versioning
1515

16-
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).
16+
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).
1717

1818
## Submitting Contributions
1919

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

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

26-
## Building the library
26+
## Development
27+
28+
### Building the library
2729

28-
npm run build
30+
```
31+
npm run build
32+
```
2933

3034
To watch the files
3135

32-
npm run build:watch
36+
```
37+
npm run build:watch
38+
```
39+
40+
### Generating the docs
41+
42+
```
43+
npm run docs
44+
```
45+
46+
### Release and publish
47+
48+
```
49+
npm run release
50+
```
51+
52+
```
53+
npm run publish:npm
54+
npm run publish:cdn
55+
```

grunt/tasks/clean.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
module.exports = {
66
task: function() {
77
return {
8-
dist: {
8+
dist_internal: {
99
files: [{
1010
dot: true,
1111
src: [
1212
'.sass-cache',
1313
'.tmp',
14-
'<%= config.dist %>',
14+
'<%= config.dist %>/internal',
1515
'!<%= config.dist %>/.git*'
1616
]
1717
}]

grunt/tasks/s3.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,4 @@ module.exports = {
214214
function isVersionPrerelease(v) {
215215
var v = v.split('.');
216216
return !/^[0-9]+$/.test(v[v.length - 1]);
217-
}
217+
}

package.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,16 @@
150150
"test": "grunt test",
151151
"lint": "eslint .",
152152
"lint:fix": "eslint . --fix",
153-
"docs": "rm -rf docs/public && jsdoc --configure config/jsdoc/public-conf.json",
154-
"docs:internal": "rm -rf docs/internal && jsdoc --configure config/jsdoc/internal-conf.json",
155-
"postversion": "git push origin v4 --follow-tags",
156-
"dist": "grunt build",
157-
"build": "rm -rf dist/public && webpack && webpack --config webpack.config.min.js && node scripts/publish.js",
153+
"docs": "rm -rf docs/public; jsdoc --configure config/jsdoc/public-conf.json",
154+
"docs:internal": "rm -rf docs/internal; jsdoc --configure config/jsdoc/internal-conf.json",
155+
"build": "rm -rf dist/public; webpack && webpack --config webpack.config.min.js && node scripts/generate-package-json.js",
156+
"build:internal": "grunt build",
158157
"build:watch": "webpack -w",
159-
"deploy": "cd dist/public && npm publish",
160-
"watch": "npm-watch"
158+
"postversion": "git push origin HEAD --follow-tags",
159+
"release": "npm version prerelease",
160+
"release:minor": "npm version minor",
161+
"release:patch": "npm version patch",
162+
"publish:npm": "./scripts/publish.sh"
161163
},
162164
"watch": {
163165
"docs": "src/**/*.js"

scripts/deploy-dist-docs-examples.sh renamed to scripts/deploy-docs-examples.sh

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

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

5-
DIST_DIR="dist"
65
DOCS_DIR="docs"
76
EXAMPLES_DIR="examples"
8-
TMP_DIST_DIR="tmp_dist"
97
TMP_DOCS_DIR="tmp_docs"
108
TMP_EXAMPLES_DIR="tmp_examples"
119

@@ -22,53 +20,21 @@ fi
2220

2321
# - Generation
2422

25-
echo "Generating dist"
26-
npm run dist
27-
2823
echo "Generating docs"
2924
npm run docs
3025
npm run docs:internal
3126

32-
echo "Move dist to tmp file"
33-
mv $DIST_DIR $TMP_DIST_DIR
34-
35-
echo "Move docs to tmp file"
27+
echo "Moving docs to tmp file"
3628
mv $DOCS_DIR $TMP_DOCS_DIR
3729

38-
echo "Move examples to tmp file"
30+
echo "Moving examples to tmp file"
3931
mv $EXAMPLES_DIR $TMP_EXAMPLES_DIR
4032

41-
echo "Copy index.html"
33+
echo "Copying index.html"
4234
cp config/jsdoc/index.html $TMP_DOCS_DIR/index.html || exit 1
4335

4436
# - Deployment
4537

46-
echo "Starting dist deployment"
47-
echo "Target: dist branch"
48-
49-
echo "Fetching dist branch"
50-
git fetch origin dist:refs/remotes/origin/dist || exit 1
51-
52-
echo "Checking out dist branch"
53-
git checkout -- . || exit 1
54-
git checkout -b dist origin/dist || exit 1
55-
56-
echo "Copying source content to root"
57-
rm -rf *.js *.map || exit 1
58-
cp $TMP_DIST_DIR/public/* . || exit 1
59-
60-
echo "Pushing new content to $ORIGIN_URL"
61-
git config user.name "Cartofante" || exit 1
62-
git config user.email "systems@cartodb.com" || exit 1
63-
64-
git add *.js *.map || exit 1
65-
git commit --allow-empty -m "Update dist for $TRAVIS_BRANCH $CURRENT_COMMIT" || exit 1
66-
git push --force --quiet "$ORIGIN_URL_WITH_CREDENTIALS" dist > /dev/null 2>&1
67-
git tag "@${TRAVIS_BRANCH:1}"
68-
git push "$ORIGIN_URL_WITH_CREDENTIALS" "@${TRAVIS_BRANCH:1}"
69-
70-
echo "Dist deployed successfully."
71-
7238
echo "Starting docs/examples deployment"
7339
echo "Target: gh-pages branch"
7440

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

94-
echo "Add version in index.html"
60+
echo "Adding version in index.html"
9561
sed -i "s|%VERSION|$TRAVIS_BRANCH|g" index.html
9662

97-
echo "Use CDN carto.js in the v4 examples"
98-
CDN="https://cdn.rawgit.com/CartoDB/cartodb.js/@${TRAVIS_BRANCH:1}/carto.js"
99-
OLD="../../../dist/public/carto.uncompressed.js"
63+
echo "Using unpkg CDN carto.js in the v4 examples"
64+
CDN="https://unpkg.com/carto.js/carto.min.js"
65+
OLD="../../../dist/public/carto.js"
10066
sed -i "s|$OLD|$CDN|g" $EXAMPLES_DIR/v4/public/**/*.html
101-
OLD="../dist/public/carto.uncompressed.js"
67+
OLD="../dist/public/carto.js"
10268
sed -i "s|$OLD|$CDN|g" $EXAMPLES_DIR/v4/index.html
10369

10470
echo "Pushing new content to $ORIGIN_URL"
File renamed without changes.

scripts/publish.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
npm update
4+
5+
VERSION=$(node --eval "console.log(require('./package.json').version);")
6+
7+
npm test || exit 1
8+
9+
echo "Ready to publish Carto.js version $VERSION."
10+
echo "Has the version number been bumped?"
11+
read -n1 -r -p "Press Ctrl+C to cancel, or any other key to continue." key
12+
13+
npm run build
14+
15+
echo "Uploading to NPM..."
16+
17+
cd dist/public
18+
19+
npm publish
20+
21+
echo "All done."

0 commit comments

Comments
 (0)