1
1
#! /usr/bin/env bash
2
2
3
- # Release Notes
4
- # Version 0.2.0
5
- # - auto detect shopify, bigcommerce, envkey
6
- # - automatically download stencil file from EnvKey if we find the variable $STENCIL_FILE
7
- # - depricate old helpers: requires_stencil, requires_themekit, requires_envkey
8
- # Version 0.1.0
9
- # - check for updates and download when a new release is available
10
- # - writes version string to .helpers-version in the same directory as helpers.sh
11
- # - only check for a new version every 24h
12
- # - added auto=detecting project types
13
- # - look for .nvmrc and assume project is using nvm
14
- # - look for .meteor directory and assume project is using meteor
15
- # - don't call nvm use since direnv is loading node
16
- # - abandon using log_error... just call _log error "something bad happened..."
17
- # Version 0.0.4
18
- # - detect yarn.lock vs package-lock.json and install yarn if needed
19
- # Version 0.0.3
20
- # - bugfix for when .nvmrc contains a release name ie: 'lts/dubnium'
21
- # Version 0.0.2
22
- # - don't assume 'layout node' when using node
23
- # Version 0.0.1
24
- # - Initial release
25
-
26
-
27
3
REPO_URL=" https://api.github.com/repos/steve-ross/direnv-helpers/releases/latest"
28
4
29
5
__prompt_install_nvm (){
@@ -149,7 +125,11 @@ _log() {
149
125
function comparedate() {
150
126
local MAXAGE=$( bc <<< ' 24*60*60' ) # seconds in 24 hours
151
127
# file age in seconds = current_time - file_modification_time.
152
- local FILEAGE=$(( $(date +% s) - $(stat - f '% m' "$1 ")) )
128
+ if [ $( uname -s) == " Darwin" ]; then
129
+ local FILEAGE=$(( $(date +% s) - $(stat - f '% m' "$1 ")) )
130
+ else
131
+ local FILEAGE=$(( $(date +% s) - $(stat - c '% Y' "$1 ")) )
132
+ fi
153
133
test $FILEAGE -gt $MAXAGE && {
154
134
echo " Time to check for an update..."
155
135
}
@@ -249,6 +229,7 @@ __use_yarn(){
249
229
fi
250
230
else
251
231
if [ ! -d ./node_modules ]; then
232
+ _log warn " Installing packages"
252
233
# no node modules... install via yarn
253
234
yarn
254
235
fi
@@ -267,6 +248,7 @@ __requires_npm_or_yarn(){
267
248
else
268
249
if [ ! -d ./node_modules ]; then
269
250
# no node modules... run npm install
251
+ _log warn " Installing packages"
270
252
npm install
271
253
fi
272
254
fi
@@ -360,6 +342,19 @@ layout_project(){
360
342
361
343
# if we have a package json do some node project detection
362
344
if [[ -f " package.json" ]]; then
345
+ # set some env vars that might be useful
346
+ # package version
347
+ export NPM_PACKAGE_VERSION=$( cat package.json \
348
+ | grep version \
349
+ | head -1 \
350
+ | awk -F: ' { print $2 }' \
351
+ | sed ' s/[",]//g' )
352
+ # package name
353
+ export NPM_PACKAGE_NAME=$( cat package.json \
354
+ | grep name \
355
+ | head -1 \
356
+ | awk -F: ' { print $2 }' \
357
+ | sed ' s/[",]//g' )
363
358
# if directory has .nvmrc assume nvm/node project
364
359
if [[ -f " .nvmrc" ]]; then
365
360
layout_nvm
0 commit comments