Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions bin/import-agent-from
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env sh

function help {
msg="$(cat <<-EOF
This repository is the new home for the @dfinity/agent npm package.
This script will take a path to its old home in the sdk, then copy it here to ./packages/agent w/ any transformations required as part of the 'move'.

Usage:
./import-agent-from ~/dfinity/sdk/src/agent/javascript

EOF)"
echo "$msg"
}

function main {
agent_target="$(dirname $0)"/../packages/agent
agent_src="$1"
if [[ -z "$agent_src" ]]; then
help
echo
echo "Error: Provide a path to the sdk agent directory to import from there"
exit 1
fi
# Warning
rm -rf "$agent_target"
cp -a "$agent_src" "$agent_target"
# Remove files we dont need
find "$agent_target" -name '*INTERNAL*' | xargs rm
find "$agent_target" -name '*.nix' | xargs rm
}

main $@
36 changes: 36 additions & 0 deletions bin/import-bootstrap-from
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env sh

function help {
msg="$(cat <<-EOF
This repository is the new home for the @dfinity/bootstrap npm package.
This script will take a path to its old home in the sdk, then copy it here to ./packages/bootstrap w/ any transformations required as part of the 'move'.

Usage:
./import-bootstrap-from ~/dfinity/sdk/src/bootstrap

EOF)"
echo "$msg"
}

function main {
bootstrap_target="$(dirname $0)"/../packages/bootstrap
bootstrap_src="$1"
if [[ -z "$bootstrap_src" ]]; then
help
echo
echo "Error: Provide a path to the sdk bootstrap directory to import from there"
exit 1
fi

# Warning
rm -rf "$bootstrap_target"

cp -a "$bootstrap_src" "$bootstrap_target"

# Remove files we dont want
find "$bootstrap_target" -name '*INTERNAL*' | xargs rm
find "$bootstrap_target" -name '*.nix' | xargs rm
echo "test.todo('@dfinity/bootstrap has tests');" > "$bootstrap_target"/src/index.test.ts
}

main $@
18 changes: 18 additions & 0 deletions packages/bootstrap/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
build_info.json
node_modules/
dist/
ts-out/
**/*.js
**/*.js.map
**/*.d.ts

# Cannot ignore candid.js, the last bastion of JS code in our app.
!src/candid/candid.js

# Cannot ignore .d.ts files in types/
!types/**/*.d.ts

# Cannot ignore setup files for webpack and jest, which are still JavaScript.
!webpack.config.js
!jest.config.js
!test-setup.js
11 changes: 11 additions & 0 deletions packages/bootstrap/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"trailingComma": "all",
"tabWidth": 2,
"printWidth": 100,
"semi": true,
"bracketSpacing": true,
"useTabs": false,
"singleQuote": true,
"quoteProps": "consistent",
"arrowParens": "avoid"
}
46 changes: 46 additions & 0 deletions packages/bootstrap/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
= Bootstrap Server

== How to Run Locally

Locally in your sdk repo, execute:

. `npm install`. To install all Node dependencies.
. `npm run webpack -- --watch` will start webpack in watch mode.
. In two separate terminals in a DFX project (create one if needed);
.. Start a `dfx replica`.
.. Start `dfx bootstrap --root $SDK_REPO_PATH/src/bootstrap/dist/ --providers http://localhost:8080 --port 8000`.
. Open your browser to `http://localhost:8000`. Change code, wait a few seconds for webpack to
build, reload browser.

If you need HTTPs (for example, using lvh or ic0.app using redirects), you will need to setup
your own nginx reverse proxy. Look up instructions online.

**Note that HTTPS is needed for the crypto API if you're accessing a non-localhost URL. This is
a limitation of the web API (see
https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts/features_restricted_to_secure_contexts[
the MDN documentation])**.



== Startup Process
. The bootstrap server determines which worker host it is using;
.. If there is a query param `workerHost`, use that value.
.. If there is a `dfinity-ic-host` value in local storage, uses that value.
.. If the host ends with `localhost` and contains more than 1 subdomain, use `dfinity.localhost`.
_This is used to test cross-domain worker._
.. If the host ends with `lvh.me`, use `dfinity.lvh.me`. _This is used to test cross-domain worker._
.. If the host ends with `ic0.app`, use `dfinity.ic0.app`.
.. Otherwise, don't use a worker (this is for localhost and development purposes).

. The bootstrap server determines the canister ID;
.. If there is a query param for `canisterId`, decode that value as text.
.. If there is a `dfinity-canister-id` value in local storage, uses that value.
.. If the host ends with `lvh.me`, split the host and use the first subdomain before
`ic0.app`. For example, `some-sub.01234567.lvh.me` would result in `01234567`.
_This is used to test cross-domain worker._
.. If the host ends with `ic0.app`, split the host and use the first subdomain before
`ic0.app`. For example, `some-sub.01234567.ic0.app` would result in `01234567`.
.. Otherwise, show a UI for the user to enter a canister ID.

. Create a worker with `${workerHost}/worker.js` using the same protocol.
. Get the canister's `/index.js` through the worker.
Loading