Skip to content

Commit

Permalink
initial setup
Browse files Browse the repository at this point in the history
  • Loading branch information
HipsterBrown committed Dec 1, 2021
0 parents commit 9394614
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2021 Nicholas Hehr

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Setup CLI for [Moddable XS tools](https://github.com/Moddable-OpenSource/moddable/blob/public/documentation/Moddable%20SDK%20-%20Getting%20Started.md)

The Moddable SDK and associated dev board tooling is incredibly empowering for embedded JS hardware development, however the set up process can be tedious to follow when getting started. This project aims to streamline the install and environment configuration requirements across platforms in just a few commands.

**Feature support:**

- [X] Moddable SDK install & setup

**Platform support:**

- [X] Mac
- [ ] Windows
- [ ] Linux

## Usage

Globally install [`zx`](https://github.com/google/zx) before running the script.

Clone this repo and `cd` into the directory:

```
git clone https://github.com/HipsterBrown/xs-setup && cd xs-setup
```

Run script:

```
./xs-setup.mjs
```
57 changes: 57 additions & 0 deletions xs-setup.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env zx

const MODDABLE_REPO = "https://github.com/Moddable-OpenSource/moddable";
const HOME_DIR = os.homedir();
const INSTALL_DIR = path.resolve(HOME_DIR, ".local", "share");
const INSTALL_PATH = path.resolve(INSTALL_DIR, 'moddable');
const BIN_PATH = path.resolve(INSTALL_PATH, 'build', 'bin', 'mac', 'release')
const exec = $;

// 1. clone moddable repo into ./local/share directory if it does not exist yet

try {
await fs.ensureDir(INSTALL_DIR);
} catch (error) {
console.error(chalk.red("Error setting up install directory: ", error));
}

if (await fs.pathExists(INSTALL_PATH)) {
console.log(chalk.blue("Moddable repo already installed"))
} else {
try {
await exec`git clone ${MODDABLE_REPO} ${INSTALL_PATH}`
} catch (error) {
console.log(chalk.red("Error cloning moddable repo: "), error)
}
}

// 2. determine shell profile (i.e. .profile or .zshrc)
const PROFILE = await (async function () {
const shell = process.env.SHELL || await exec`echo $0`;
if (shell.includes('zsh')) return '.zshrc';
return '.profile';
})()
const PROFILE_PATH = path.resolve(HOME_DIR, PROFILE);

await fs.ensureFile(PROFILE_PATH);
console.log(chalk.blue(`Using ${PROFILE} environment config`))

// 3. configure MODDABLE env variable, add release binaries dir to PATH
if (!process.env.MODDABLE) {
process.env.MODDABLE = INSTALL_PATH
process.env.PATH += BIN_PATH

await exec`echo 'export MODDABLE=${process.env.MODDABLE}' >> ${PROFILE_PATH}`
await exec`echo 'export PATH="${BIN_PATH}:$PATH"' >> ${PROFILE_PATH}`
}

// 4. cd into makefiles dir for platform, run `make`
cd(path.resolve(INSTALL_PATH, 'build', 'makefiles', 'mac'));
await exec`make`.pipe(process.stdout)

// 5. symlink xsbug.app into user applications directory
try {
await fs.ensureSymlink(path.resolve(INSTALL_PATH, 'build', 'bin', 'mac', 'release', 'xsbug.app'), '/Applications/xsbug.app')
} catch (error) {
console.log(chalk.red("Issue creating symlink for xsbug.app: ", error))
}

0 comments on commit 9394614

Please sign in to comment.