@temporalio/create
Advanced tools
Comparing version 0.3.4 to 0.4.0
131
lib/index.js
@@ -13,3 +13,4 @@ #!/usr/bin/env node | ||
const command = '@temporalio/create'; | ||
const typescriptVersion = '4.2.2'; | ||
const typescriptVersion = '4.4.2'; | ||
const nodeMajorVersion = parseInt(process.versions.node, 10); | ||
const npm = /^win/.test(process.platform) ? 'npm.cmd' : 'npm'; | ||
@@ -20,12 +21,24 @@ const packageJsonBase = { | ||
scripts: { | ||
build: 'tsc --build src/worker/tsconfig.json', | ||
'build.watch': 'tsc --build --watch src/worker/tsconfig.json', | ||
start: 'node lib/worker', | ||
build: 'tsc --build', | ||
'build.watch': 'tsc --build --watch', | ||
start: 'ts-node src/worker.ts', | ||
'start.watch': 'nodemon src/worker.ts', | ||
workflow: 'ts-node src/exec-workflow.ts', | ||
}, | ||
devDependencies: { | ||
typescript: `^${typescriptVersion}`, | ||
'@tsconfig/node14': '^1.0.0', | ||
[`@tsconfig/node${nodeMajorVersion}`]: '^1.0.0', | ||
'ts-node': '^10.2.1', | ||
nodemon: '^2.0.12', | ||
}, | ||
nodemonConfig: { | ||
watch: ['src'], | ||
ext: 'ts', | ||
execMap: { | ||
ts: 'ts-node', | ||
}, | ||
}, | ||
}; | ||
const tsConfigSharedBase = { | ||
const tsConfig = { | ||
extends: `@tsconfig/node${nodeMajorVersion}/tsconfig.json`, | ||
version: typescriptVersion, | ||
@@ -39,42 +52,8 @@ compilerOptions: { | ||
composite: true, | ||
incremental: true, | ||
rootDir: '.', | ||
rootDir: './src', | ||
outDir: './lib', | ||
}, | ||
include: ['./**/*.ts'], | ||
include: ['src/**/*.ts'], | ||
exclude: ['node_modules'], | ||
}; | ||
const tsConfigBase = { | ||
extends: '@tsconfig/node14/tsconfig.json', | ||
...tsConfigSharedBase, | ||
}; | ||
const workflowsTsConfig = { | ||
...tsConfigBase, | ||
compilerOptions: { | ||
...tsConfigSharedBase.compilerOptions, | ||
lib: [ | ||
// es2015.collection excluded because it defines WeakMap and WeakSet | ||
'es5', | ||
'es2015.core', | ||
'es2015.generator', | ||
'es2015.iterable', | ||
'es2015.promise', | ||
'es2015.proxy', | ||
'es2015.reflect', | ||
'es2015.symbol', | ||
'es2015.symbol.wellknown', | ||
'es2016.array.include', | ||
'es2017.object', | ||
'es2017.intl', | ||
'es2017.sharedmemory', | ||
'es2017.string', | ||
'es2017.typedarrays', | ||
], | ||
typeRoots: ['.'], | ||
outDir: '../../lib/workflows', | ||
paths: { | ||
'@activities': ['../activities'], | ||
'@activities/*': ['../activities/*'], | ||
}, | ||
}, | ||
references: [{ path: '../activities/tsconfig.json' }, { path: '../interfaces/tsconfig.json' }], | ||
}; | ||
/** | ||
@@ -84,8 +63,8 @@ * Copy sample from `source` to `target` stripping away snipsync comments | ||
async function copySample(source, target) { | ||
const code = await fs_extra_1.readFile(source, 'utf8'); | ||
const code = await (0, fs_extra_1.readFile)(source, 'utf8'); | ||
const stripped = code.replace(/.*@@@SNIP(START|END).*\n/gm, ''); | ||
await fs_extra_1.writeFile(target, stripped); | ||
await (0, fs_extra_1.writeFile)(target, stripped); | ||
} | ||
async function writePrettyJson(path, obj) { | ||
await fs_extra_1.writeFile(path, JSON.stringify(obj, null, 2) + os_1.default.EOL); | ||
await (0, fs_extra_1.writeFile)(path, JSON.stringify(obj, null, 2) + os_1.default.EOL); | ||
} | ||
@@ -104,11 +83,11 @@ class UsageError extends Error { | ||
if (this.connectionVariant === 'default') { | ||
await copySample(path_1.default.join(sampleDir, 'worker.ts'), path_1.default.join(targetDir, 'worker', 'index.ts')); | ||
await copySample(path_1.default.join(sampleDir, 'client.ts'), path_1.default.join(targetDir, 'worker', 'schedule-workflow.ts')); | ||
await copySample(path_1.default.join(sampleDir, 'worker.ts'), path_1.default.join(targetDir, 'worker.ts')); | ||
await copySample(path_1.default.join(sampleDir, 'client.ts'), path_1.default.join(targetDir, 'exec-workflow.ts')); | ||
} | ||
else if (this.connectionVariant === 'mtls') { | ||
await copySample(path_1.default.join(sampleDir, 'mtls-env.ts'), path_1.default.join(targetDir, 'worker', 'mtls-env.ts')); | ||
await copySample(path_1.default.join(sampleDir, 'worker-mtls.ts'), path_1.default.join(targetDir, 'worker', 'index.ts')); | ||
await copySample(path_1.default.join(sampleDir, 'client-mtls.ts'), path_1.default.join(targetDir, 'worker', 'schedule-workflow.ts')); | ||
await copySample(path_1.default.join(sampleDir, 'mtls-env.ts'), path_1.default.join(targetDir, 'mtls-env.ts')); | ||
await copySample(path_1.default.join(sampleDir, 'worker-mtls.ts'), path_1.default.join(targetDir, 'worker.ts')); | ||
await copySample(path_1.default.join(sampleDir, 'client-mtls.ts'), path_1.default.join(targetDir, 'exec-workflow.ts')); | ||
} | ||
await copySample(path_1.default.join(sampleDir, 'activity.ts'), path_1.default.join(targetDir, 'activities', 'greeter.ts')); | ||
await copySample(path_1.default.join(sampleDir, 'activity.ts'), path_1.default.join(targetDir, 'activities.ts')); | ||
await copySample(path_1.default.join(sampleDir, 'workflow.ts'), path_1.default.join(targetDir, 'workflows', 'example.ts')); | ||
@@ -131,35 +110,9 @@ await copySample(path_1.default.join(sampleDir, 'interface.ts'), path_1.default.join(targetDir, 'interfaces', 'workflows.ts')); | ||
const name = path_1.default.basename(root); | ||
await fs_extra_1.mkdir(root); | ||
await (0, fs_extra_1.mkdir)(root); | ||
const packageJson = { ...packageJsonBase, name }; | ||
await writePrettyJson(path_1.default.join(root, 'package.json'), packageJson); | ||
await fs_extra_1.mkdir(src); | ||
await fs_extra_1.mkdir(path_1.default.join(src, 'interfaces')); | ||
await fs_extra_1.mkdir(path_1.default.join(src, 'workflows')); | ||
await fs_extra_1.mkdir(path_1.default.join(src, 'activities')); | ||
await fs_extra_1.mkdir(path_1.default.join(src, 'worker')); | ||
await writePrettyJson(path_1.default.join(src, 'interfaces', 'tsconfig.json'), { | ||
...tsConfigBase, | ||
compilerOptions: { ...tsConfigBase.compilerOptions, outDir: '../../lib/interfaces' }, | ||
}); | ||
await writePrettyJson(path_1.default.join(src, 'workflows', 'tsconfig.json'), workflowsTsConfig); | ||
await writePrettyJson(path_1.default.join(src, 'activities', 'tsconfig.json'), { | ||
...tsConfigBase, | ||
compilerOptions: { | ||
...tsConfigBase.compilerOptions, | ||
outDir: '../../lib/activities', | ||
}, | ||
references: [{ path: '../interfaces/tsconfig.json' }], | ||
}); | ||
await writePrettyJson(path_1.default.join(src, 'worker', 'tsconfig.json'), { | ||
...tsConfigBase, | ||
compilerOptions: { | ||
...tsConfigBase.compilerOptions, | ||
outDir: '../../lib/worker', | ||
}, | ||
references: [ | ||
{ path: '../interfaces/tsconfig.json' }, | ||
{ path: '../activities/tsconfig.json' }, | ||
{ path: '../workflows/tsconfig.json' }, | ||
], | ||
}); | ||
await (0, fs_extra_1.mkdir)(src); | ||
await (0, fs_extra_1.mkdir)(path_1.default.join(src, 'interfaces')); | ||
await (0, fs_extra_1.mkdir)(path_1.default.join(src, 'workflows')); | ||
await writePrettyJson(path_1.default.join(root, 'tsconfig.json'), tsConfig); | ||
const sampleDir = path_1.default.join(__dirname, '../samples'); | ||
@@ -169,12 +122,12 @@ const template = getTemplate(sample); | ||
if (useYarn) { | ||
await subprocess_1.spawn('yarn', ['install'], { cwd: root, stdio: 'inherit' }); | ||
await subprocess_1.spawn('yarn', ['add', `temporalio@${temporalVersion}`], { cwd: root, stdio: 'inherit' }); | ||
await (0, subprocess_1.spawn)('yarn', ['install'], { cwd: root, stdio: 'inherit' }); | ||
await (0, subprocess_1.spawn)('yarn', ['add', `temporalio@${temporalVersion}`], { cwd: root, stdio: 'inherit' }); | ||
} | ||
else { | ||
await subprocess_1.spawn(npm, ['install'], { cwd: root, stdio: 'inherit' }); | ||
await subprocess_1.spawn(npm, ['install', `temporalio@${temporalVersion}`], { cwd: root, stdio: 'inherit' }); | ||
await (0, subprocess_1.spawn)(npm, ['install'], { cwd: root, stdio: 'inherit' }); | ||
await (0, subprocess_1.spawn)(npm, ['install', `temporalio@${temporalVersion}`], { cwd: root, stdio: 'inherit' }); | ||
} | ||
} | ||
async function init() { | ||
const { _: args, ...opts } = arg_1.default({ | ||
const { _: args, ...opts } = (0, arg_1.default)({ | ||
'--use-yarn': Boolean, | ||
@@ -181,0 +134,0 @@ '--temporal-version': String, |
@@ -17,3 +17,3 @@ "use strict"; | ||
// Workaround @types/node - avoid choosing overloads per options.stdio variants | ||
await waitOnChild(options === undefined ? child_process_1.spawn(command, args) : child_process_1.spawn(command, args || [], options)); | ||
await waitOnChild(options === undefined ? (0, child_process_1.spawn)(command, args) : (0, child_process_1.spawn)(command, args || [], options)); | ||
} | ||
@@ -20,0 +20,0 @@ catch (err) { |
{ | ||
"name": "@temporalio/create", | ||
"version": "0.3.4", | ||
"version": "0.4.0", | ||
"description": "Create a Temporal project from template", | ||
@@ -29,3 +29,3 @@ "main": "lib/index.js", | ||
}, | ||
"gitHead": "cd10cb4b187a6a733770502fbca32b9dcd2d2244" | ||
"gitHead": "254e9f5793afc11cb5fb64a9829b1c55190092f0" | ||
} |
// @@@SNIPSTART nodejs-mtls-client | ||
import fs from 'fs'; | ||
import { Connection, WorkflowClient } from '@temporalio/client'; | ||
import { Example } from '../interfaces/workflows'; | ||
import { Example } from './interfaces/workflows'; | ||
import { getEnv, Env } from './mtls-env'; | ||
@@ -6,0 +6,0 @@ |
// @@@SNIPSTART nodejs-hello-client | ||
import { Connection, WorkflowClient } from '@temporalio/client'; | ||
import { Example } from '../interfaces/workflows'; | ||
import { Example } from './interfaces/workflows'; | ||
@@ -5,0 +5,0 @@ async function run() { |
@@ -6,3 +6,3 @@ // @@@SNIPSTART nodejs-hello-worker | ||
// Automatically locate and register Activities and Workflows relative to __dirname | ||
// (assuming package was bootstrapped with `npm init @temporalio`). | ||
// (assuming package was bootstrapped with `npx @temporalio/create@latest`). | ||
// Worker connects to localhost by default and uses console error for logging. | ||
@@ -9,0 +9,0 @@ // Customize the Worker by passing more options to create(). |
// @@@SNIPSTART nodejs-hello-workflow | ||
import { Context } from '@temporalio/workflow'; | ||
import { Example } from '../interfaces/workflows'; | ||
import { greet } from '@activities/greeter'; | ||
import * as activities from '../activities'; | ||
const { greet } = Context.configureActivities<typeof activities>({ | ||
type: 'remote', | ||
startToCloseTimeout: '30 minutes', | ||
}); | ||
// A workflow that simply calls an activity | ||
@@ -10,4 +16,3 @@ async function main(name: string): Promise<string> { | ||
// Declare the workflow's type to be checked by the Typescript compiler | ||
export const workflow: Example = { main }; | ||
export const workflow = { main }; | ||
// @@@SNIPEND |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23110
393