stepzen 0.17.0-beta.0 → 0.17.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -5
- package/lib/commands/import.d.ts +11 -5
- package/lib/commands/import.js +59 -39
- package/lib/commands/init.d.ts +0 -3
- package/lib/commands/init.js +5 -108
- package/lib/commands/lint.js +2 -2
- package/lib/commands/start.d.ts +0 -1
- package/lib/commands/start.js +38 -37
- package/lib/commands/transpile.d.ts +1 -1
- package/lib/commands/transpile.js +5 -5
- package/lib/commands/validate.js +3 -3
- package/lib/generate/curl2sdl.d.ts +1 -19
- package/lib/generate/curl2sdl.js +42 -113
- package/lib/generate/graphql2sdl.d.ts +23 -0
- package/lib/generate/graphql2sdl.js +62 -0
- package/lib/generate/helpers.d.ts +18 -0
- package/lib/generate/helpers.js +87 -2
- package/lib/shared/header-params-parser.d.ts +1 -1
- package/lib/shared/header.d.ts +21 -0
- package/lib/shared/header.js +13 -0
- package/lib/shared/utils.d.ts +15 -1
- package/lib/shared/utils.js +28 -7
- package/lib/shared/workspace.d.ts +8 -0
- package/lib/shared/workspace.js +105 -1
- package/lib/shared/zen-command.d.ts +5 -1
- package/lib/shared/zen-command.js +27 -0
- package/lib/start/console.d.ts +11 -2
- package/lib/start/console.js +41 -9
- package/lib/start/deploy.d.ts +5 -1
- package/lib/start/deploy.js +21 -29
- package/lib/start/index.d.ts +2 -3
- package/lib/start/index.js +6 -5
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ $ npm install -g stepzen
|
|
|
29
29
|
$ stepzen COMMAND
|
|
30
30
|
running command...
|
|
31
31
|
$ stepzen (-v|--version|version)
|
|
32
|
-
stepzen/0.17.0-beta.
|
|
32
|
+
stepzen/0.17.0-beta.3 darwin-x64 node-v14.19.3
|
|
33
33
|
$ stepzen --help [COMMAND]
|
|
34
34
|
USAGE
|
|
35
35
|
$ stepzen COMMAND
|
|
@@ -126,9 +126,6 @@ OPTIONS
|
|
|
126
126
|
Subfolder inside the workspace folder to save the imported schema files to. Defaults to the name of the imported
|
|
127
127
|
schema.
|
|
128
128
|
|
|
129
|
-
--overwrite
|
|
130
|
-
Overwrite any existing schema with the same name. Cannot be used without also providing a --name flag.
|
|
131
|
-
|
|
132
129
|
--path-params=path-params
|
|
133
130
|
[curl] specifies path parameters in the URL path. Can be formed by taking the original path and replacing the
|
|
134
131
|
variable segments with $paramName placeholders.
|
|
@@ -137,7 +134,7 @@ OPTIONS
|
|
|
137
134
|
stepzen import curl https://example.com/users/jane/posts/12 --path-params '/users/$userId/posts/$postId'
|
|
138
135
|
|
|
139
136
|
--prefix=prefix
|
|
140
|
-
[curl] prefix to add every type in the generated schema.
|
|
137
|
+
[curl, graphql] prefix to add every type in the generated schema.
|
|
141
138
|
|
|
142
139
|
--query-name=query-name
|
|
143
140
|
[curl] property name to add to the Query type as a way to access the imported cURL endpoint.
|
package/lib/commands/import.d.ts
CHANGED
|
@@ -3,8 +3,10 @@ import ZenCommand from '../shared/zen-command';
|
|
|
3
3
|
import { Workspace } from '../shared/types';
|
|
4
4
|
export default class Import extends ZenCommand {
|
|
5
5
|
static description: string;
|
|
6
|
-
static
|
|
6
|
+
static commonIntrospectionFlags: {
|
|
7
7
|
prefix: flags.IOptionFlag<string | undefined>;
|
|
8
|
+
};
|
|
9
|
+
static curlFlags: {
|
|
8
10
|
'query-name': flags.IOptionFlag<string | undefined>;
|
|
9
11
|
'query-type': flags.IOptionFlag<string | undefined>;
|
|
10
12
|
'path-params': flags.IOptionFlag<string | undefined>;
|
|
@@ -22,6 +24,10 @@ export default class Import extends ZenCommand {
|
|
|
22
24
|
static flagsForSchemas: ({
|
|
23
25
|
flags: {
|
|
24
26
|
prefix: flags.IOptionFlag<string | undefined>;
|
|
27
|
+
};
|
|
28
|
+
schemas: string[];
|
|
29
|
+
} | {
|
|
30
|
+
flags: {
|
|
25
31
|
'query-name': flags.IOptionFlag<string | undefined>;
|
|
26
32
|
'query-type': flags.IOptionFlag<string | undefined>;
|
|
27
33
|
'path-params': flags.IOptionFlag<string | undefined>;
|
|
@@ -48,11 +54,11 @@ export default class Import extends ZenCommand {
|
|
|
48
54
|
'db-user': flags.IOptionFlag<string | undefined>;
|
|
49
55
|
'db-password': flags.IOptionFlag<string | undefined>;
|
|
50
56
|
'db-database': flags.IOptionFlag<string | undefined>;
|
|
51
|
-
prefix: flags.IOptionFlag<string | undefined>;
|
|
52
57
|
'query-name': flags.IOptionFlag<string | undefined>;
|
|
53
58
|
'query-type': flags.IOptionFlag<string | undefined>;
|
|
54
59
|
'path-params': flags.IOptionFlag<string | undefined>;
|
|
55
60
|
'header-param': flags.IOptionFlag<string[]>;
|
|
61
|
+
prefix: flags.IOptionFlag<string | undefined>;
|
|
56
62
|
dir: flags.IOptionFlag<string | undefined>;
|
|
57
63
|
help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
|
|
58
64
|
silent: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
@@ -67,20 +73,20 @@ export default class Import extends ZenCommand {
|
|
|
67
73
|
static strict: boolean;
|
|
68
74
|
run(): Promise<void>;
|
|
69
75
|
ensureOnConflictBehavior(workspace: Workspace, schema: string, flags: ReturnType<Import['parseWorkaround']>['flags']): Promise<"overwrite" | "append">;
|
|
70
|
-
warnAboutIgnoredFlags
|
|
76
|
+
warnAboutIgnoredFlags(schema: string, usedFlags: {
|
|
71
77
|
[key: string]: any;
|
|
72
|
-
})
|
|
78
|
+
}): void;
|
|
73
79
|
parseWorkaround(): import("@oclif/parser").Output<{
|
|
74
80
|
'db-schema': string | undefined;
|
|
75
81
|
'db-host': string | undefined;
|
|
76
82
|
'db-user': string | undefined;
|
|
77
83
|
'db-password': string | undefined;
|
|
78
84
|
'db-database': string | undefined;
|
|
79
|
-
prefix: string | undefined;
|
|
80
85
|
'query-name': string | undefined;
|
|
81
86
|
'query-type': string | undefined;
|
|
82
87
|
'path-params': string | undefined;
|
|
83
88
|
'header-param': string[];
|
|
89
|
+
prefix: string | undefined;
|
|
84
90
|
dir: string | undefined;
|
|
85
91
|
help: void;
|
|
86
92
|
silent: boolean;
|
package/lib/commands/import.js
CHANGED
|
@@ -14,50 +14,19 @@ const utils_1 = require("../shared/utils");
|
|
|
14
14
|
const helpers_1 = require("../generate/helpers");
|
|
15
15
|
const curl2sdl_1 = require("../generate/curl2sdl");
|
|
16
16
|
const curl_parser_1 = require("../shared/curl-parser");
|
|
17
|
-
const workspace_1 = require("../shared/workspace");
|
|
18
17
|
const zen_command_1 = require("../shared/zen-command");
|
|
19
|
-
const
|
|
18
|
+
const graphql2sdl_1 = require("../generate/graphql2sdl");
|
|
20
19
|
const constants_1 = require("../shared/constants");
|
|
21
20
|
const path_params_parser_1 = require("../shared/path-params-parser");
|
|
22
21
|
const header_params_parser_1 = require("../shared/header-params-parser");
|
|
23
22
|
class Import extends zen_command_1.default {
|
|
24
|
-
constructor() {
|
|
25
|
-
super(...arguments);
|
|
26
|
-
// notify the user about any ignored flags
|
|
27
|
-
this.warnAboutIgnoredFlags = (schema, usedFlags) => {
|
|
28
|
-
Import.flagsForSchemas.forEach(({ flags, schemas }) => {
|
|
29
|
-
if (!schemas.includes(schema)) {
|
|
30
|
-
Object.keys(flags).forEach(flag => {
|
|
31
|
-
if (Object.prototype.hasOwnProperty.call(usedFlags, flag)) {
|
|
32
|
-
this.log(chalk.gray(`The ${chalk.bold(`--${flag}`)} flag only applies when importing ${schemas
|
|
33
|
-
.map(schema => chalk.bold(schema))
|
|
34
|
-
.join(', ')}. It will be ignored now.`));
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
23
|
async run() {
|
|
42
24
|
const { args, argv, flags } = this.parseWorkaround();
|
|
43
25
|
// Get a list of schemas you're asking for
|
|
44
26
|
const schema = helpers_1.getSchema(args.schema);
|
|
45
|
-
// Get
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const maybeWorkspace = workspace_1.getWorkspace(directory);
|
|
49
|
-
if (maybeWorkspace) {
|
|
50
|
-
workspace = maybeWorkspace;
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
try {
|
|
54
|
-
workspace = await init_1.default.run([directory]);
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
throw new errors_1.CLIError(`Could not create a StepZen workspace in the ${flags.dir ? directory : 'current'} directory.\n` + error.message);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
// Make sure that the onConflict behaviour is defined and feasible
|
|
27
|
+
// Get or create a StepZen workspace (possibly interactive)
|
|
28
|
+
const workspace = await this.ensureStepZenWorkspace({ directory: flags.dir });
|
|
29
|
+
// Define a sane onConflict behaviour (possibly interactive)
|
|
61
30
|
const onConflict = await this.ensureOnConflictBehavior(workspace, schema, flags);
|
|
62
31
|
this.warnAboutIgnoredFlags(schema, flags);
|
|
63
32
|
// Select an import execution flow:
|
|
@@ -125,6 +94,35 @@ class Import extends zen_command_1.default {
|
|
|
125
94
|
}
|
|
126
95
|
result = resultOrError.outPath;
|
|
127
96
|
}
|
|
97
|
+
else if (schema === 'graphql') {
|
|
98
|
+
const editableOptions = {
|
|
99
|
+
typePrefix: flags.prefix,
|
|
100
|
+
};
|
|
101
|
+
let answers;
|
|
102
|
+
if (argv.length === 1) {
|
|
103
|
+
// interactive
|
|
104
|
+
answers = await graphql2sdl_1.askGraphQLQuestions(editableOptions);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
// non-interactive
|
|
108
|
+
answers = Object.assign(Object.assign({}, editableOptions), { endpoint: argv[1] });
|
|
109
|
+
}
|
|
110
|
+
const fixedOptions = {
|
|
111
|
+
name: flags.name,
|
|
112
|
+
source: workspace.schema,
|
|
113
|
+
onConflict,
|
|
114
|
+
};
|
|
115
|
+
const options = Object.assign(Object.assign({}, fixedOptions), answers);
|
|
116
|
+
core_1.CliUx.ux.action.start('Starting');
|
|
117
|
+
const resultOrError = await graphql2sdl_1.graphql2sdl(options);
|
|
118
|
+
core_1.CliUx.ux.action.stop();
|
|
119
|
+
if ('error' in resultOrError) {
|
|
120
|
+
this.log('A problem occured while processing your import.');
|
|
121
|
+
this.log(resultOrError.error);
|
|
122
|
+
this.exit();
|
|
123
|
+
}
|
|
124
|
+
result = resultOrError.outPath;
|
|
125
|
+
}
|
|
128
126
|
else {
|
|
129
127
|
// Map flag names to the properties defined for sql engines in:
|
|
130
128
|
// https://github.com/steprz/generator-engines/blob/main/generator/src/shared/sql.ts
|
|
@@ -156,6 +154,10 @@ class Import extends zen_command_1.default {
|
|
|
156
154
|
this.log(chalk.green(`Successfully imported schema ${chalk.bold(schema)} from StepZen`));
|
|
157
155
|
}
|
|
158
156
|
async ensureOnConflictBehavior(workspace, schema, flags) {
|
|
157
|
+
const featureFlag = process.env.STEPZEN_DETECT_NAME_CONFLICTS;
|
|
158
|
+
if (featureFlag === undefined || featureFlag.toLowerCase() === 'false') {
|
|
159
|
+
return 'append';
|
|
160
|
+
}
|
|
159
161
|
const name = flags.name || schema;
|
|
160
162
|
const hasConflict = fs.existsSync(path.join(workspace.schema, name));
|
|
161
163
|
if (!hasConflict) {
|
|
@@ -196,6 +198,20 @@ class Import extends zen_command_1.default {
|
|
|
196
198
|
}
|
|
197
199
|
this.exit();
|
|
198
200
|
}
|
|
201
|
+
// notify the user about any ignored flags
|
|
202
|
+
warnAboutIgnoredFlags(schema, usedFlags) {
|
|
203
|
+
Import.flagsForSchemas.forEach(({ flags, schemas }) => {
|
|
204
|
+
if (!schemas.includes(schema)) {
|
|
205
|
+
Object.keys(flags).forEach(flag => {
|
|
206
|
+
if (Object.prototype.hasOwnProperty.call(usedFlags, flag)) {
|
|
207
|
+
this.log(chalk.gray(`The ${chalk.bold(`--${flag}`)} flag only applies when importing ${schemas
|
|
208
|
+
.map(schema => chalk.bold(schema))
|
|
209
|
+
.join(', ')}. It will be ignored now.`));
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
}
|
|
199
215
|
// Correct the value for the 'header-param' flag to work around the oclif's
|
|
200
216
|
// parser issue with multi-value flags: https://github.com/oclif/oclif/issues/261
|
|
201
217
|
parseWorkaround() {
|
|
@@ -235,10 +251,12 @@ class Import extends zen_command_1.default {
|
|
|
235
251
|
}
|
|
236
252
|
exports.default = Import;
|
|
237
253
|
Import.description = 'import a schema for an external data source or a API endpoint to your GraphQL API';
|
|
238
|
-
Import.
|
|
254
|
+
Import.commonIntrospectionFlags = {
|
|
239
255
|
prefix: command_1.flags.string({
|
|
240
|
-
description: '[curl] prefix to add every type in the generated schema.',
|
|
256
|
+
description: '[curl, graphql] prefix to add every type in the generated schema.',
|
|
241
257
|
}),
|
|
258
|
+
};
|
|
259
|
+
Import.curlFlags = {
|
|
242
260
|
'query-name': command_1.flags.string({
|
|
243
261
|
description: '[curl] property name to add to the Query type as a way to' +
|
|
244
262
|
' access the imported cURL endpoint.',
|
|
@@ -289,18 +307,20 @@ Import.postgresqlFlags = {
|
|
|
289
307
|
}),
|
|
290
308
|
};
|
|
291
309
|
Import.flagsForSchemas = [
|
|
310
|
+
{ flags: Import.commonIntrospectionFlags, schemas: ['curl', 'graphql'] },
|
|
292
311
|
{ flags: Import.curlFlags, schemas: ['curl'] },
|
|
293
312
|
{ flags: Import.sqlFlags, schemas: ['mysql', 'postgresql'] },
|
|
294
313
|
{ flags: Import.postgresqlFlags, schemas: ['postgresql'] },
|
|
295
314
|
];
|
|
296
|
-
Import.flags = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, zen_command_1.default.flags), { dir: command_1.flags.string({ description: 'working directory' }), help: command_1.flags.help({ char: 'h' }), silent: command_1.flags.boolean({ hidden: true }), name: command_1.flags.string({
|
|
315
|
+
Import.flags = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, zen_command_1.default.flags), { dir: command_1.flags.string({ description: 'working directory' }), help: command_1.flags.help({ char: 'h' }), silent: command_1.flags.boolean({ hidden: true }), name: command_1.flags.string({
|
|
297
316
|
description: 'Subfolder inside the workspace folder to save the imported' +
|
|
298
317
|
' schema files to. Defaults to the name of the imported schema.',
|
|
299
318
|
}), overwrite: command_1.flags.boolean({
|
|
300
319
|
description: 'Overwrite any existing schema with the same name. Cannot be used' +
|
|
301
320
|
' without also providing a --name flag.',
|
|
302
321
|
dependsOn: ['name'],
|
|
303
|
-
|
|
322
|
+
hidden: true,
|
|
323
|
+
}) }), Import.commonIntrospectionFlags), Import.curlFlags), Import.sqlFlags), Import.postgresqlFlags);
|
|
304
324
|
Import.args = [
|
|
305
325
|
{
|
|
306
326
|
name: 'schema',
|
package/lib/commands/init.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { flags } from '@oclif/command';
|
|
2
2
|
import ZenCommand from '../shared/zen-command';
|
|
3
|
-
export declare const validateWorkspaceName: (directory: string, name: string) => boolean;
|
|
4
|
-
export declare const generateWorkspaceName: (directory: string) => string;
|
|
5
|
-
export declare const guessSchemaRoot: (directory: string) => string;
|
|
6
3
|
export default class Init extends ZenCommand {
|
|
7
4
|
static description: string;
|
|
8
5
|
static hidden: boolean;
|
package/lib/commands/init.js
CHANGED
|
@@ -1,120 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.guessSchemaRoot = exports.generateWorkspaceName = exports.validateWorkspaceName = void 0;
|
|
5
4
|
const command_1 = require("@oclif/command");
|
|
6
|
-
const errors_1 = require("@oclif/errors");
|
|
7
|
-
const fs = require("fs");
|
|
8
|
-
const glob = require("glob");
|
|
9
|
-
const inquirer = require("inquirer");
|
|
10
|
-
const os = require("os");
|
|
11
|
-
const path = require("path");
|
|
12
|
-
const utils_1 = require("../shared/utils");
|
|
13
|
-
const moniker_1 = require("../shared/moniker");
|
|
14
5
|
const workspace_1 = require("../shared/workspace");
|
|
15
6
|
const zen_command_1 = require("../shared/zen-command");
|
|
16
|
-
exports.validateWorkspaceName = (directory, name) => {
|
|
17
|
-
return !fs.existsSync(path.join(directory, name));
|
|
18
|
-
};
|
|
19
|
-
exports.generateWorkspaceName = (directory) => {
|
|
20
|
-
let name = 'hello-stepzen';
|
|
21
|
-
while (!exports.validateWorkspaceName(directory, name)) {
|
|
22
|
-
name = `hello-${moniker_1.getRandomDescriptor()}-stepzen`;
|
|
23
|
-
}
|
|
24
|
-
return name;
|
|
25
|
-
};
|
|
26
|
-
exports.guessSchemaRoot = (directory) => {
|
|
27
|
-
const existing = [
|
|
28
|
-
...glob.sync('*/**/config.yaml', {
|
|
29
|
-
cwd: directory,
|
|
30
|
-
ignore: '**/node_modules/**',
|
|
31
|
-
}),
|
|
32
|
-
...glob.sync('*/**/index.graphql', {
|
|
33
|
-
cwd: directory,
|
|
34
|
-
ignore: '**/node_modules/**',
|
|
35
|
-
}),
|
|
36
|
-
];
|
|
37
|
-
return existing.length > 0 ? path.dirname(existing[0]) : '';
|
|
38
|
-
};
|
|
39
7
|
class Init extends zen_command_1.default {
|
|
40
8
|
async run() {
|
|
41
9
|
const { args, flags } = this.parse(Init);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
' Please select a different directory.');
|
|
48
|
-
}
|
|
49
|
-
const isHomeDir = directory === os.homedir();
|
|
50
|
-
// Prevent init from running in the home directory if the directory was
|
|
51
|
-
// explicitly provided as an aargument to `stepzen init`.
|
|
52
|
-
// StepZen CLI sometimes would enumerate all files in the workspace folder
|
|
53
|
-
// doing so in the home directory is likely to fail.
|
|
54
|
-
if (args.directory && isHomeDir) {
|
|
55
|
-
throw new errors_1.CLIError('Using the home directory as a StepZen workspace is not supported.' +
|
|
56
|
-
' Please select a different directory.');
|
|
57
|
-
}
|
|
58
|
-
// Make a suggestion for the workspace name (if running in the HOME
|
|
59
|
-
// directory)
|
|
60
|
-
const name = isHomeDir
|
|
61
|
-
? exports.generateWorkspaceName(directory)
|
|
62
|
-
: path.basename(directory);
|
|
63
|
-
// See if we think there's a StepZen schema already
|
|
64
|
-
const root = isHomeDir ? '' : exports.guessSchemaRoot(directory);
|
|
65
|
-
// If you've passed an endpoint, validate it, and throw an error
|
|
66
|
-
// straight away if needed
|
|
67
|
-
if (flags.endpoint) {
|
|
68
|
-
const error = utils_1.validateEndpoint(flags.endpoint);
|
|
69
|
-
if (typeof error === 'string') {
|
|
70
|
-
throw new errors_1.CLIError(error);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
// Make a suggestion for the endpoint
|
|
74
|
-
const endpoint = flags.endpoint || `api/${moniker_1.default()}`;
|
|
75
|
-
// What questions will we ask?
|
|
76
|
-
const questions = [
|
|
77
|
-
{
|
|
78
|
-
default: name,
|
|
79
|
-
message: 'What would you like to call your workspace?',
|
|
80
|
-
name: 'name',
|
|
81
|
-
validate: (name) => exports.validateWorkspaceName(directory, name),
|
|
82
|
-
when: isHomeDir && !flags.yes,
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
default: endpoint,
|
|
86
|
-
message: 'What would you like your endpoint to be called?',
|
|
87
|
-
name: 'endpoint',
|
|
88
|
-
validate: utils_1.validateEndpoint,
|
|
89
|
-
when: !flags.endpoint && !flags.yes,
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
message: `We have detected a schema in this directory. Set the schema root to "${root}"?`,
|
|
93
|
-
name: 'use-root',
|
|
94
|
-
type: 'confirm',
|
|
95
|
-
when: Boolean(root) && !flags.yes,
|
|
96
|
-
},
|
|
97
|
-
];
|
|
98
|
-
// Get the answers
|
|
99
|
-
const answers = Object.assign({ name,
|
|
100
|
-
endpoint, 'use-root': true }, (await inquirer.prompt(questions)));
|
|
101
|
-
// Append the suggested workspace name to the directory (if running
|
|
102
|
-
// in the HOME directory)
|
|
103
|
-
if (isHomeDir) {
|
|
104
|
-
// eslint-disable-next-line require-atomic-updates
|
|
105
|
-
directory = path.join(directory, answers.name);
|
|
106
|
-
fs.mkdirSync(directory);
|
|
107
|
-
}
|
|
108
|
-
// Create the workspace
|
|
109
|
-
const workspace = { endpoint: answers.endpoint };
|
|
110
|
-
if (root && answers['use-root'])
|
|
111
|
-
workspace.root = root;
|
|
112
|
-
// Write the file
|
|
113
|
-
const file = path.join(directory, 'stepzen.config.json');
|
|
114
|
-
fs.writeFileSync(file, JSON.stringify(workspace, null, ' '));
|
|
115
|
-
// Fetch the newly created workspace
|
|
116
|
-
const created = workspace_1.getWorkspace(directory);
|
|
117
|
-
// Done!
|
|
10
|
+
const created = await workspace_1.initWorkspace({
|
|
11
|
+
directory: args.directory,
|
|
12
|
+
endpoint: flags.endpoint,
|
|
13
|
+
yes: flags.yes,
|
|
14
|
+
});
|
|
118
15
|
this.log(`Created a StepZen workspace in ${created.directory}`);
|
|
119
16
|
return created;
|
|
120
17
|
}
|
package/lib/commands/lint.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const command_1 = require("@oclif/command");
|
|
5
|
+
const transpiler_1 = require("@stepzen/transpiler");
|
|
5
6
|
const utils_1 = require("../shared/utils");
|
|
6
7
|
const zen_command_1 = require("../shared/zen-command");
|
|
7
|
-
const { lint } = require('@stepzen/transpiler');
|
|
8
8
|
class Init extends zen_command_1.default {
|
|
9
9
|
async run() {
|
|
10
10
|
const { flags } = this.parse(Init);
|
|
@@ -18,7 +18,7 @@ class Init extends zen_command_1.default {
|
|
|
18
18
|
this.log(formatted);
|
|
19
19
|
};
|
|
20
20
|
// Lint
|
|
21
|
-
await lint(directory);
|
|
21
|
+
await transpiler_1.lint(directory);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
exports.default = Init;
|
package/lib/commands/start.d.ts
CHANGED
|
@@ -9,7 +9,6 @@ export default class Start extends ZenCommand {
|
|
|
9
9
|
'no-console': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
10
10
|
'no-dashboard': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
11
11
|
'no-init': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
12
|
-
'no-server': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
13
12
|
'no-validate': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
14
13
|
'no-watcher': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
15
14
|
port: import("@oclif/parser/lib/flags").IOptionFlag<number>;
|
package/lib/commands/start.js
CHANGED
|
@@ -2,15 +2,13 @@
|
|
|
2
2
|
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const chokidar = require("chokidar");
|
|
5
|
+
const debug = require("debug");
|
|
5
6
|
const core_1 = require("@oclif/core");
|
|
6
7
|
const command_1 = require("@oclif/command");
|
|
7
8
|
const errors_1 = require("@oclif/errors");
|
|
8
9
|
const throttle_debounce_1 = require("throttle-debounce");
|
|
9
10
|
const detect = require("detect-port");
|
|
10
|
-
const utils_1 = require("../shared/utils");
|
|
11
11
|
const start_1 = require("../start");
|
|
12
|
-
const workspace_1 = require("../shared/workspace");
|
|
13
|
-
const init_1 = require("./init");
|
|
14
12
|
const constants_1 = require("../shared/constants");
|
|
15
13
|
const zen_command_1 = require("../shared/zen-command");
|
|
16
14
|
const dashboard = require('@stepzen/dashboard');
|
|
@@ -19,28 +17,13 @@ class Start extends zen_command_1.default {
|
|
|
19
17
|
async run() {
|
|
20
18
|
const { flags } = this.parse(Start);
|
|
21
19
|
const { configuration } = await this.ensureStepZenAccount();
|
|
22
|
-
// Get
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
const initArgs = [directory];
|
|
31
|
-
if (flags.endpoint) {
|
|
32
|
-
initArgs.push('--endpoint', flags.endpoint);
|
|
33
|
-
}
|
|
34
|
-
try {
|
|
35
|
-
workspace = await init_1.default.run(initArgs);
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
throw new errors_1.CLIError(`Could not create a StepZen workspace in the ${flags.dir ? directory : 'current'} directory.\n` + error.message);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
// If you have overridden the endpoint, set it
|
|
20
|
+
// Get or create a StepZen workspace (possibly interactive)
|
|
21
|
+
const workspace = await this.ensureStepZenWorkspace({
|
|
22
|
+
directory: flags.dir,
|
|
23
|
+
endpoint: flags.endpoint,
|
|
24
|
+
});
|
|
25
|
+
// If the user has overridden the endpoint, apply the override
|
|
42
26
|
if (flags.endpoint) {
|
|
43
|
-
// eslint-disable-next-line require-atomic-updates
|
|
44
27
|
workspace.endpoint = flags.endpoint;
|
|
45
28
|
}
|
|
46
29
|
// Check the port is available
|
|
@@ -50,28 +33,32 @@ class Start extends zen_command_1.default {
|
|
|
50
33
|
}
|
|
51
34
|
// This is the file watcher
|
|
52
35
|
if (!flags['no-watcher']) {
|
|
36
|
+
const redeploy = throttle_debounce_1.debounce(500, (path) => {
|
|
37
|
+
debug('stepzen:start')(`chokidar decected change to ${path}`);
|
|
38
|
+
start_1.changed({ workspace, file: path });
|
|
39
|
+
start_1.deploy({ workspace, flags });
|
|
40
|
+
});
|
|
53
41
|
chokidar
|
|
54
|
-
.watch(
|
|
55
|
-
|
|
42
|
+
.watch(['**/*.graphql', 'config.yaml'], {
|
|
43
|
+
cwd: workspace.schema,
|
|
44
|
+
ignored: 'node_modules/**',
|
|
45
|
+
ignoreInitial: true,
|
|
56
46
|
})
|
|
57
|
-
.on('change',
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}));
|
|
47
|
+
.on('change', redeploy)
|
|
48
|
+
.on('add', redeploy)
|
|
49
|
+
.on('unlink', redeploy);
|
|
50
|
+
debug('stepzen:start')(`chokidar started watching ${workspace.schema}`);
|
|
62
51
|
}
|
|
63
52
|
// Start!
|
|
64
|
-
utils_1.clearConsole();
|
|
65
53
|
core_1.CliUx.ux.action.start('Starting...');
|
|
54
|
+
let didDeploy = false;
|
|
66
55
|
// Unless explicitly disabled, auto-init
|
|
67
56
|
if (!flags['no-init']) {
|
|
68
|
-
await start_1.deploy(
|
|
69
|
-
}
|
|
70
|
-
if (!flags['no-console']) {
|
|
71
|
-
start_1.console(workspace);
|
|
57
|
+
didDeploy = await start_1.deploy({ workspace, flags });
|
|
72
58
|
}
|
|
73
59
|
// Create the dashboard
|
|
74
60
|
if (!flags['no-dashboard']) {
|
|
61
|
+
debug('stepzen:start')(`starting the dashboard server on ${flags.port}`);
|
|
75
62
|
const ui = await dashboard({
|
|
76
63
|
account: configuration.account,
|
|
77
64
|
adminkey: configuration.adminkey,
|
|
@@ -89,12 +76,26 @@ class Start extends zen_command_1.default {
|
|
|
89
76
|
workspace,
|
|
90
77
|
});
|
|
91
78
|
await ui.start();
|
|
79
|
+
debug('stepzen:start')(`dashboard server on ${flags.port} started`);
|
|
92
80
|
}
|
|
93
81
|
// Done
|
|
94
82
|
core_1.CliUx.ux.action.stop();
|
|
83
|
+
if (!flags['no-console']) {
|
|
84
|
+
if (didDeploy) {
|
|
85
|
+
start_1.success({
|
|
86
|
+
workspace,
|
|
87
|
+
account: configuration.account,
|
|
88
|
+
port: flags.port,
|
|
89
|
+
});
|
|
90
|
+
this.log();
|
|
91
|
+
}
|
|
92
|
+
if (!flags['no-watcher']) {
|
|
93
|
+
start_1.watching(workspace);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
95
96
|
}
|
|
96
97
|
}
|
|
97
98
|
exports.default = Start;
|
|
98
99
|
Start.description = 'upload and deploy your schema';
|
|
99
|
-
Start.flags = Object.assign(Object.assign({}, zen_command_1.default.flags), { dir: command_1.flags.string({ description: 'working directory' }), endpoint: command_1.flags.string({ description: 'Override workspace endpoint' }), help: command_1.flags.help({ char: 'h' }), 'no-console': command_1.flags.boolean({ hidden: true }), 'no-dashboard': command_1.flags.boolean({ hidden: true }), 'no-init': command_1.flags.boolean({ hidden: true }), 'no-
|
|
100
|
+
Start.flags = Object.assign(Object.assign({}, zen_command_1.default.flags), { dir: command_1.flags.string({ description: 'working directory' }), endpoint: command_1.flags.string({ description: 'Override workspace endpoint' }), help: command_1.flags.help({ char: 'h' }), 'no-console': command_1.flags.boolean({ hidden: true }), 'no-dashboard': command_1.flags.boolean({ hidden: true }), 'no-init': command_1.flags.boolean({ hidden: true }), 'no-validate': command_1.flags.boolean({ hidden: true }), 'no-watcher': command_1.flags.boolean({ hidden: true }), port: command_1.flags.integer({ default: 5001, env: 'PORT' }) });
|
|
100
101
|
Start.args = [];
|
|
@@ -6,26 +6,26 @@ const command_1 = require("@oclif/command");
|
|
|
6
6
|
const errors_1 = require("@oclif/errors");
|
|
7
7
|
const fs = require("fs-extra");
|
|
8
8
|
const path = require("path");
|
|
9
|
+
const transpiler_1 = require("@stepzen/transpiler");
|
|
9
10
|
const utils_1 = require("../shared/utils");
|
|
10
11
|
const zen_command_1 = require("../shared/zen-command");
|
|
11
|
-
const { configure, stitch, validate } = require('@stepzen/transpiler');
|
|
12
12
|
class Transpile extends zen_command_1.default {
|
|
13
13
|
async run() {
|
|
14
14
|
const { args, flags } = this.parse(Transpile);
|
|
15
15
|
const folder = utils_1.getDirectory(args.folder);
|
|
16
16
|
// CONFIG
|
|
17
17
|
if (flags['output-configuration']) {
|
|
18
|
-
const config = await configure(folder, flags.silent);
|
|
18
|
+
const config = await transpiler_1.configure(folder, flags.silent);
|
|
19
19
|
if (flags['hide-output']) {
|
|
20
20
|
return config;
|
|
21
21
|
}
|
|
22
|
-
this.log(config);
|
|
22
|
+
this.log(`${config}`);
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
25
|
// SCHEMA
|
|
26
26
|
try {
|
|
27
|
-
const schema = stitch(folder);
|
|
28
|
-
validate(schema, {
|
|
27
|
+
const schema = transpiler_1.stitch(folder);
|
|
28
|
+
transpiler_1.validate(schema, {
|
|
29
29
|
extensions: await utils_1.getStepZenExtensions(),
|
|
30
30
|
});
|
|
31
31
|
const file = path.join(schema, 'index.graphql');
|
package/lib/commands/validate.js
CHANGED
|
@@ -4,16 +4,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
const chalk = require("chalk");
|
|
5
5
|
const command_1 = require("@oclif/command");
|
|
6
6
|
const errors_1 = require("@oclif/errors");
|
|
7
|
+
const transpiler_1 = require("@stepzen/transpiler");
|
|
7
8
|
const utils_1 = require("../shared/utils");
|
|
8
9
|
const zen_command_1 = require("../shared/zen-command");
|
|
9
|
-
const { stitch, validate } = require('@stepzen/transpiler');
|
|
10
10
|
class Validate extends zen_command_1.default {
|
|
11
11
|
async run() {
|
|
12
12
|
const { args } = this.parse(Validate);
|
|
13
13
|
const folder = utils_1.getDirectory(args.folder);
|
|
14
14
|
try {
|
|
15
|
-
const schema = stitch(folder);
|
|
16
|
-
validate(schema, {
|
|
15
|
+
const schema = transpiler_1.stitch(folder);
|
|
16
|
+
transpiler_1.validate(schema, {
|
|
17
17
|
extensions: await utils_1.getStepZenExtensions(),
|
|
18
18
|
});
|
|
19
19
|
}
|
|
@@ -1,24 +1,6 @@
|
|
|
1
1
|
import { CurlArguments } from '../shared/curl-parser';
|
|
2
2
|
import { PathParam } from '../shared/path-params-parser';
|
|
3
|
-
|
|
4
|
-
name: string;
|
|
5
|
-
value: string;
|
|
6
|
-
};
|
|
7
|
-
export declare type NamePartsHeaderInput = {
|
|
8
|
-
name: string;
|
|
9
|
-
parts: HeaderInputValuePart[];
|
|
10
|
-
};
|
|
11
|
-
export declare type HeaderInput = NameValueHeaderInput | NamePartsHeaderInput;
|
|
12
|
-
export declare type HeaderInputConstantValuePart = {
|
|
13
|
-
kind: 'Constant';
|
|
14
|
-
value: string;
|
|
15
|
-
};
|
|
16
|
-
export declare type HeaderInputVariableValuePart = {
|
|
17
|
-
kind: 'Variable';
|
|
18
|
-
value: string;
|
|
19
|
-
name: string;
|
|
20
|
-
};
|
|
21
|
-
export declare type HeaderInputValuePart = HeaderInputConstantValuePart | HeaderInputVariableValuePart;
|
|
3
|
+
import { HeaderInput } from '../shared/header';
|
|
22
4
|
export declare type Curl2SdlOptions = {
|
|
23
5
|
curlArgs: CurlArguments;
|
|
24
6
|
name?: string;
|