-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-package.sh
More file actions
executable file
·67 lines (57 loc) · 3.5 KB
/
Copy pathcreate-package.sh
File metadata and controls
executable file
·67 lines (57 loc) · 3.5 KB
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
#!/usr/bin/env bash
set -o errexit
set -o pipefail
set -o nounset
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
# Validate arguments
if [ $# -lt 1 ] || [ -z "$1" ] ; then
echo "Error: Specify the name of the new package." >&2
exit 1
fi
scope=$(npx json -f 'scope.json' scope)
name=$scope.$1
root_path="${__dir}/../"
pkg_path="${root_path}/packages/${name}/"
echo "Trying to create package '${name}' at '${pkg_path}'..."
if [ -d "${pkg_path}" ]; then
echo 'The path for this package already exists.'
exit 1
fi
lerna create "${name}" 'packages' --description "" --yes
# prepare package
mkdir -p "${pkg_path}/src/"
touch "${pkg_path}/src/index.ts"
rm -r "${pkg_path:?}/lib"
echo "" > "${pkg_path}/__tests__/${name}.test.js"
# copy tsconfig and index.html
cp "${__dir}/utils/tsconfig.json" "${pkg_path}"
cp "${__dir}/utils/index.html" "${pkg_path}"
# adjust package.json
npx json -q -I -f "${pkg_path}package.json" -e "this.name=\"@shapediver/${name}\""
npx json -q -I -f "${pkg_path}package.json" -e 'this.description=""'
npx json -q -I -f "${pkg_path}package.json" -e 'this.main="dist/index.js"'
npx json -q -I -f "${pkg_path}package.json" -e 'this.typings="dist/index.d.ts"'
npx json -q -I -f "${pkg_path}package.json" -e 'this.files=["dist"]'
npx json -q -I -f "${pkg_path}package.json" -e 'this.scripts.check="tsc --noEmit"'
npx json -q -I -f "${pkg_path}package.json" -e 'this.scripts.build="bash ../../scripts/build.sh"'
npx json -q -I -f "${pkg_path}package.json" -e 'this.scripts["build-dep"]="bash ../../scripts/build-dep.sh"'
npx json -q -I -f "${pkg_path}package.json" -e 'this.scripts["build-dev"]="bash ../../scripts/build-dev.sh"'
npx json -q -I -f "${pkg_path}package.json" -e 'this.scripts["build-prod"]="bash ../../scripts/build-prod.sh"'
npx json -q -I -f "${pkg_path}package.json" -e 'this.scripts.test="bash ../../scripts/test.sh"'
npx json -q -I -f "${pkg_path}package.json" -e 'this.scripts["pre-publish"]="bash ../../scripts/pre-publish.sh"'
npx json -q -I -f "${pkg_path}package.json" -e 'this.scripts["post-publish"]="bash ../../scripts/post-publish.sh"'
npx json -q -I -f "${pkg_path}package.json" -e 'this.jest={}'
npx json -q -I -f "${pkg_path}package.json" -e 'this.jest.preset="ts-jest"'
npx json -q -I -f "${pkg_path}package.json" -e 'this.jest.testEnvironment="node"'
npx json -q -I -f "${pkg_path}package.json" -e 'this.devDependencies={}'
npx json -q -I -f "${pkg_path}package.json" -e 'this.directories={}'
npx json -q -I -f "${pkg_path}package.json" -e 'this.directories.test="__tests__"'
npx json -q -I -f "${pkg_path}package.json" -e "this.devDependencies['jest']=\"$(npx json -f "${root_path}/package.json" 'devDependencies.jest')\""
npx json -q -I -f "${pkg_path}package.json" -e "this.devDependencies['lerna']=\"$(npx json -f "${root_path}/package.json" 'devDependencies.lerna')\""
npx json -q -I -f "${pkg_path}package.json" -e "this.devDependencies['typescript']=\"$(npx json -f "${root_path}/package.json" 'devDependencies.typescript')\""
npx json -q -I -f "${pkg_path}package.json" -e "this.devDependencies['webpack']=\"$(npx json -f "${root_path}/package.json" 'devDependencies.webpack')\""
npx json -q -I -f "${pkg_path}package.json" -e "this.devDependencies['webpack-cli']=\"$(npx json -f "${root_path}/package.json" 'devDependencies.webpack-cli')\""
npx json -q -I -f "${pkg_path}package.json" -e "this.devDependencies['webpack-dev-server']=\"$(npx json -f "${root_path}/package.json" 'devDependencies.webpack-dev-server')\""
cd "${root_path}"
pnpm install
echo "Package '${name}' successfully created!"