Skip to content

Commit d211925

Browse files
authored
Merge pull request #29 from ember-learn/windows-kill
Use "tree kill" on windows to stop servers
2 parents cf1354e + d062a7a commit d211925

File tree

5 files changed

+34
-20
lines changed

5 files changed

+34
-20
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,6 @@ Options:
417417

418418
Indicates a checkpoint where the following steps are performed:
419419

420-
* `yarn lint:hbs`
421-
* `yarn lint:js`
422420
* `yarn test`
423421
* Optionally, commit the current changes
424422
* Verify the git tree is clean (i.e. no dirty or untracked files)

src/lib/plugins/run-code-blocks/directives/checkpoint.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@ export default async function checkpoint(node: Code, options: Options): Promise<
2828
cwd = join(cwd, args.cwd);
2929
}
3030

31-
console.log(`$ yarn lint:hbs`);
32-
33-
await exec('yarn lint:hbs', { cwd });
34-
35-
console.log(`$ yarn lint:js`);
36-
37-
await exec('yarn lint:js', { cwd });
38-
3931
console.log(`$ yarn test`);
4032

4133
await exec('yarn test', { cwd });

src/lib/plugins/run-code-blocks/server.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { ChildProcess, spawn } from 'child_process';
22
import { Option, assert } from 'ts-std';
33

4+
const WINDOWS = process.platform === 'win32';
5+
46
export enum Status {
57
Starting = 'STARTING',
68
Started = 'STARTED',
@@ -58,7 +60,12 @@ export default class Server {
5860

5961
let { id, cmd, cwd } = this;
6062

61-
let process = this.process = spawn(cmd, { cwd, shell: true, detached: true });
63+
let process = this.process = spawn(cmd, {
64+
cwd,
65+
shell: true,
66+
// On Windows, if we set this to true, the stdio pipes do not work
67+
detached: !WINDOWS
68+
});
6269

6370
return new Promise<Option<string>>((resolveStart, rejectStart) => {
6471
let settled = false;
@@ -133,7 +140,8 @@ export default class Server {
133140

134141
let { status } = this;
135142

136-
if (status === Status.Stopping && (code === 0 || signal === 'SIGTERM')) {
143+
// On Windows, we can only forcefully terminate at the moment
144+
if (status === Status.Stopping && (WINDOWS || code === 0 || signal === 'SIGTERM')) {
137145
assert(didComplete !== null, 'didComplete must not be null');
138146
didComplete!();
139147
} else {
@@ -204,7 +212,7 @@ ${this.stderr || '(No output)'}
204212
assert(this.pid !== null, `Unknown pid for server \`${this.id}\``);
205213

206214
this.status = Status.Stopping;
207-
process.kill(-this.pid!);
215+
this.sendKill();
208216

209217
await this.promise;
210218
}
@@ -214,7 +222,7 @@ ${this.stderr || '(No output)'}
214222

215223
if (pid) {
216224
this.status = Status.Stopping;
217-
process.kill(-pid, 'SIGKILL');
225+
this.sendKill(true);
218226

219227
if (promise) {
220228
try {
@@ -225,4 +233,17 @@ ${this.stderr || '(No output)'}
225233
}
226234
}
227235
}
236+
237+
private sendKill(force = false) {
238+
assert(this.pid !== null, 'pid cannot be null');
239+
240+
let pid = this.pid!;
241+
242+
if (WINDOWS) {
243+
// On Windows, we can only forcefully terminate at the moment
244+
spawn('taskkill', ['/pid', `${pid}`, '/t', '/f']);
245+
} else {
246+
process.kill(-pid, force ? 'SIGKILL' : 'SIGTERM');
247+
}
248+
}
228249
}

src/markdown/tutorial/part-1/01-orientation.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@ If a version number is shown, you're ready to go.
3232

3333
We can create a new project using Ember CLI's `new` command. It follows the pattern `ember new <project-name>`. In our case, the project name would be `super-rentals`:
3434

35-
```run:command hidden=true
36-
# Hack: convince ember-cli we are really not in a project. Otherwise, we will get the "You cannot use the new command inside an ember-cli project." error when running `ember new`.
37-
echo "{}" > package.json
35+
```run:ignore
36+
Hack: make an empty package.json to convince ember-cli we are really not in an Ember project. Otherwise, we will get the "You cannot use the new command inside an ember-cli project." error when running `ember new`.
37+
```
38+
39+
```run:file:create hidden=true filename=package.json
40+
{}
3841
```
3942

4043
```run:command
@@ -221,7 +224,7 @@ tree super-rentals -a -I "node_modules|.git|yarn.lock|_redirects" --dirsfirst \
221224
!/package\.json/ { print }'
222225
223226
#[cfg(windows)]
224-
tree super-rentals /F
227+
npx --quiet tree-cli --base super-rentals --ignore node_modules --ignore .git --ignore yarn.lock --ignore _redirects --directoryFirst -a -l 99
225228
```
226229
227230
We'll learn about the purposes of these files and folders as we go. For now, just know that we'll spend most of our time working within the `app` folder.

src/markdown/tutorial/part-1/07-reusable-components.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ As its name implies, `config/environment.js` is used to *configure* our app and
3939
> If you prefer, you can [create different Mapbox access tokens](https://account.mapbox.com/access-tokens/) for use in different environments. At a minimum, the tokens will each need to have the "styles:tiles" scope in order to use Mapbox's static images API.
4040
4141
```run:command hidden=true cwd=super-rentals
42-
yarn test
42+
yarn ember test
4343
git add config/environment.js
4444
```
4545

@@ -52,7 +52,7 @@ git add config/environment.js
5252
```
5353

5454
```run:command hidden=true cwd=super-rentals
55-
yarn test
55+
yarn ember test
5656
git add config/environment.js
5757
```
5858

0 commit comments

Comments
 (0)