Skip to content

Commit 022d78f

Browse files
authored
Get scratchpad working with create script (#347)
* Add package.json * Run hook * run hook * mv back * use start.watch * add quickstart method * not global
1 parent 906cf9a commit 022d78f

20 files changed

+204
-13
lines changed

.scripts/copy-shared-files.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const TSCONFIG_EXCLUDE = [
2020
'nestjs-exchange-rates',
2121
'empty',
2222
'hello-world',
23+
'scratchpad',
2324
];
2425
const GITIGNORE_EXCLUDE = [
2526
'nextjs-ecommerce-oneclick',

scratchpad/.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
lib
3+
.eslintrc.js

scratchpad/.eslintrc.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const { builtinModules } = require('module');
2+
3+
const ALLOWED_NODE_BUILTINS = new Set(['assert']);
4+
5+
module.exports = {
6+
root: true,
7+
parser: '@typescript-eslint/parser',
8+
parserOptions: {
9+
project: './tsconfig.json',
10+
tsconfigRootDir: __dirname,
11+
},
12+
plugins: ['@typescript-eslint', 'deprecation'],
13+
extends: [
14+
'eslint:recommended',
15+
'plugin:@typescript-eslint/eslint-recommended',
16+
'plugin:@typescript-eslint/recommended',
17+
'prettier',
18+
],
19+
rules: {
20+
// recommended for safety
21+
'@typescript-eslint/no-floating-promises': 'error', // forgetting to await Activities and Workflow APIs is bad
22+
'deprecation/deprecation': 'warn',
23+
24+
// code style preference
25+
'object-shorthand': ['error', 'always'],
26+
27+
// relaxed rules, for convenience
28+
'@typescript-eslint/no-unused-vars': [
29+
'warn',
30+
{
31+
argsIgnorePattern: '^_',
32+
varsIgnorePattern: '^_',
33+
},
34+
],
35+
'@typescript-eslint/no-explicit-any': 'off',
36+
},
37+
overrides: [
38+
{
39+
files: ['src/workflows.ts', 'src/workflows-*.ts', 'src/workflows/*.ts'],
40+
rules: {
41+
'no-restricted-imports': [
42+
'error',
43+
...builtinModules.filter((m) => !ALLOWED_NODE_BUILTINS.has(m)).flatMap((m) => [m, `node:${m}`]),
44+
],
45+
},
46+
},
47+
],
48+
};

scratchpad/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lib
2+
node_modules

scratchpad/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

scratchpad/.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
16

scratchpad/.post-create

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ Start Temporal Server:
77

88
{cyan temporal server start-dev}
99

10-
Install ts-node: https://www.npmjs.com/package/ts-node
10+
Use Node version 16+:
1111

12-
Then, in the project directory, install the Temporal SDK and run scratchpad.ts:
12+
Mac: {cyan brew install node@16}
13+
Other: https://nodejs.org/en/download/
1314

14-
{cyan npm install temporalio}
15-
{cyan ts-node scratchpad.ts}
15+
Then, in the project directory, run scratchpad.ts:
16+
17+
{cyan npm run start.watch}

scratchpad/.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lib

scratchpad/.prettierrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
printWidth: 120
2+
singleQuote: true

scratchpad/README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@
33
This sample demonstrates a minimalistic single-file style that might be useful for quickly sketching out an idea, or for sharing a minimal reproduction of a bug.
44
Production code should not be arranged like this! See the other samples in this repo for recommended project structure.
55

6-
### Running this sample
6+
### Quickstart
77

8-
In one terminal:
8+
To get started quickly without cloning:
99

10-
```
11-
temporal server start-dev
10+
```sh
11+
npm i ts-node temporalio
12+
curl -sOL https://raw.githubusercontent.com/temporalio/samples-typescript/main/scratchpad/scratchpad.ts
13+
ts-node scratchpad.ts
1214
```
1315

14-
In another terminal:
16+
### Watch changes
1517

16-
```
17-
npm install temporalio
18-
ts-node scratchpad.ts
19-
```
18+
If you've cloned this repo locally, you can run:
19+
20+
1. `temporal server start-dev` to start [Temporal Server](https://github.com/temporalio/cli/#installation).
21+
1. `npm install` to install dependencies.
22+
1. `npm run start.watch` to run the single file, [`scratchpad.ts`](scratchpad.ts).
2023

2124
The following will be printed out:
2225

0 commit comments

Comments
 (0)