Skip to content

Commit 5316360

Browse files
authored
Merge pull request #83 from neuroglia-io/packaging
Packaging / Publishing
2 parents 6de17ec + c5ef39b commit 5316360

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+440
-240
lines changed

README.md

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44

55
Provides the Typescript API/SPI for the [Serverless Workflow Specification](https://github.com/serverlessworkflow/specification)
66

7-
87
With the SDK you can:
98
* Parse workflow JSON and YAML definitions
109
* Programmatically build workflow definitions
1110
* Validate workflow definitions
1211

13-
## Getting Started
1412

13+
## Getting Started
1514

1615
### Building locally
1716

@@ -53,7 +52,8 @@ It will create a symbolic link from globally-installed `sdk-typescript` to `node
5352
#### Create Workflow using builder API
5453

5554
```typescript
56-
const workflow = workflowBuilder()
55+
56+
const workflow: Specification.Workflow = workflowBuilder()
5757
.id("helloworld")
5858
.version("1.0")
5959
.name("Hello World Workflow")
@@ -70,6 +70,30 @@ const workflow = workflowBuilder()
7070
.build();
7171
```
7272

73+
74+
#### Create Workflow using object literals
75+
76+
```typescript
77+
const workflow: Specification.Workflow = {
78+
id: 'helloworld',
79+
version: '1.0',
80+
name: 'Hello World Workflow',
81+
description: 'Inject Hello World',
82+
start: 'Hello State',
83+
states: [
84+
{
85+
type: 'inject',
86+
name: 'Hello State',
87+
end: true,
88+
data: {
89+
result: "Hello World!"
90+
}
91+
} as Specification.Injectstate
92+
]
93+
};
94+
```
95+
96+
7397
#### Load a file JSON/YAML to a Workflow instance
7498

7599
```typescript
@@ -78,7 +102,6 @@ const workflow = workflowBuilder()
78102
Where `source` is a JSON or a YAML string.
79103

80104

81-
82105
#### Parse a Workflow instance to JSON/YAML
83106

84107
Having the following workflow instance:
@@ -112,6 +135,7 @@ by using the static methods `toJson` or `toYaml` respectively:
112135
const workflowAsYaml = WorkflowConverter.toYaml(workflow);
113136
```
114137

138+
115139
#### Validate workflow definitions
116140

117141
The sdk provides a way to validate if a workflow object is compliant with the serverlessworkflow specification.

examples/browser/index.html

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Serveless Workflow JS SDK</title>
6+
<base href="/">
7+
<meta name="viewport" content="width=device-width, initial-scale=1">
8+
</head>
9+
<body>
10+
<!--
11+
Run http-server from the project root then navigate to http://localhost:8080/examples/browser/index.html
12+
-->
13+
<div id="output"></div>
14+
<script src="../../dist/umd/index.umd.js"></script>
15+
<script type="text/javascript">
16+
(() => {
17+
const { workflowBuilder, injectstateBuilder } = serverWorkflowSdk;
18+
const outputDiv = document.getElementById('output');
19+
const workflow = workflowBuilder()
20+
.id("helloworld")
21+
.version("1.0")
22+
.name("Hello World Workflow")
23+
.description("Inject Hello World")
24+
.start("Hello State")
25+
.states([
26+
injectstateBuilder()
27+
.name("Hello State")
28+
.data({
29+
"result": "Hello World!"
30+
})
31+
.end(true)
32+
.build()
33+
])
34+
.build();
35+
outputDiv.innerHTML = workflow.id;
36+
})();
37+
</script>
38+
</body>
39+
</html>

examples/node/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const { workflowBuilder, injectstateBuilder } = require('../../dist');
2+
const workflow = workflowBuilder()
3+
.id("helloworld")
4+
.version("1.0")
5+
.name("Hello World Workflow")
6+
.description("Inject Hello World")
7+
.start("Hello State")
8+
.states([
9+
injectstateBuilder()
10+
.name("Hello State")
11+
.data({
12+
"result": "Hello World!"
13+
})
14+
.end(true)
15+
.build()
16+
])
17+
.build();
18+
console.log(workflow.id);

examples/node/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { workflowBuilder, injectstateBuilder, Specification } from '../../dist';
2+
const workflow: Specification.Workflow = workflowBuilder()
3+
.id("helloworld")
4+
.version("1.0")
5+
.name("Hello World Workflow")
6+
.description("Inject Hello World")
7+
.start("Hello State")
8+
.states([
9+
injectstateBuilder()
10+
.name("Hello State")
11+
.data({
12+
"result": "Hello World!"
13+
})
14+
.end(true)
15+
.build()
16+
])
17+
.build();
18+
console.log(workflow.id);

examples/node/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "../../tsconfig.base.json"
3+
}

package-lock.json

Lines changed: 105 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,27 @@
33
"version": "0.6.0",
44
"description": "Typescript SDK for Serverless Workflow Specification",
55
"main": "umd/index.umd.min.js",
6+
"browser": "umd/index.umd.min.js",
67
"module": "esm/index.esm.min.js",
7-
"typings": "serverless-workflow-sdk.d.ts",
8+
"typings": "index.d.ts",
89
"scripts": {
910
"rimraf": "npx rimraf",
11+
"shx": "npx shx",
1012
"tsc": "npx tsc",
1113
"ts-node": "npx ts-node",
12-
"prebuild": "rimraf dist",
13-
"build": "rollup -c rollup.config.ts",
14-
"clean": "rimraf dist && rimraf out-tsc",
15-
"tools:download-schemas": "ts-node --project tsconfig.tools.json ./tools/download-schemas.ts",
16-
"tools:generate-definitions": "ts-node --project tsconfig.tools.json ./tools/generate-definitions.ts",
17-
"tools:generate-builders": "ts-node --project tsconfig.tools.json ./tools/generate-builders.ts",
14+
"clean": "npx rimraf dist && rimraf out-tsc",
15+
"tools:download-schemas": "npx ts-node --project ./tools/tsconfig.json ./tools/download-schemas.ts",
16+
"tools:generate-definitions": "npx ts-node --project ./tools/tsconfig.json ./tools/generate-definitions.ts",
17+
"tools:generate-builders": "npx ts-node --project ./tools/tsconfig.json ./tools/generate-builders.ts",
1818
"update-code-base": "npm run tools:download-schemas && npm run tools:generate-definitions && npm run tools:generate-builders",
19-
"pretest": "rimraf out-tsc",
20-
"test": "tsc --project tsconfig.spec.json && jasmine --config=./tests/support/jasmine.json"
19+
"pretest": "npx rimraf out-tsc",
20+
"test": "npx tsc --project ./tests/tsconfig.json && npx jasmine --config=./tests/support/jasmine.json",
21+
"prebuild": "npx rimraf dist",
22+
"build": "npx rollup -c rollup.config.ts",
23+
"postbuild": "npx shx cp ./package.json ./README.md ./LICENSE ./dist/",
24+
"verify-publish-directory": "node -e 'if (!process.cwd().endsWith(\"dist\")) { console.error(\"Packaging/Publishing should be done from ./dist/\"); process.exitCode = 1; } process.exit();'",
25+
"prepack": "npm run verify-publish-directory",
26+
"prepublishOnly": "npm run verify-publish-directory"
2127
},
2228
"dependencies": {
2329
"ajv": "^8.1.0",
@@ -42,6 +48,7 @@
4248
"rollup-plugin-sourcemaps": "^0.6.3",
4349
"rollup-plugin-terser": "^7.0.2",
4450
"rollup-plugin-typescript2": "^0.30.0",
51+
"shx": "^0.3.3",
4552
"ts-node": "^9.1.1",
4653
"typescript": "^4.2.4",
4754
"yargs": "^17.0.1"
@@ -59,9 +66,6 @@
5966
"url": "https://github.com/serverlessworkflow/sdk-typescript/issues"
6067
},
6168
"homepage": "https://serverlessworkflow.io",
62-
"files": [
63-
"dist/*"
64-
],
6569
"engines": {
6670
"node": ">=15.0",
6771
"npm": ">=7.0.0"

0 commit comments

Comments
 (0)