Skip to content

Commit 4acb029

Browse files
committed
Refactor recipes for generating and analyzing npm tarballs
1 parent 8da1a6e commit 4acb029

File tree

3 files changed

+49
-29
lines changed

3 files changed

+49
-29
lines changed

tools/make/common.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ NODE ?= node
147147
# Define the command for `npm`:
148148
NPM ?= npm
149149

150+
# Define the command for generating an npm gzipped archive:
151+
NPM_PACK ?= npm pack
152+
150153
# Define the command for `julia`:
151154
JULIA ?= julia
152155

@@ -159,6 +162,9 @@ R ?= r
159162
# Define the command for running R script files:
160163
RSCRIPT ?= Rscript
161164

165+
# Define the command for getting the current project version:
166+
CURRENT_PROJECT_VERSION ?= $(NODE) -e "console.log( require( '$(ROOT_DIR)/package.json' ).version )"
167+
162168

163169
# COMPILERS #
164170

tools/make/lib/node/npm.mk

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,37 @@ ifeq ($(NPM_VERSION), pre-release)
3636
npm_version_prerequisite := npm-version-pre-release
3737
endif
3838

39+
# Specify the output build directory when generating an npm gzipped archive:
40+
NPM_TARBALL_BUILD_OUT := $(BUILD_DIR)/npm
41+
42+
# Specify the gzipped archive basename:
43+
npm_tarball_basename := "stdlib-stdlib-$(shell $(CURRENT_PROJECT_VERSION)).tgz"
44+
45+
# Specify the output npm gzipped archive:
46+
npm_tarball := $(NPM_TARBALL_BUILD_OUT)/$(npm_tarball_basename)
47+
3948

4049
# TARGETS #
4150

51+
# Generate an npm tarball.
52+
#
53+
# This target generates an npm gzipped archive.
54+
55+
$(npm_tarball):
56+
$(QUIET) $(MKDIR_RECURSIVE) $(NPM_TARBALL_BUILD_OUT)
57+
$(QUIET) $(NPM_PACK) $(ROOT_DIR) >/dev/null
58+
$(QUIET) mv $(ROOT_DIR)/$(npm_tarball_basename) $@
59+
60+
61+
# Generate an npm tarball.
62+
#
63+
# This target generates an npm gzipped archive.
64+
65+
npm-tarball: $(npm_tarball)
66+
67+
.PHONY: npm-tarball
68+
69+
4270
# Run pre-version tasks.
4371
#
4472
# This target runs tasks which should be completed before incrementing the project version.
@@ -144,10 +172,22 @@ npm-post-version:
144172
$(QUIET) echo ''
145173
$(QUIET) echo 'Incremented version and committed changes.'
146174
$(QUIET) echo ''
175+
$(QUIET) echo "Tarball size: $(shell $(MAKE) -f $(this_file) stats-npm-tarball-size)"
176+
$(QUIET) echo ''
147177
$(QUIET) echo 'If okay to publish, run:'
148178
$(QUIET) echo ''
149179
$(QUIET) echo ' $$ make npm-publish'
150180
$(QUIET) echo " $$ git push origin $(shell $(GIT_BRANCH)) && git push origin --tags"
151181
$(QUIET) echo ''
152182

153183
.PHONY: npm-post-version
184+
185+
186+
# Remove npm tarball(s).
187+
#
188+
# This target removes npm gzipped archives.
189+
190+
clean-npm-tarball:
191+
$(QUIET) -rm -f $(NPM_TARBALL_BUILD_OUT)/*.tgz
192+
193+
.PHONY: clean-npm-tarball

tools/make/lib/stats/npm.mk

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,11 @@
11

2-
# VARIABLES #
3-
4-
# Specify the output build directory when generating an npm gzipped archive.
5-
stats_npm_tarball_build_out := $(BUILD_DIR)/npm
6-
7-
# Get the current package version:
8-
stats_npm_tarball_pkg_version := $(shell $(NODE) -e "console.log( require( '$(ROOT_DIR)/package.json' ).version )")
9-
10-
# Specify the gzipped archive basename:
11-
stats_npm_tarball_basename := "stdlib-stdlib-$(stats_npm_tarball_pkg_version).tgz"
12-
13-
# Specify the output npm gzipped archive:
14-
stats_npm_tarball := $(stats_npm_tarball_build_out)/$(stats_npm_tarball_basename)
15-
16-
172
# TARGETS #
183

19-
# Generate npm tarball.
20-
#
21-
# This target generates an npm gzipped archive.
22-
23-
$(stats_npm_tarball):
24-
$(QUIET) $(DELETE) $(DELETE_FLAGS) $(stats_npm_tarball_build_out)
25-
$(QUIET) $(MKDIR_RECURSIVE) $(BUILD_DIR)/npm
26-
$(QUIET) $(NPM) pack $(ROOT_DIR) >/dev/null
27-
$(QUIET) mv $(ROOT_DIR)/$(stats_npm_tarball_basename) $@
28-
29-
304
# Compute npm archive size.
315
#
32-
# This target computes size of the gzipped archive which would be published to npm.
6+
# This target computes size (in bytes) of the gzipped archive which would be published to npm.
337

34-
stats-npm-tarball-size: $(stats_npm_tarball)
35-
$(QUIET) wc -c $(stats_npm_tarball) | awk '{print $$1 OFS "B"}'
8+
stats-npm-tarball-size: npm-tarball
9+
$(QUIET) wc -c $(npm_tarball) | awk '{print $$1 OFS "B"}'
3610

3711
.PHONY: stats-npm-tarball-size

0 commit comments

Comments
 (0)