Skip to content

Commit 1a49d51

Browse files
Add grunt pack command
Add grunt pack command that will: * remove prepublish script from package.json * clean the project (delete all .js files inside it) * build .ts files in release mode * call `npm pack` and produce .tgz for the new version We have to remove the prepublish script as it does not allow us clean publish of the .tgz. The problem is that when `npm publish <tgz>` is used, the package is added to local npm cache. After that it's package.json is extracted from the cached .tgz file and modified with additional metadata. At this point npm calls the prepublish script, but it fails to find our prepublish.js as it's not extracted in the cache (only the package.json is extracted). I've not removed the prepublish script from the package.json, so if anyone uses `npm pack` locally or `npm publish` directly, the correct .js files will be used. > NOTE: Calling `grunt pack` locally will modify your package.json. DO NOT commit these changes.
1 parent ea23501 commit 1a49d51

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

Gruntfile.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,25 @@ module.exports = function(grunt) {
1313
devlib: {
1414
src: ["lib/**/*.ts"],
1515
reference: "lib/.d.ts"
16+
},
17+
release_build: {
18+
src: ["lib/**/*.ts"],
19+
reference: "lib/.d.ts",
20+
options: {
21+
sourceMap: false,
22+
removeComments: true
23+
}
24+
}
25+
},
26+
27+
shell: {
28+
options: {
29+
stdout: true,
30+
stderr: true
31+
},
32+
33+
build_package: {
34+
command: "npm pack"
1635
}
1736
},
1837

@@ -23,6 +42,20 @@ module.exports = function(grunt) {
2342

2443
grunt.loadNpmTasks("grunt-contrib-clean");
2544
grunt.loadNpmTasks("grunt-ts");
45+
grunt.loadNpmTasks('grunt-shell');
46+
47+
grunt.registerTask("remove_prepublish_script", function() {
48+
var packageJson = grunt.file.readJSON("package.json");
49+
delete packageJson.scripts.prepublish;
50+
grunt.file.write("package.json", JSON.stringify(packageJson, null, " "));
51+
});
52+
53+
grunt.registerTask("pack", [
54+
"clean",
55+
"remove_prepublish_script",
56+
"ts:release_build",
57+
"shell:build_package"
58+
]);
2659

2760
grunt.registerTask("default", "ts:devlib");
2861
}

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@
3838
"yargs": "4.7.1"
3939
},
4040
"devDependencies": {
41-
"grunt-contrib-clean": "0.6.0",
42-
"grunt": "0.4.5",
43-
"grunt-ts": "4.2.0",
41+
"grunt": "1.0.1",
42+
"grunt-contrib-clean": "1.0.0",
43+
"grunt-shell": "1.3.0",
44+
"grunt-ts": "5.5.1",
4445
"typescript": "1.7.5"
4546
},
4647
"engines": {

0 commit comments

Comments
 (0)