@transitive-sdk/utils-caps 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Dockerfile ADDED
@@ -0,0 +1,15 @@
1
+ FROM node:16
2
+
3
+ WORKDIR /app
4
+ ENV TRANSITIVE_IS_CLOUD=1
5
+ ENV TR_DEVMODE=1
6
+ ENV EXTERNAL_IP=127.0.0.1
7
+ RUN apt-get update && apt-get install -y vim
8
+
9
+ COPY . /app/
10
+ ENV npm_config_userconfig=/app/.npmrc
11
+ RUN npm --prefix cloud install
12
+
13
+ # CMD cp -a dist /app/run && npm run cloud
14
+ CMD ["npm","run","cloud"]
15
+
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2016 Chris Smith
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,10 @@
1
+ # @transitive-sdk/utils-caps
2
+
3
+ Utilities to build and run Transitive capabilities in dev.
4
+
5
+ This package is included as a dependency in new Transitive capabilities created using the capability initializer (`npm init @transitive-sdk@latest mycap`). It contains scripts to:
6
+ - run the robot component in development,
7
+ - build the web components using [esbuild](https://esbuild.github.io/),
8
+ - build and run the docker container for the cloud component in development.
9
+
10
+ You do not typically use this package directly, so we recommend to follow our documentation for creating your own capabilities.
package/docker.sh ADDED
@@ -0,0 +1,82 @@
1
+ #!/bin/bash
2
+
3
+
4
+ # Script to run cloud caps in docker. This tries to replicate what we do in
5
+ # cloud/app/docker.js, just for dev.
6
+ # Usage: sym-link into cap folder, run there.
7
+
8
+ set -e
9
+
10
+ BASE_PORT=1234
11
+
12
+ # The directory where this script lives
13
+ DIR=$(dirname $0)
14
+
15
+ # find an available port we can use
16
+ function findOffset() {
17
+ local PORT=$BASE_PORT
18
+ local OFFSET=0
19
+ while (nc -z 127.0.0.1 $PORT); do
20
+ OFFSET=$(( $OFFSET + 1 ));
21
+ PORT=$(( $BASE_PORT + $OFFSET ));
22
+ done
23
+ echo $OFFSET
24
+ }
25
+
26
+ OFFSET=$(findOffset)
27
+ PORT=$(( $BASE_PORT + $OFFSET ))
28
+ MIN_PORT=$((30000 + $OFFSET * 100))
29
+ MAX_PORT=$((30080 + $OFFSET * 100))
30
+
31
+ echo "using port offset $OFFSET, i.e., port $PORT and port range $MIN_PORT-$MAX_PORT"
32
+
33
+ CAP_NAME=$(npm pkg get name)
34
+ VERSION=$(npm pkg get version)
35
+ FULL_NAME=${CAP_NAME/\//.}.${VERSION}
36
+ FULL_NAME2=${FULL_NAME//\"/}
37
+ CONTAINER_NAME=${FULL_NAME2//@/}
38
+ TAG="transitive-robotics/$(basename $PWD):${VERSION//\"/}"
39
+ TMP=${CAP_NAME//[\"@]/};
40
+ SAFE_NAME=${TMP//\//_} # e.g., transitive-robotics-webrtc-video
41
+
42
+ echo Building $TAG and running as $CONTAINER_NAME
43
+
44
+ $DIR/generate_certs.sh
45
+ mkdir -p cloud/certs
46
+ mv client.* cloud/certs
47
+
48
+ # copy with -L (symlink resolution) into tmp dir for building
49
+ TMPDIR=/tmp/_tr_build/$TAG
50
+ mkdir -p $TMPDIR
51
+ echo "copying to $TMPDIR"
52
+ cp -aLu . $TMPDIR
53
+
54
+ # docker build -f $SCRIPT_PATH/Dockerfile -t $TAG \
55
+ docker build -f $DIR/Dockerfile -t $TAG \
56
+ --add-host=registry.homedesk.local:host-gateway \
57
+ $TMPDIR
58
+
59
+ mkdir -p /tmp/pers/common
60
+ mkdir -p /tmp/pers/$TAG
61
+
62
+ docker run -it --rm --init \
63
+ --env MQTT_URL=mqtts://mosquitto \
64
+ --env PUBLIC_PORT=$PORT \
65
+ --env MIN_PORT=$MIN_PORT \
66
+ --env MAX_PORT=$MAX_PORT \
67
+ --env MONGO_DB="cap_$SAFE_NAME" \
68
+ --env MONGO_URL="mongodb://mongodb" \
69
+ -p $PORT:1000 -p $PORT:1000/udp \
70
+ -p $MIN_PORT-$MAX_PORT:$MIN_PORT-$MAX_PORT -p $MIN_PORT-$MAX_PORT:$MIN_PORT-$MAX_PORT/udp \
71
+ -v /tmp/pers/common:/persistent/common \
72
+ -v /tmp/pers/${TAG//:/.}:/persistent/self \
73
+ --network=cloud_caps \
74
+ --name $CONTAINER_NAME \
75
+ $TAG $@
76
+ # -v $PWD/cloud:/app/cloud \
77
+
78
+ # doesn't yet work: when using this, the npm script runs as the owning user,
79
+ # "node", because it has the same uid (1000) as us. But we want root.
80
+ # -v $PWD:/app \
81
+
82
+ rm -rf $TMPDIR
package/esbuild.js ADDED
@@ -0,0 +1,64 @@
1
+ const esbuild = require('esbuild');
2
+ const fs = require('fs');
3
+ const { execSync } = require('child_process');
4
+ // const svgrPlugin = require('esbuild-plugin-svgr');
5
+ const { getPackageVersionNamespace } = require('@transitive-sdk/utils');
6
+
7
+ if (!process.env.npm_package_version || !process.env.npm_package_name) {
8
+ console.error('This build script must be run from npm.');
9
+ process.exit(1);
10
+ }
11
+
12
+ const entryPoints = fs.readdirSync('./web', {withFileTypes: true})
13
+ .filter(item => !item.isDirectory())
14
+ .filter(({name}) => name.search('test.js') == -1)
15
+ .map(({name}) => `./web/${name}`);
16
+
17
+ const isDevelopment = (process.env.npm_lifecycle_event != 'prepare');
18
+
19
+ const config = {
20
+ entryPoints,
21
+ bundle: true,
22
+ preserveSymlinks: true, // this allows us to use symlinks to ../shared
23
+ minify: !isDevelopment,
24
+ sourcemap: isDevelopment,
25
+ target: ['es2022'],
26
+ outdir: 'dist',
27
+ define: {
28
+ TR_PKG_VERSION: JSON.stringify(process.env.npm_package_version),
29
+ TR_PKG_NAME: JSON.stringify(process.env.npm_package_name),
30
+ TR_PKG_VERSION_NS: JSON.stringify(getPackageVersionNamespace()),
31
+ },
32
+ // plugins: [
33
+ // svgrPlugin(),
34
+ // ],
35
+ loader: {
36
+ '.svg': 'text',
37
+ '.wasm': 'file',
38
+ // '.css': 'local-css',
39
+ },
40
+ plugins: [{
41
+ name: 'rebuild-notify',
42
+ setup(build) {
43
+ build.onEnd(result => {
44
+ console.log(new Date(),
45
+ `build ended with ${result.errors.length} errors`);
46
+
47
+ const dir = `/tmp/caps/${process.env.npm_package_name}`;
48
+ isDevelopment && execSync(`mkdir -p ${dir} && cp -r package.json dist ${dir}`);
49
+ })
50
+ },
51
+ }],
52
+ };
53
+
54
+ const run = async () => {
55
+ const ctx = await esbuild.context(config);
56
+ if (isDevelopment) {
57
+ await ctx.watch();
58
+ } else {
59
+ await ctx.rebuild();
60
+ process.exit(0);
61
+ }
62
+ };
63
+
64
+ run();
@@ -0,0 +1,26 @@
1
+ #!/bin/bash
2
+
3
+ # generate client certificate for mqtt broker for the package of the current folder
4
+
5
+ set -e
6
+
7
+ CN=$(npm pkg get name) # get package name
8
+ CN=${CN//\"} # remove the quotes
9
+ CN=${CN/\//\\/} # escape the slash
10
+
11
+ if [ ! -e client.crt ]; then
12
+ TR_VAR_DIR=$(curl -sf http://install.localhost/var-folder-location)
13
+ VARDIR=${TR_VAR_DIR:-~/transitive}
14
+ echo "Generating cloud certs using CA certs in $VARDIR"
15
+
16
+ openssl genrsa -out client.key 2048
17
+ echo using "CN=cap:$CN"
18
+ openssl req -out client.csr -key client.key -new -subj="/CN=cap:$CN"
19
+ openssl x509 -req -in client.csr -CA $VARDIR/certs/ca.crt \
20
+ -CAkey $VARDIR/certs/ca.key -CAcreateserial -out client.crt -days 36500
21
+
22
+ echo "certificate generated (client.crt):"
23
+ openssl x509 -in client.crt -text | grep CN
24
+ else
25
+ echo "certificates already exist, not overwriting"
26
+ fi
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@transitive-sdk/utils-caps",
3
+ "version": "0.1.0",
4
+ "description": "Utilities to build and run Transitive capabilities in dev",
5
+ "homepage": "https://transitiverobotics.com",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/transitiverobotics/transitive-utils.git",
9
+ "directory": "caps"
10
+ },
11
+ "main": "index.js",
12
+ "author": {
13
+ "name": "Christian Fritz",
14
+ "email": "christian@transitiverobotics.com"
15
+ },
16
+ "keywords": [
17
+ "robotics"
18
+ ],
19
+ "bin": {
20
+ "subScript": "subScript.sh",
21
+ "transitiveDev": "transitiveDev.sh"
22
+ },
23
+ "scripts": {
24
+ "test": "echo \"Error: no test specified\" && exit 1"
25
+ },
26
+ "license": "Apache-2.0",
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "dependencies": {
31
+ "@transitive-sdk/utils": ">=0.9.5",
32
+ "esbuild": "^0.18.15"
33
+ }
34
+ }
package/publish.sh ADDED
@@ -0,0 +1,80 @@
1
+ #!/bin/bash
2
+
3
+ set -e
4
+
5
+ # Ensure we are logged in to the given registry
6
+ function ensureAuth() {
7
+ registry=$1
8
+ if ( grep "^//$registry/:_authToken" ~/.npmrc ); then
9
+ echo "We are already logged into registry"
10
+ else
11
+ # get location of local dev's var folder
12
+ TR_VAR_DIR=$(curl -sf http://install.localhost/var-folder-location)
13
+ # "source" the .env file
14
+ set -o allexport
15
+ . $TR_VAR_DIR/.env
16
+ set +o allexport
17
+
18
+ echo "Logging in to local npm registry"
19
+
20
+ # add npm login authentication using the bot token from local .env file
21
+ echo "//$registry/:_authToken=$TR_BOT_TOKEN" >> ~/.npmrc
22
+ fi;
23
+ }
24
+
25
+ CWD=$PWD
26
+
27
+ if ( git rev-parse --is-inside-work-tree &>/dev/null ); then
28
+ # We are inside a git repo.
29
+ # Refuse to run if git working directory has unstaged changes. Untracked files
30
+ # are OK. See https://unix.stackexchange.com/a/155077/53593
31
+ git diff --quiet --exit-code || (echo 'Not clean, refusing to publish' && exit 1);
32
+ else
33
+ if [[ $1 = "prod" ]]; then
34
+ echo 'Need to be inside a clean git working directory to publish to prod'
35
+ exit 2
36
+ fi;
37
+ fi;
38
+
39
+ NAME=$(npm pkg get name | tr -d '"');
40
+ VERSION=$(npm pkg get version | tr -d '"');
41
+ TAG="${NAME/*\//}@$VERSION"
42
+
43
+ TMPDIR=$(mktemp -d)
44
+
45
+ echo "copying to $TMPDIR"
46
+ cp -aL . $TMPDIR
47
+ cd $TMPDIR
48
+
49
+ echo "Transpiling front-end components"
50
+ rm -rf dist
51
+ npm run prepare
52
+
53
+ npm install --no-save javascript-obfuscator@4.0.0
54
+
55
+ FILES=$(find . -name "*.js" -not -path "**/hi-perf/*" -not -path "**/node_modules/*" -not -path "./dist/*")
56
+ for f in $FILES; do
57
+ npx javascript-obfuscator --split-strings true --split-strings-chunk-length 8 --string-array-encoding base64 --ignore-imports true --output $f $f
58
+ # Maybe add later: --self-defending true
59
+ done
60
+
61
+ rm -f .npmrc
62
+
63
+ # This allows `npm prepack` to run, see package.json in cap itself (from init package)
64
+ export TRANSITIVEDEV=1
65
+
66
+ if [[ $1 = "prod" ]]; then
67
+ echo "publishing $TAG to production"
68
+ npm publish --registry=https://registry.transitiverobotics.com
69
+ echo
70
+ cd $CWD
71
+ echo 'tagging'
72
+ git tag $TAG
73
+ git push --tags
74
+ else
75
+ ensureAuth registry.localhost
76
+ echo "publishing $TAG to development"
77
+ npm publish --registry=http://registry.localhost
78
+ fi;
79
+
80
+ echo 'done'
package/republish.sh ADDED
@@ -0,0 +1,2 @@
1
+ npm unpublish --registry=http://registry.$(hostname).local -f
2
+ ./publish.sh
package/rundev.sh ADDED
@@ -0,0 +1,54 @@
1
+ #!/bin/bash
2
+
3
+ # A script for starting the robot component of a capability in development, i.e.
4
+ # establishing the same or similar runtime context as when the component is run
5
+ # on a robot/device in production.
6
+
7
+ if [[ ! -e ~/.transitive/.env ]]; then
8
+ >&2 echo "** Error. It seems that the Transitive agent is not installed. Aborting."
9
+ exit 1;
10
+ fi;
11
+
12
+ CAP=$(npm pkg get name | tr -d '"')
13
+ mkdir -p ~/.transitive/packages/$CAP
14
+ echo -n 1234 > ~/.transitive/packages/$CAP/password
15
+ . ~/.transitive/etc/env_local
16
+
17
+ getROSRelease() {
18
+ case $(lsb_release -sc) in
19
+ xenial) echo kinetic;;
20
+ bionic) echo melodic;;
21
+ focal) echo noetic;;
22
+ *) echo noetic;;
23
+ esac
24
+ }
25
+
26
+ tryToSourceROS() {
27
+ ROS_RELEASE=$1
28
+ if [ -e /opt/ros/$ROS_RELEASE/setup.bash ]; then
29
+ echo "found ROS $ROS_RELEASE, sourcing it";
30
+ . /opt/ros/$ROS_RELEASE/setup.bash;
31
+ fi
32
+ }
33
+
34
+ # automatically decide which ROS1 release to source based on OS
35
+ tryToSourceROS $(getROSRelease)
36
+
37
+ # ROS 2:
38
+ tryToSourceROS foxy
39
+ tryToSourceROS galactic
40
+ tryToSourceROS humble
41
+ tryToSourceROS iron
42
+
43
+ # Make sure a config file exists
44
+ if [[ ! -e ~/.transitive/config.json ]]; then
45
+ echo "{}" > ~/.transitive/config.json
46
+ fi;
47
+
48
+ env $(cat ~/.transitive/.env | grep -v ^\# | xargs) \
49
+ PASSWORD="1234" \
50
+ TRPACKAGE=$CAP \
51
+ TRCONFIG="$(cat ~/.transitive/config.json | tr -d '\n' | sed "s#$CAP#package#")" \
52
+ NODE_ARGS=$@ \
53
+ TRANSITIVE_IS_ROBOT=1 \
54
+ npm start
package/subScript.sh ADDED
@@ -0,0 +1,51 @@
1
+ #!/bin/bash
2
+
3
+ # Use this script in your wrapper package's script to relay invokation to scripts
4
+ # int he correct subproject.
5
+
6
+ # Define a mapping from lifecycle events to scripts in sub-project. Note that
7
+ # we *don't* want to map preinstall to preinstall, since in the subproject
8
+ # preinstall will already be executed when running install. Instead we create
9
+ # new script names, preall and postall, that will run before *anything* happens
10
+ # in the subproject, and in particular before npm dependencies are installed.
11
+ declare -A subscripts
12
+ subscripts["preinstall"]="preall"
13
+ subscripts["postinstall"]="postall"
14
+
15
+ # Known npm command that should be invoked without `run`
16
+ declare -A npmCommands
17
+ npmCommands["install"]=1
18
+ npmCommands["update"]=1
19
+ npmCommands["rebuild"]=1
20
+
21
+ SUBSCRIPT=${subscripts[$npm_lifecycle_event]:-$npm_lifecycle_event}
22
+
23
+ if [[ $TRANSITIVE_IS_ROBOT ]]; then
24
+ SUBPROJECT=robot
25
+ elif [[ $TRANSITIVE_IS_CLOUD ]]; then
26
+ SUBPROJECT=cloud
27
+ fi;
28
+
29
+ if [[ $SUBPROJECT ]]; then
30
+ PREFIX="--prefix $SUBPROJECT"
31
+ else
32
+ PREFIX=
33
+ fi;
34
+
35
+ if [[ $SUBSCRIPT == "start" ]]; then
36
+ # ensure dependencies are installed
37
+ npm $PREFIX ls || npm $PREFIX update
38
+ fi;
39
+
40
+ if [[ $SUBPROJECT ]]; then
41
+ if [[ ${npmCommands[$npm_lifecycle_event]} ]]; then
42
+ echo "Invoking $npm_lifecycle_event in $SUBPROJECT"
43
+ npm $PREFIX $npm_lifecycle_event
44
+ else
45
+ echo "Invoking $SUBSCRIPT in $SUBPROJECT"
46
+ npm $PREFIX run --if-present $SUBSCRIPT
47
+ fi;
48
+ else
49
+ echo "Invoking dev:$SUBSCRIPT"
50
+ npm run --if-present dev:$SUBSCRIPT
51
+ fi;
package/tmux.sh ADDED
@@ -0,0 +1,34 @@
1
+ #! /bin/bash
2
+
3
+ # usage: newWindow NAME COMMAND [DIRECTORY]
4
+ function newWindow() {
5
+ tmux new-window
6
+ run "$@"
7
+ }
8
+
9
+ # usage: run NAME COMMAND [DIRECTORY]
10
+ function run() {
11
+ tmux rename-window $1
12
+ if [[ $# > 2 ]]; then
13
+ tmux send "cd \"$3\"" C-m
14
+ fi;
15
+ tmux send "$2" C-m
16
+ }
17
+
18
+ # -----------------------------------
19
+
20
+ NAME=$(npm pkg get name)
21
+ NAME_UNQUOTED=${NAME//[\"\@]}
22
+ NAME_DOT=${NAME_UNQUOTED//\//\.}
23
+ VERSION=$(npm pkg get version)
24
+
25
+ BASENAME=$(basename $PWD)
26
+ echo -e "\033]0;$BASENAME\007"
27
+
28
+ tmux new-session -s "$BASENAME" -d
29
+ sleep 0.25
30
+ run "robot" "npx transitiveDev robot"
31
+ newWindow "web" "npx transitiveDev web"
32
+ newWindow "cloud" "npx transitiveDev cloud"
33
+
34
+ tmux a
@@ -0,0 +1,30 @@
1
+ #!/bin/bash
2
+
3
+ if [[ $# -lt 1 ]]; then
4
+ echo "need to provide command"
5
+ exit 1;
6
+ fi;
7
+
8
+ # echo $0
9
+ # DIR=$(dirname $0)
10
+ DIR=node_modules/@transitive-sdk/utils-caps
11
+
12
+ declare -A commands
13
+ commands[env]="env | sort"
14
+ commands[robot]="$DIR/rundev.sh"
15
+ commands[web]="node $DIR/esbuild.js"
16
+ commands[cloud]="$DIR/docker.sh"
17
+ commands[tmux]="$DIR/tmux.sh"
18
+
19
+ commands[prepack]="if [ ${npm_command} = 'publish' ] && [ ! $TRANSITIVEDEV ]; then echo -e '\033[33m*** Please use \"npx transitiveDev publish [prod]\"\n\n'; exit 1; fi";
20
+ commands[publish]="$DIR/publish.sh $2"
21
+
22
+ commands[all]="(${commands[robot]} | sed 's/^/\r🤖 /' ) & (${commands[web]} | sed 's/^/\r🌐 /') & (${commands[cloud]} | sed 's/^/\r☁️: /') & wait"
23
+
24
+ cmd=${commands[$1]}
25
+ if [[ -z $cmd ]]; then
26
+ echo "Unknown command: " $1
27
+ exit 2
28
+ fi;
29
+
30
+ bash -c "$cmd"