-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
snapcraft.yaml.sh
executable file
·107 lines (94 loc) · 3.06 KB
/
snapcraft.yaml.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
set -xe
__dirname="$(CDPATH= cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
STRIP_NPX=no
while getopts "r:g:" opt; do
case $opt in
r)
echo "Updating for latest $OPTARG release" >&2
# release
NODE_VERSION="$(curl -sL https://nodejs.org/download/release/index.tab | awk '/^v'"$OPTARG"'\..*[^a-z0-9]src[^a-z0-9]/ { print substr($1, 2); exit }')"
NODE_DISTTYPE="release"
NODE_TAG=""
if [ "X${OPTARG}" = "X6" ]; then
# no npx in the npm that comes with Node 6
STRIP_NPX=yes
fi
;;
g)
echo "Pushing to git $OPTARG" >&2
UPDATE_GIT=yes
GIT_BRANCH=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit
esac
done
# not a release?
if [ -z ${NODE_DISTTYPE+x} ]; then
# nightly
NODE_VERSION="$(curl -sL https://nodejs.org/download/nightly/index.tab | awk '/^v[1-9].*[^a-z0-9]src[^a-z0-9]/ { print substr($1, 2); exit }')"
NODE_DISTTYPE="nightly"
NODE_TAG="$(echo $NODE_VERSION | sed -E 's/^[^-]+-//')"
fi
echo "NODE_VERSION=$NODE_VERSION"
echo "NODE_DISTTYPE=$NODE_DISTTYPE"
echo "NODE_TAG=$NODE_TAG"
if [ "X${UPDATE_GIT}" = "Xyes" ]; then
git clean -fdx
git reset HEAD --hard
git checkout $GIT_BRANCH --force
git pull -r origin $GIT_BRANCH
fi
# Write snapcraft.yaml for this config
cat > ${__dirname}/snapcraft.yaml << EOF
name: node
version: '${NODE_VERSION:0:30}'
summary: Node.js
description: |
A JavaScript runtime built on Chrome's V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js' package ecosystem, npm, is the largest ecosystem of open source libraries in the world. https://nodejs.org/
grade: stable
confinement: classic
apps:
node:
command: bin/node
npm:
command: bin/npm
npx:
command: bin/npx
yarn:
command: bin/yarn.js
yarnpkg:
command: bin/yarn.js
parts:
node:
plugin: make
source-type: tar
source: https://nodejs.org/download/${NODE_DISTTYPE}/v${NODE_VERSION}/node-v${NODE_VERSION}.tar.gz
build-packages:
- g++
- make
- python2.7
prepare: |
./configure --prefix=/ --release-urlbase=https://nodejs.org/download/${NODE_DISTTYPE}/ --tag=${NODE_TAG}
install: |
mkdir -p \$SNAPCRAFT_PART_INSTALL/etc
echo "prefix = /usr/local" >> \$SNAPCRAFT_PART_INSTALL/etc/npmrc
yarn:
source-type: tar
source: https://yarnpkg.com/latest.tar.gz
plugin: dump
# Yarn has a problem with lifecycle scripts when used inside snap, they don't complete properly, with exit code !=0.
# Replacing the spinner with proper stdio appears to fix it.
install: |
sed -i "s/var stdio = spinner ? undefined : 'inherit';/var stdio = 'inherit';/" \$SNAPCRAFT_PART_INSTALL/lib/cli.js
EOF
if [ "X${STRIP_NPX}" = "Xyes" ]; then
sed -i '/^.*npx.*$/d' ${__dirname}/snapcraft.yaml
fi
if [ "X${UPDATE_GIT}" = "Xyes" ] && [ -n "$(git status --porcelain $__dirname)" ]; then
echo "Updating git repo and pushing ..."
git commit $__dirname -m "snap: (auto) updated to ${NODE_VERSION}"
git push origin $GIT_BRANCH
fi