stepzen 0.16.0 → 0.17.0-beta.2
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 +4 -3
- package/lib/commands/import.d.ts +15 -5
- package/lib/commands/import.js +117 -41
- 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 +32 -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 +3 -20
- package/lib/generate/curl2sdl.js +43 -113
- package/lib/generate/graphql2sdl.d.ts +23 -0
- package/lib/generate/graphql2sdl.js +62 -0
- package/lib/generate/helpers.d.ts +18 -1
- package/lib/generate/helpers.js +81 -8
- package/lib/generate/index.d.ts +10 -3
- package/lib/generate/index.js +11 -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 +37 -9
- package/lib/start/deploy.d.ts +5 -1
- package/lib/start/deploy.js +2 -26
- package/lib/start/index.d.ts +2 -3
- package/lib/start/index.js +6 -5
- package/oclif.manifest.json +1 -1
- package/package.json +3 -3
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.
|
|
32
|
+
stepzen/0.17.0-beta.2 darwin-x64 node-v14.19.3
|
|
33
33
|
$ stepzen --help [COMMAND]
|
|
34
34
|
USAGE
|
|
35
35
|
$ stepzen COMMAND
|
|
@@ -123,7 +123,8 @@ OPTIONS
|
|
|
123
123
|
--header-param 'Authorization: apikey $apikey'
|
|
124
124
|
|
|
125
125
|
--name=name
|
|
126
|
-
|
|
126
|
+
Subfolder inside the workspace folder to save the imported schema files to. Defaults to the name of the imported
|
|
127
|
+
schema.
|
|
127
128
|
|
|
128
129
|
--path-params=path-params
|
|
129
130
|
[curl] specifies path parameters in the URL path. Can be formed by taking the original path and replacing the
|
|
@@ -133,7 +134,7 @@ OPTIONS
|
|
|
133
134
|
stepzen import curl https://example.com/users/jane/posts/12 --path-params '/users/$userId/posts/$postId'
|
|
134
135
|
|
|
135
136
|
--prefix=prefix
|
|
136
|
-
[curl] prefix to add every type in the generated schema.
|
|
137
|
+
[curl, graphql] prefix to add every type in the generated schema.
|
|
137
138
|
|
|
138
139
|
--query-name=query-name
|
|
139
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
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { flags } from '@oclif/command';
|
|
2
2
|
import ZenCommand from '../shared/zen-command';
|
|
3
|
+
import { Workspace } from '../shared/types';
|
|
3
4
|
export default class Import extends ZenCommand {
|
|
4
5
|
static description: string;
|
|
5
|
-
static
|
|
6
|
+
static commonIntrospectionFlags: {
|
|
6
7
|
prefix: flags.IOptionFlag<string | undefined>;
|
|
8
|
+
};
|
|
9
|
+
static curlFlags: {
|
|
7
10
|
'query-name': flags.IOptionFlag<string | undefined>;
|
|
8
11
|
'query-type': flags.IOptionFlag<string | undefined>;
|
|
9
12
|
'path-params': flags.IOptionFlag<string | undefined>;
|
|
@@ -21,6 +24,10 @@ export default class Import extends ZenCommand {
|
|
|
21
24
|
static flagsForSchemas: ({
|
|
22
25
|
flags: {
|
|
23
26
|
prefix: flags.IOptionFlag<string | undefined>;
|
|
27
|
+
};
|
|
28
|
+
schemas: string[];
|
|
29
|
+
} | {
|
|
30
|
+
flags: {
|
|
24
31
|
'query-name': flags.IOptionFlag<string | undefined>;
|
|
25
32
|
'query-type': flags.IOptionFlag<string | undefined>;
|
|
26
33
|
'path-params': flags.IOptionFlag<string | undefined>;
|
|
@@ -47,15 +54,16 @@ export default class Import extends ZenCommand {
|
|
|
47
54
|
'db-user': flags.IOptionFlag<string | undefined>;
|
|
48
55
|
'db-password': flags.IOptionFlag<string | undefined>;
|
|
49
56
|
'db-database': flags.IOptionFlag<string | undefined>;
|
|
50
|
-
prefix: flags.IOptionFlag<string | undefined>;
|
|
51
57
|
'query-name': flags.IOptionFlag<string | undefined>;
|
|
52
58
|
'query-type': flags.IOptionFlag<string | undefined>;
|
|
53
59
|
'path-params': flags.IOptionFlag<string | undefined>;
|
|
54
60
|
'header-param': flags.IOptionFlag<string[]>;
|
|
61
|
+
prefix: flags.IOptionFlag<string | undefined>;
|
|
55
62
|
dir: flags.IOptionFlag<string | undefined>;
|
|
56
63
|
help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
|
|
57
64
|
silent: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
58
65
|
name: flags.IOptionFlag<string | undefined>;
|
|
66
|
+
overwrite: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
59
67
|
'non-interactive': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
60
68
|
};
|
|
61
69
|
static args: {
|
|
@@ -64,24 +72,26 @@ export default class Import extends ZenCommand {
|
|
|
64
72
|
}[];
|
|
65
73
|
static strict: boolean;
|
|
66
74
|
run(): Promise<void>;
|
|
67
|
-
|
|
75
|
+
ensureOnConflictBehavior(workspace: Workspace, schema: string, flags: ReturnType<Import['parseWorkaround']>['flags']): Promise<"overwrite" | "append">;
|
|
76
|
+
warnAboutIgnoredFlags(schema: string, usedFlags: {
|
|
68
77
|
[key: string]: any;
|
|
69
|
-
})
|
|
78
|
+
}): void;
|
|
70
79
|
parseWorkaround(): import("@oclif/parser").Output<{
|
|
71
80
|
'db-schema': string | undefined;
|
|
72
81
|
'db-host': string | undefined;
|
|
73
82
|
'db-user': string | undefined;
|
|
74
83
|
'db-password': string | undefined;
|
|
75
84
|
'db-database': string | undefined;
|
|
76
|
-
prefix: string | undefined;
|
|
77
85
|
'query-name': string | undefined;
|
|
78
86
|
'query-type': string | undefined;
|
|
79
87
|
'path-params': string | undefined;
|
|
80
88
|
'header-param': string[];
|
|
89
|
+
prefix: string | undefined;
|
|
81
90
|
dir: string | undefined;
|
|
82
91
|
help: void;
|
|
83
92
|
silent: boolean;
|
|
84
93
|
name: string | undefined;
|
|
94
|
+
overwrite: boolean;
|
|
85
95
|
'non-interactive': boolean;
|
|
86
96
|
}, {
|
|
87
97
|
[name: string]: any;
|
package/lib/commands/import.js
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const chalk = require("chalk");
|
|
5
5
|
const fs = require("fs-extra");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const inquirer = require("inquirer");
|
|
6
8
|
const command_1 = require("@oclif/command");
|
|
7
9
|
const errors_1 = require("@oclif/errors");
|
|
8
10
|
const transpiler_1 = require("@stepzen/transpiler");
|
|
@@ -12,49 +14,20 @@ const utils_1 = require("../shared/utils");
|
|
|
12
14
|
const helpers_1 = require("../generate/helpers");
|
|
13
15
|
const curl2sdl_1 = require("../generate/curl2sdl");
|
|
14
16
|
const curl_parser_1 = require("../shared/curl-parser");
|
|
15
|
-
const workspace_1 = require("../shared/workspace");
|
|
16
17
|
const zen_command_1 = require("../shared/zen-command");
|
|
17
|
-
const
|
|
18
|
+
const graphql2sdl_1 = require("../generate/graphql2sdl");
|
|
18
19
|
const constants_1 = require("../shared/constants");
|
|
19
20
|
const path_params_parser_1 = require("../shared/path-params-parser");
|
|
20
21
|
const header_params_parser_1 = require("../shared/header-params-parser");
|
|
21
22
|
class Import extends zen_command_1.default {
|
|
22
|
-
constructor() {
|
|
23
|
-
super(...arguments);
|
|
24
|
-
// notify the user about any ignored flags
|
|
25
|
-
this.warnAboutIgnoredFlags = (schema, usedFlags) => {
|
|
26
|
-
Import.flagsForSchemas.forEach(({ flags, schemas }) => {
|
|
27
|
-
if (!schemas.includes(schema)) {
|
|
28
|
-
Object.keys(flags).forEach(flag => {
|
|
29
|
-
if (Object.prototype.hasOwnProperty.call(usedFlags, flag)) {
|
|
30
|
-
this.log(chalk.gray(`The ${chalk.bold(`--${flag}`)} flag only applies when importing ${schemas
|
|
31
|
-
.map(schema => chalk.bold(schema))
|
|
32
|
-
.join(', ')}. It will be ignored now.`));
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
23
|
async run() {
|
|
40
24
|
const { args, argv, flags } = this.parseWorkaround();
|
|
41
25
|
// Get a list of schemas you're asking for
|
|
42
26
|
const schema = helpers_1.getSchema(args.schema);
|
|
43
|
-
// Get
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
if (maybeWorkspace) {
|
|
48
|
-
workspace = maybeWorkspace;
|
|
49
|
-
}
|
|
50
|
-
else {
|
|
51
|
-
try {
|
|
52
|
-
workspace = await init_1.default.run([directory]);
|
|
53
|
-
}
|
|
54
|
-
catch (error) {
|
|
55
|
-
throw new errors_1.CLIError(`Could not create a StepZen workspace in the ${flags.dir ? directory : 'current'} directory.\n` + error.message);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
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)
|
|
30
|
+
const onConflict = await this.ensureOnConflictBehavior(workspace, schema, flags);
|
|
58
31
|
this.warnAboutIgnoredFlags(schema, flags);
|
|
59
32
|
// Select an import execution flow:
|
|
60
33
|
// - v1 with `stepzen/engines` and cloud function
|
|
@@ -71,6 +44,7 @@ class Import extends zen_command_1.default {
|
|
|
71
44
|
const fixedOptions = {
|
|
72
45
|
name: flags.name,
|
|
73
46
|
source: workspace.schema,
|
|
47
|
+
onConflict,
|
|
74
48
|
};
|
|
75
49
|
const editableOptions = {
|
|
76
50
|
queryName: flags['query-name'],
|
|
@@ -120,6 +94,35 @@ class Import extends zen_command_1.default {
|
|
|
120
94
|
}
|
|
121
95
|
result = resultOrError.outPath;
|
|
122
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
|
+
}
|
|
123
126
|
else {
|
|
124
127
|
// Map flag names to the properties defined for sql engines in:
|
|
125
128
|
// https://github.com/steprz/generator-engines/blob/main/generator/src/shared/sql.ts
|
|
@@ -132,7 +135,13 @@ class Import extends zen_command_1.default {
|
|
|
132
135
|
preAnswered = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, asKeyValue('host', flags['db-host'])), asKeyValue('user', flags['db-user'])), asKeyValue('password', flags['db-password'])), asKeyValue('database', flags['db-database'])), asKeyValue('schema', flags['db-schema']));
|
|
133
136
|
}
|
|
134
137
|
// Let's go!
|
|
135
|
-
result = await generate_1.default(
|
|
138
|
+
result = await generate_1.default({
|
|
139
|
+
schema,
|
|
140
|
+
name: flags.name,
|
|
141
|
+
onConflict,
|
|
142
|
+
source: workspace.schema,
|
|
143
|
+
preAnswered,
|
|
144
|
+
});
|
|
136
145
|
// Validate
|
|
137
146
|
await transpiler_1.validate(result, {
|
|
138
147
|
extensions: await utils_1.getStepZenExtensions(),
|
|
@@ -144,6 +153,65 @@ class Import extends zen_command_1.default {
|
|
|
144
153
|
// Nice message
|
|
145
154
|
this.log(chalk.green(`Successfully imported schema ${chalk.bold(schema)} from StepZen`));
|
|
146
155
|
}
|
|
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
|
+
}
|
|
161
|
+
const name = flags.name || schema;
|
|
162
|
+
const hasConflict = fs.existsSync(path.join(workspace.schema, name));
|
|
163
|
+
if (!hasConflict) {
|
|
164
|
+
return 'append';
|
|
165
|
+
}
|
|
166
|
+
// No `--name` is given (i.e. naming is automatic)
|
|
167
|
+
// Using the default name is going to lead to a conflict, and it should
|
|
168
|
+
// be resolved by inventing a new unique name for the new schema.
|
|
169
|
+
if (!flags.name) {
|
|
170
|
+
return 'append';
|
|
171
|
+
}
|
|
172
|
+
// `--name` is given and (i.e. naming is namaged by the user)
|
|
173
|
+
// There is a naming conflict.
|
|
174
|
+
// The user has explicitly asked to overwrite the existing schema.
|
|
175
|
+
if (flags.overwrite) {
|
|
176
|
+
return 'overwrite';
|
|
177
|
+
}
|
|
178
|
+
// `--name` is given and (i.e. naming is namaged by the user)
|
|
179
|
+
// There is a naming conflict.
|
|
180
|
+
// The user has NOT given an explicit permission to overwrite the existing
|
|
181
|
+
// schema.
|
|
182
|
+
// In an interactive mode the CLI asks them for a confirmation.
|
|
183
|
+
// In a non-interactive mode the CLI throws an error.
|
|
184
|
+
if (flags['non-interactive']) {
|
|
185
|
+
throw new errors_1.CLIError(`A schema named ${chalk.bold(flags.name)} already exists in this workspace. Add an ${chalk.bold('--overwrite')} flag to overwrite it.`);
|
|
186
|
+
}
|
|
187
|
+
this.log(`A schema named ${chalk.bold(flags.name)} already exists in this workspace. Would you like to overwrite it?`);
|
|
188
|
+
const answers = await inquirer.prompt([
|
|
189
|
+
{
|
|
190
|
+
name: 'overwrite',
|
|
191
|
+
type: 'confirm',
|
|
192
|
+
default: false,
|
|
193
|
+
message: `Overwrite ${flags.name}?`,
|
|
194
|
+
},
|
|
195
|
+
]);
|
|
196
|
+
if (answers.overwrite) {
|
|
197
|
+
return 'overwrite';
|
|
198
|
+
}
|
|
199
|
+
this.exit();
|
|
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
|
+
}
|
|
147
215
|
// Correct the value for the 'header-param' flag to work around the oclif's
|
|
148
216
|
// parser issue with multi-value flags: https://github.com/oclif/oclif/issues/261
|
|
149
217
|
parseWorkaround() {
|
|
@@ -183,10 +251,12 @@ class Import extends zen_command_1.default {
|
|
|
183
251
|
}
|
|
184
252
|
exports.default = Import;
|
|
185
253
|
Import.description = 'import a schema for an external data source or a API endpoint to your GraphQL API';
|
|
186
|
-
Import.
|
|
254
|
+
Import.commonIntrospectionFlags = {
|
|
187
255
|
prefix: command_1.flags.string({
|
|
188
|
-
description: '[curl] prefix to add every type in the generated schema.',
|
|
256
|
+
description: '[curl, graphql] prefix to add every type in the generated schema.',
|
|
189
257
|
}),
|
|
258
|
+
};
|
|
259
|
+
Import.curlFlags = {
|
|
190
260
|
'query-name': command_1.flags.string({
|
|
191
261
|
description: '[curl] property name to add to the Query type as a way to' +
|
|
192
262
|
' access the imported cURL endpoint.',
|
|
@@ -237,14 +307,20 @@ Import.postgresqlFlags = {
|
|
|
237
307
|
}),
|
|
238
308
|
};
|
|
239
309
|
Import.flagsForSchemas = [
|
|
310
|
+
{ flags: Import.commonIntrospectionFlags, schemas: ['curl', 'graphql'] },
|
|
240
311
|
{ flags: Import.curlFlags, schemas: ['curl'] },
|
|
241
312
|
{ flags: Import.sqlFlags, schemas: ['mysql', 'postgresql'] },
|
|
242
313
|
{ flags: Import.postgresqlFlags, schemas: ['postgresql'] },
|
|
243
314
|
];
|
|
244
|
-
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({
|
|
245
|
-
description: '
|
|
246
|
-
' schema files
|
|
247
|
-
})
|
|
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({
|
|
316
|
+
description: 'Subfolder inside the workspace folder to save the imported' +
|
|
317
|
+
' schema files to. Defaults to the name of the imported schema.',
|
|
318
|
+
}), overwrite: command_1.flags.boolean({
|
|
319
|
+
description: 'Overwrite any existing schema with the same name. Cannot be used' +
|
|
320
|
+
' without also providing a --name flag.',
|
|
321
|
+
dependsOn: ['name'],
|
|
322
|
+
hidden: true,
|
|
323
|
+
}) }), Import.commonIntrospectionFlags), Import.curlFlags), Import.sqlFlags), Import.postgresqlFlags);
|
|
248
324
|
Import.args = [
|
|
249
325
|
{
|
|
250
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
|
@@ -7,10 +7,7 @@ const command_1 = require("@oclif/command");
|
|
|
7
7
|
const errors_1 = require("@oclif/errors");
|
|
8
8
|
const throttle_debounce_1 = require("throttle-debounce");
|
|
9
9
|
const detect = require("detect-port");
|
|
10
|
-
const utils_1 = require("../shared/utils");
|
|
11
10
|
const start_1 = require("../start");
|
|
12
|
-
const workspace_1 = require("../shared/workspace");
|
|
13
|
-
const init_1 = require("./init");
|
|
14
11
|
const constants_1 = require("../shared/constants");
|
|
15
12
|
const zen_command_1 = require("../shared/zen-command");
|
|
16
13
|
const dashboard = require('@stepzen/dashboard');
|
|
@@ -19,28 +16,13 @@ class Start extends zen_command_1.default {
|
|
|
19
16
|
async run() {
|
|
20
17
|
const { flags } = this.parse(Start);
|
|
21
18
|
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
|
|
19
|
+
// Get or create a StepZen workspace (possibly interactive)
|
|
20
|
+
const workspace = await this.ensureStepZenWorkspace({
|
|
21
|
+
directory: flags.dir,
|
|
22
|
+
endpoint: flags.endpoint,
|
|
23
|
+
});
|
|
24
|
+
// If the user has overridden the endpoint, apply the override
|
|
42
25
|
if (flags.endpoint) {
|
|
43
|
-
// eslint-disable-next-line require-atomic-updates
|
|
44
26
|
workspace.endpoint = flags.endpoint;
|
|
45
27
|
}
|
|
46
28
|
// Check the port is available
|
|
@@ -50,25 +32,25 @@ class Start extends zen_command_1.default {
|
|
|
50
32
|
}
|
|
51
33
|
// This is the file watcher
|
|
52
34
|
if (!flags['no-watcher']) {
|
|
35
|
+
const redeploy = throttle_debounce_1.debounce(500, (path) => {
|
|
36
|
+
start_1.changed({ workspace, file: path });
|
|
37
|
+
start_1.deploy({ workspace, flags });
|
|
38
|
+
});
|
|
53
39
|
chokidar
|
|
54
|
-
.watch(
|
|
55
|
-
|
|
40
|
+
.watch(['**/*.graphql', 'config.yaml'], {
|
|
41
|
+
cwd: workspace.schema,
|
|
42
|
+
ignored: 'node_modules/**',
|
|
43
|
+
ignoreInitial: true,
|
|
56
44
|
})
|
|
57
|
-
.on('change',
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
await start_1.console(workspace);
|
|
61
|
-
}));
|
|
45
|
+
.on('change', redeploy)
|
|
46
|
+
.on('add', redeploy)
|
|
47
|
+
.on('unlink', redeploy);
|
|
62
48
|
}
|
|
63
49
|
// Start!
|
|
64
|
-
utils_1.clearConsole();
|
|
65
50
|
core_1.CliUx.ux.action.start('Starting...');
|
|
66
51
|
// Unless explicitly disabled, auto-init
|
|
67
52
|
if (!flags['no-init']) {
|
|
68
|
-
await start_1.deploy(
|
|
69
|
-
}
|
|
70
|
-
if (!flags['no-console']) {
|
|
71
|
-
start_1.console(workspace);
|
|
53
|
+
await start_1.deploy({ workspace, flags });
|
|
72
54
|
}
|
|
73
55
|
// Create the dashboard
|
|
74
56
|
if (!flags['no-dashboard']) {
|
|
@@ -92,9 +74,22 @@ class Start extends zen_command_1.default {
|
|
|
92
74
|
}
|
|
93
75
|
// Done
|
|
94
76
|
core_1.CliUx.ux.action.stop();
|
|
77
|
+
if (!flags['no-console']) {
|
|
78
|
+
if (!flags['no-init']) {
|
|
79
|
+
start_1.success({
|
|
80
|
+
workspace,
|
|
81
|
+
account: configuration.account,
|
|
82
|
+
port: flags.port,
|
|
83
|
+
});
|
|
84
|
+
this.log();
|
|
85
|
+
}
|
|
86
|
+
if (!flags['no-watcher']) {
|
|
87
|
+
start_1.watching(workspace);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
95
90
|
}
|
|
96
91
|
}
|
|
97
92
|
exports.default = Start;
|
|
98
93
|
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-
|
|
94
|
+
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
95
|
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
|
}
|