Skip to content

Commit

Permalink
fix(install): update development installer for npm workspaces
Browse files Browse the repository at this point in the history
* Fix/npm workspaces

- Remove npm run bootstrap
- Fix typos and grammar in README using <https://languagetool.org/>
- Change test/uninstall/index.ts ls 35 because of change in api calls

Signed-off-by: Tim_Tech_Dev <Tim_Tech_Dev@protonmail.com>

* Implemented Requested Changes

- Inline boolean in src/install/index
- Remove version check in src/install/dev
- Change `createDevInstall` test respectively

Signed-off-by: Tim_Tech_Dev <Tim_Tech_Dev@protonmail.com>
  • Loading branch information
TimTechDev authored Oct 23, 2021
1 parent 34b37a0 commit 42b68fb
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 27 deletions.
32 changes: 16 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# nodecg-io-cli
<!-- prettier-ignore-end -->

This is the cli for [nodecg-io](https://github.com/codeoverflow-org/nodecg-io) that allows you to easily manage your nodecg-io installation and helps you with nodecg-io related development.
This is the CLI for [nodecg-io](https://github.com/codeoverflow-org/nodecg-io) that allows you to easily manage your nodecg-io installation and helps you with nodecg-io related development.

## Table of contents

Expand All @@ -21,46 +21,46 @@ This is the cli for [nodecg-io](https://github.com/codeoverflow-org/nodecg-io) t

## Commands

Here's a brief overview of the available commands. More indepth usage guides of these commands will be available in the [nodecg-io docs](https://nodecg.io) at some point.
Here's a brief overview of the available commands. More in-depth usage guides of these commands will be available in the [nodecg-io docs](https://nodecg.io) at some point.

### `nodecg-io install`

Installs nodecg-io to your current nodecg installation into a sub-directory called `nodecg-io`. Allows you to select which released version you want or if you wish to get a development install.
Installs nodecg-io to your current NodeCG installation into a subdirectory called `nodecg-io`. Allows you to select which released version you want or if you wish to get a development install.

A production install fetches tarballs of the needed packages from the official npm registry, unpacks them, creates a `package.json` with all packages in a npm v7 workspace configuration and installs dependencies that way.

A development install clones the official git repository (`master`), installs dependencies, bootstraps all packages using lerna and builds all packages.
A development install clones the official git repository (`master`), installs dependencies builds all packages.

Either way at the end of the installation it will automatically add the nodecg-io directory (and samples if dev install and selected) to the `bundles.paths` array of your nodecg configuration. If you don't have a nodecg configuration it will create one for you.
Either way at the end of the installation it will automatically add the nodecg-io directory (and samples if dev install and selected) to the `bundles.paths` array of your NodeCG configuration. If you don't have a NodeCG configuration it will create one for you.

If you later decide that you want to add or remove a service you can just re-run `nodecg-io install`. It saves your choices and makes them the default selected if you already have a installation so you can make changes to them. If you re-run the install command it will also pull the repo and rebuild if necessary in case of a development install and, in case of a production install, it will make any updates if some packages have a new patch version available. Updates of minor and major changes must be made explicitly by selecting the newer version when running the install command.
If you later decide that you want to add or remove a service you can just re-run `nodecg-io install`. It saves your choices and makes them the default selected if you already have an installation, so you can make changes to them. If you re-run the `install` command it will also pull the repo and rebuild if necessary. In case of a development install and, in case of a production install, it will make any updates if some packages have a new patch version available. Updates of minor and major changes must be made explicitly by selecting the newer version when running the `install` command.

### `nodecg-io uninstall`

Undos everything that `nodecg-io install` did. It removes the `nodecg-io` directory with your installation and removes nodecg-io from your nodecg configuration.
Undoes everything that `nodecg-io install` did. It removes the `nodecg-io` directory with your installation and removes nodecg-io from your NodeCG configuration.

### `nodecg-io generate`

Generates a new bundle in the `bundles/` directory in your nodecg installation.
Allows you to decide on language (typescript or javascript), whether you want a dashboard/graphic and which services you want to use.
Generates a new bundle in the `bundles/` directory in your NodeCG installation.
Allows you to decide on language (TypeScript or JavaScript), whether you want a dashboard/graphic and which services you want to use.
Uses your installed nodecg-io version and services, meaning you need to have the services that you want to use installed.

These generated bundles are only meant as a starting point, you may probably do more things like creating a git repository for your bundle,
add a license, or add other tools like linters.
add a licence, or add other tools like linters.

Also this command currently only works with installs of released versions and not with development installs. This is because all bundles using nodecg-io depend on `nodecg-io-core` and if you use typescript each used service as well. For development installs these are not published on npm and you would need some way of linking the packages locally.
Also, this command currently only works with installs of released versions and not with development installs. This is because all bundles using nodecg-io depend on `nodecg-io-core` and if you use typescript each used service as well. For development installs these are not published on npm, and you would need some way of linking the packages locally.

## A note about versioning

This cli follows and is versioned independently from the rest of nodecg-io like `nodecg-io-core` or the services.
This CLI follows and is versioned independently of the rest of nodecg-io like `nodecg-io-core` or the services.

The following table show which versions of the cli are compatible with which nodecg-io versions:
The following table show which versions of the CLI are compatible with which nodecg-io versions:

| CLI versions | nodecg-io versions |
| ------------ | ------------------ |
| `0.1` | `0.1` |

Currently they are the same but we will follow [semver2](https://semver.org/) using [semantic-release](https://semantic-release.gitbook.io/semantic-release/) and the versions will diverge at some point.
Currently, they are the same, but we will follow [semver2](https://semver.org/) using [semantic-release](https://semantic-release.gitbook.io/semantic-release/) and the versions will diverge at some point.

## Developer workflow

Expand All @@ -73,10 +73,10 @@ $ npm i
$ npm run build
```

Then link your current local install of the cli to your global `node_modules` directory (might require `sudo` on linux):
Then link your current local installation of the CLI to your global `node_modules` directory (might require `sudo` on linux):

```console
$ npm link
```

You can now use the `nodecg-io` command and it will use your local install. You DO NOT need to rerun the link command after you make changes to the cli, unless you move it another location. While developing you may want to start a TypeScript watcher by running `npm run watch` that will automatically update the JS files that are used while you make changes.
You can now use the `nodecg-io` command, and it will use your local install. You DO NOT need to rerun the link command after you make changes to the CLI, unless you move it another location. While developing you may want to start a TypeScript watcher by running `npm run watch` that will automatically update the JS files that are used while you make changes.
9 changes: 3 additions & 6 deletions src/install/development.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as chalk from "chalk";
import * as git from "isomorphic-git";
import * as fs from "fs";
import * as http from "isomorphic-git/http/node";
import { directoryExists, executeCommand, removeDirectory } from "../utils/fs";
import { directoryExists, removeDirectory } from "../utils/fs";
import { DevelopmentInstallation, writeInstallInfo } from "../utils/installation";
import { logger } from "../utils/log";
import * as path from "path";
Expand Down Expand Up @@ -175,12 +175,9 @@ function getGitCommitHash(dir: string): Promise<string> {
}

async function installNPMDependencies(nodecgIODir: string) {
logger.info("Installing npm dependencies and bootstrapping...");

logger.info("Installing npm dependencies...");
await runNpmInstall(nodecgIODir, false);
await executeCommand("npm", ["run", "bootstrap"], nodecgIODir);

logger.info("Installed npm dependencies and bootstrapped.");
logger.info("Installed npm dependencies.");
}

async function buildTypeScript(nodecgIODir: string, concurrency: number) {
Expand Down
1 change: 1 addition & 0 deletions src/install/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ async function install(concurrency: number): Promise<void> {

// Add bundle dirs to the nodecg config, so that they are loaded.
await manageBundleDir(nodecgDir, nodecgIODir, true);
await manageBundleDir(nodecgDir, path.join(nodecgIODir, "services"), requestedInstall.version !== "0.1");
await manageBundleDir(
nodecgDir,
path.join(nodecgIODir, "samples"),
Expand Down
1 change: 1 addition & 0 deletions src/uninstall/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export async function uninstall(): Promise<void> {

// Remove bundle dirs from nodecg configuration
await manageBundleDir(nodecgDir, nodecgIODir, false);
await manageBundleDir(nodecgDir, path.join(nodecgIODir, "services"), false);
await manageBundleDir(nodecgDir, path.join(nodecgIODir, "samples"), false);

// Delete directory
Expand Down
4 changes: 2 additions & 2 deletions test/install/development.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ describe("createDevInstall", () => {
expect(execSpy).toHaveBeenCalledTimes(0);
});

test("should execute install, bootstrap and build", async () => {
test("should execute install and build", async () => {
fetchSpy.mockResolvedValueOnce(altFetchResult);
await dev.createDevInstall(validDevInstall, fsRoot, 0);
expect(execSpy).toHaveBeenCalledTimes(3);
expect(execSpy).toHaveBeenCalledTimes(2);
});

test("should not clone docs if not wanted in installation info", async () => {
Expand Down
7 changes: 4 additions & 3 deletions test/uninstall/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ describe("uninstall", () => {
await vol.promises.mkdir(nodecgIODir);
await uninstall();

expect(spyManageBundleDir).toHaveBeenCalledTimes(2);
expect(spyManageBundleDir).toBeCalledTimes(3);

// Should remove nodecg-io directory and sample bundle directory (if applicable)
expect(spyManageBundleDir.mock.calls[0][1]).toBe(nodecgIODir);
expect(spyManageBundleDir.mock.calls[1][1]).toBe(path.join(nodecgIODir, "samples"));

expect(spyManageBundleDir.mock.calls[1][1]).toBe(path.join(nodecgIODir, "services"));
expect(spyManageBundleDir.mock.calls[2][1]).toBe(path.join(nodecgIODir, "samples"));
// Should remove them, not add them
expect(spyManageBundleDir.mock.calls[0][2]).toBe(false);
expect(spyManageBundleDir.mock.calls[1][2]).toBe(false);
expect(spyManageBundleDir.mock.calls[2][2]).toBe(false);
});

test("should remove nodecg-io directory", async () => {
Expand Down

0 comments on commit 42b68fb

Please sign in to comment.