Skip to content

Commit

Permalink
[package] Get ready for real public npm packages!
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Spitzer committed Oct 2, 2018
1 parent 984f7ae commit 7cc8782
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 34 deletions.
10 changes: 7 additions & 3 deletions .release-it.beta.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@
"commitMessage": "Pre-release v%s",
"tagName": "v%s",
"tagAnnotation": "Tradeshift UI v%s",
"beforeStartCommand":
"echo 'S3 overwrite protection & code linting…' && grunt check_cdn:cdn && grunt clean && npm run lint",
"beforeStartCommand": "grunt clean && npm run lint",
"afterReleaseCommand": "echo Successfully released Tradeshift UI v${version}."
},
"buildCommand":
"echo 'Building Tradeshift UI…' && grunt dist && echo 'Uploading to S3…' && grunt exec:s3_upload",
"grunt check_cdn:cdn && echo 'Building Tradeshift UI…' && grunt dist && echo 'Uploading to S3…' && grunt exec:s3_upload",
"github": {
"release": true,
"releaseName": "Pre-release: v%s",
"preRelease": true,
"tokenRef": "GH_ACCESS_TOK"
},
"npm": {
"publish": true,
"publishPath": "dist/npm",
"tag": "beta"
}
}
10 changes: 7 additions & 3 deletions .release-it.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@
"commitMessage": "Release v%s",
"tagName": "v%s",
"tagAnnotation": "Tradeshift UI v%s",
"beforeStartCommand":
"echo 'S3 overwrite protection & code linting…' && grunt check_cdn:cdn && grunt clean && npm run lint",
"beforeStartCommand": "grunt clean && npm run lint",
"afterReleaseCommand": "echo Successfully released Tradeshift UI v${version}."
},
"buildCommand":
"echo 'Building Tradeshift UI…' && grunt dist && echo 'Uploading to S3…' && grunt exec:s3_upload",
"grunt check_cdn:cdn && echo 'Building Tradeshift UI…' && grunt dist && echo 'Uploading to S3…' && grunt exec:s3_upload",
"github": {
"release": true,
"releaseName": "v%s",
"preRelease": false,
"tokenRef": "GH_ACCESS_TOK"
},
"npm": {
"publish": true,
"publishPath": "dist/npm",
"tag": "latest"
}
}
29 changes: 25 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ module.exports = function(grunt) {
dest: 'dist/cdn/ts-<%= pkg.version %>.min.css'
}
]
},
npm: {
files: [
{
src: 'LICENSE.md',
dest: 'dist/npm/LICENSE.md'
},
{
src: 'README.md',
dest: 'dist/npm/README.md'
}
]
}
},

Expand Down Expand Up @@ -415,6 +427,10 @@ module.exports = function(grunt) {
docs_grunt: {
command: 'cd docs && grunt',
stdout: 'inherit'
},
npm_package_json: {
command: 'npm run package-dist',
stdout: 'inherit'
}
},

Expand Down Expand Up @@ -471,16 +487,21 @@ module.exports = function(grunt) {
}

function generateJsConcurrent(target = 'cdn') {
return [
const out = [
'edbml', // edbml -> js
[
// generate ts.js
`tsless:${returnDevForJasmine(target)}`, // generate ts.less
`copy:docs_${returnDevForJasmine(target)}` // copy ts-runtime.less over to the docs
],
'concat:spin', // generate spin.js
'guibundles' // generate ts-runtime-{api,gui}.js
]
];
if (target === 'cdn') {
out.push('exec:npm_package_json'); // generate minimum viable package.json
out.push('copy:npm'); // copy LICENSE/README to npm folder
}
out.push('concat:spin'); // generate spin.js
out.push('guibundles'); // generate ts-runtime-{api,gui}.js
return out;
}

function concatAndUglifyJs(target = 'cdn') {
Expand Down
38 changes: 14 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
{
"name": "tradeshift-ui",
"name": "@tradeshift/tradeshift-ui",
"version": "11.0.0-alpha.1",
"private": true,
"description": "The Tradeshift UI Library & Framework",
"homepage": "https://ui.tradeshift.com/",
"bugs": {
"url": "https://github.com/Tradeshift/tradeshift-ui/issues",
"email": "[email protected]"
"url": "https://github.com/Tradeshift/tradeshift-ui/issues"
},
"author": "Tradeshift UI Team",
"contributors": [
"Wired Earp <jmo@tradeshift.com> (https://github.com/wiredearp)",
"Daniel Spitzer <dsp@tradeshift.com> (https://github.com/sampi)",
"Leo Zhang <[email protected]> (https://github.com/zdlm)",
"Daniel Spitzer <[email protected]> (https://github.com/sampi)"
"Tynan DeBold <[email protected]> (https://github.com/tynandebold)",
"Wired Earp (https://github.com/wiredearp)"
],
"license": "SEE LICENSE IN LICENSE.md",
"engines": {
Expand All @@ -38,27 +37,15 @@
"****** NODE *****": "",
"postinstall": "cd docs && npm ci",
"precommit": "lint-staged",
"gh-pages": "grunt dist && node tasks/gh-pages.js"
"gh-pages": "grunt dist && node tasks/gh-pages.js",
"package-dist": "node tasks/package-dist.js"
},
"lint-staged": {
"*.js": [
"prettier --write",
"eslint --config ./.eslintrc.json",
"git add"
],
"*.json": [
"prettier --write",
"git add"
],
"*.less": [
"prettier --write",
"git add"
]
"*.js": ["prettier --write", "eslint --config ./.eslintrc.json", "git add"],
"*.json": ["prettier --write", "git add"],
"*.less": ["prettier --write", "git add"]
},
"browserslist": [
"Last 2 versions",
"ie 11"
],
"browserslist": ["Last 2 versions", "ie 11"],
"devDependencies": {
"alce": "^1.2.0",
"ali-oss": "^4.10.1",
Expand Down Expand Up @@ -125,5 +112,8 @@
"repository": {
"type": "git",
"url": "git+https://github.com/Tradeshift/tradeshift-ui.git"
},
"publishConfig": {
"access": "public"
}
}
39 changes: 39 additions & 0 deletions tasks/package-dist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env node

/**
* Generate the minimum viable package.json for an npm package
*/

const prettier = require('prettier');
const fs = require('fs');
const path = require('path');
const packageJson = require('../package.json');

delete packageJson.scripts;
delete packageJson.devDependencies;
delete packageJson.browserslist;
delete packageJson['lint-staged'];
packageJson.main = 'ts.js';

try {
write('../dist/npm/package.json', packageJson);
} catch (e) {
process.exit(1);
}
process.exit(0);

function write(file, json) {
fs.writeFileSync(
path.join(path.dirname(fs.realpathSync(__filename)), file),
pretty(json),
'utf-8'
);
}

function pretty(json) {
return prettier.format(`${JSON.stringify(json, null, '\t')}\n`, {
parser: 'json',
useTabs: true,
printWidth: 100
});
}

0 comments on commit 7cc8782

Please sign in to comment.