stepzen 0.12.0-beta.0 → 0.13.0-beta.1
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 +1 -1
- package/lib/commands/import.js +12 -3
- package/lib/commands/init.d.ts +4 -1
- package/lib/commands/init.js +69 -29
- package/lib/commands/start.js +14 -5
- package/lib/shared/curl-parser.js +65 -27
- package/lib/shared/moniker.d.ts +2 -0
- package/lib/shared/moniker.js +4 -5
- package/lib/shared/types.d.ts +11 -2
- package/lib/shared/utils.js +5 -4
- package/lib/shared/workspace.d.ts +2 -1
- package/lib/shared/workspace.js +39 -36
- 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.
|
|
32
|
+
stepzen/0.13.0-beta.1 darwin-x64 node-v14.19.1
|
|
33
33
|
$ stepzen --help [COMMAND]
|
|
34
34
|
USAGE
|
|
35
35
|
$ stepzen COMMAND
|
package/lib/commands/import.js
CHANGED
|
@@ -27,10 +27,19 @@ class Import extends command_1.Command {
|
|
|
27
27
|
'In order to use the --name flag please import each schema separately.');
|
|
28
28
|
}
|
|
29
29
|
// Get the working directory and workspace
|
|
30
|
+
let workspace;
|
|
30
31
|
const directory = utils_1.getDirectory(flags.dir);
|
|
31
|
-
|
|
32
|
-
if (
|
|
33
|
-
workspace =
|
|
32
|
+
const maybeWorkspace = workspace_1.getWorkspace(directory);
|
|
33
|
+
if (maybeWorkspace) {
|
|
34
|
+
workspace = maybeWorkspace;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
try {
|
|
38
|
+
workspace = await init_1.default.run([directory]);
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
throw new errors_1.CLIError(`Could not create a StepZen workspace in the ${flags.dir ? directory : 'current'} directory.\n` + error.message);
|
|
42
|
+
}
|
|
34
43
|
}
|
|
35
44
|
// Select an import execution flow:
|
|
36
45
|
// - v1 with `stepzen/engines` and cloud function
|
package/lib/commands/init.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { Command, flags } from '@oclif/command';
|
|
2
|
+
export declare const validateWorkspaceName: (directory: string, name: string) => boolean;
|
|
3
|
+
export declare const generateWorkspaceName: (directory: string) => string;
|
|
4
|
+
export declare const guessSchemaRoot: (directory: string) => string;
|
|
2
5
|
export default class Init extends Command {
|
|
3
6
|
static description: string;
|
|
4
7
|
static hidden: boolean;
|
|
@@ -7,5 +10,5 @@ export default class Init extends Command {
|
|
|
7
10
|
hidden: boolean;
|
|
8
11
|
name: string;
|
|
9
12
|
}[];
|
|
10
|
-
run(): Promise<
|
|
13
|
+
run(): Promise<import("../shared/types").Workspace>;
|
|
11
14
|
}
|
package/lib/commands/init.js
CHANGED
|
@@ -1,53 +1,85 @@
|
|
|
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;
|
|
4
5
|
const command_1 = require("@oclif/command");
|
|
5
6
|
const errors_1 = require("@oclif/errors");
|
|
6
7
|
const fs = require("fs");
|
|
7
8
|
const glob = require("glob");
|
|
8
9
|
const inquirer = require("inquirer");
|
|
10
|
+
const os = require("os");
|
|
9
11
|
const path = require("path");
|
|
10
12
|
const utils_1 = require("../shared/utils");
|
|
11
13
|
const moniker_1 = require("../shared/moniker");
|
|
12
14
|
const workspace_1 = require("../shared/workspace");
|
|
15
|
+
exports.validateWorkspaceName = (directory, name) => {
|
|
16
|
+
return !fs.existsSync(path.join(directory, name));
|
|
17
|
+
};
|
|
18
|
+
exports.generateWorkspaceName = (directory) => {
|
|
19
|
+
let name = 'hello-stepzen';
|
|
20
|
+
while (!exports.validateWorkspaceName(directory, name)) {
|
|
21
|
+
name = `hello-${moniker_1.getRandomDescriptor()}-stepzen`;
|
|
22
|
+
}
|
|
23
|
+
return name;
|
|
24
|
+
};
|
|
25
|
+
exports.guessSchemaRoot = (directory) => {
|
|
26
|
+
const existing = [
|
|
27
|
+
...glob.sync('*/**/config.yaml', {
|
|
28
|
+
cwd: directory,
|
|
29
|
+
ignore: '**/node_modules/**',
|
|
30
|
+
}),
|
|
31
|
+
...glob.sync('*/**/index.graphql', {
|
|
32
|
+
cwd: directory,
|
|
33
|
+
ignore: '**/node_modules/**',
|
|
34
|
+
}),
|
|
35
|
+
];
|
|
36
|
+
return existing.length > 0 ? path.dirname(existing[0]) : '';
|
|
37
|
+
};
|
|
13
38
|
class Init extends command_1.Command {
|
|
14
39
|
async run() {
|
|
15
40
|
const { args, flags } = this.parse(Init);
|
|
16
41
|
// Get the correct directory
|
|
17
|
-
|
|
42
|
+
let directory = utils_1.getDirectory(args.directory);
|
|
18
43
|
// Make sure it is not already a workspace
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
44
|
+
if (workspace_1.getWorkspace(directory)) {
|
|
45
|
+
throw new errors_1.CLIError(`This directory is already a StepZen workspace: ${directory}.` +
|
|
46
|
+
' Please select a different directory.');
|
|
47
|
+
}
|
|
48
|
+
const isHomeDir = directory === os.homedir();
|
|
49
|
+
// Prevent init from running in the home directory if the directory was
|
|
50
|
+
// explicitly provided as an aargument to `stepzen init`.
|
|
51
|
+
// StepZen CLI sometimes would enumerate all files in the workspace folder
|
|
52
|
+
// doing so in the home directory is likely to fail.
|
|
53
|
+
if (args.directory && isHomeDir) {
|
|
54
|
+
throw new errors_1.CLIError('Using the home directory as a StepZen workspace is not supported.' +
|
|
55
|
+
' Please select a different directory.');
|
|
56
|
+
}
|
|
57
|
+
// Make a suggestion for the workspace name (if running in the HOME
|
|
58
|
+
// directory)
|
|
59
|
+
const name = isHomeDir
|
|
60
|
+
? exports.generateWorkspaceName(directory)
|
|
61
|
+
: path.basename(directory);
|
|
62
|
+
// See if we think there's a StepZen schema already
|
|
63
|
+
const root = isHomeDir ? '' : exports.guessSchemaRoot(directory);
|
|
64
|
+
// If you've passed an endpoint, validate it, and throw an error
|
|
65
|
+
// straight away if needed
|
|
23
66
|
if (flags.endpoint) {
|
|
24
67
|
const error = utils_1.validateEndpoint(flags.endpoint);
|
|
25
|
-
if (typeof error === 'string')
|
|
68
|
+
if (typeof error === 'string') {
|
|
26
69
|
throw new errors_1.CLIError(error);
|
|
70
|
+
}
|
|
27
71
|
}
|
|
28
72
|
// Make a suggestion for the endpoint
|
|
29
73
|
const endpoint = flags.endpoint || `api/${moniker_1.default()}`;
|
|
30
|
-
// See if we think there's a StepZen schema already
|
|
31
|
-
let root;
|
|
32
|
-
const existing = [
|
|
33
|
-
...glob.sync('*/**/config.yaml', {
|
|
34
|
-
cwd: directory,
|
|
35
|
-
ignore: '**/node_modules/**',
|
|
36
|
-
}),
|
|
37
|
-
...glob.sync('*/**/index.graphql', {
|
|
38
|
-
cwd: directory,
|
|
39
|
-
ignore: '**/node_modules/**',
|
|
40
|
-
}),
|
|
41
|
-
];
|
|
42
|
-
if (existing.length > 0) {
|
|
43
|
-
root = existing[0]
|
|
44
|
-
.replace('config.yaml', '')
|
|
45
|
-
.replace('index.graphql', '')
|
|
46
|
-
.replace(/\/*$/, '');
|
|
47
|
-
}
|
|
48
|
-
const hasRoot = existing.length > 0;
|
|
49
74
|
// What questions will we ask?
|
|
50
75
|
const questions = [
|
|
76
|
+
{
|
|
77
|
+
default: name,
|
|
78
|
+
message: 'What would you like to call your workspace?',
|
|
79
|
+
name: 'name',
|
|
80
|
+
validate: (name) => exports.validateWorkspaceName(directory, name),
|
|
81
|
+
when: isHomeDir && !flags.yes,
|
|
82
|
+
},
|
|
51
83
|
{
|
|
52
84
|
default: endpoint,
|
|
53
85
|
message: 'What would you like your endpoint to be called?',
|
|
@@ -59,14 +91,22 @@ class Init extends command_1.Command {
|
|
|
59
91
|
message: `We have detected a schema in this directory. Set the schema root to "${root}"?`,
|
|
60
92
|
name: 'use-root',
|
|
61
93
|
type: 'confirm',
|
|
62
|
-
when:
|
|
94
|
+
when: Boolean(root) && !flags.yes,
|
|
63
95
|
},
|
|
64
96
|
];
|
|
65
97
|
// Get the answers
|
|
66
|
-
const answers = Object.assign({
|
|
98
|
+
const answers = Object.assign({ name,
|
|
99
|
+
endpoint, 'use-root': true }, (await inquirer.prompt(questions)));
|
|
100
|
+
// Append the suggested workspace name to the directory (if running
|
|
101
|
+
// in the HOME directory)
|
|
102
|
+
if (isHomeDir) {
|
|
103
|
+
// eslint-disable-next-line require-atomic-updates
|
|
104
|
+
directory = path.join(directory, answers.name);
|
|
105
|
+
fs.mkdirSync(directory);
|
|
106
|
+
}
|
|
67
107
|
// Create the workspace
|
|
68
108
|
const workspace = { endpoint: answers.endpoint };
|
|
69
|
-
if (
|
|
109
|
+
if (root && answers['use-root'])
|
|
70
110
|
workspace.root = root;
|
|
71
111
|
// Write the file
|
|
72
112
|
const file = path.join(directory, 'stepzen.config.json');
|
|
@@ -74,7 +114,7 @@ class Init extends command_1.Command {
|
|
|
74
114
|
// Fetch the newly created workspace
|
|
75
115
|
const created = workspace_1.getWorkspace(directory);
|
|
76
116
|
// Done!
|
|
77
|
-
this.log(`Created ${
|
|
117
|
+
this.log(`Created a StepZen workspace in ${created.directory}`);
|
|
78
118
|
return created;
|
|
79
119
|
}
|
|
80
120
|
}
|
package/lib/commands/start.js
CHANGED
|
@@ -25,14 +25,23 @@ class Start extends command_1.Command {
|
|
|
25
25
|
throw new errors_1.CLIError('You are probably not logged in.');
|
|
26
26
|
}
|
|
27
27
|
// Get the working directory and workspace
|
|
28
|
+
let workspace;
|
|
28
29
|
const directory = utils_1.getDirectory(flags.dir);
|
|
29
|
-
|
|
30
|
-
if (
|
|
30
|
+
const maybeWorkspace = workspace_1.getWorkspace(directory);
|
|
31
|
+
if (maybeWorkspace) {
|
|
32
|
+
workspace = maybeWorkspace;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
31
35
|
const initArgs = [directory];
|
|
32
|
-
if (flags.endpoint)
|
|
36
|
+
if (flags.endpoint) {
|
|
33
37
|
initArgs.push('--endpoint', flags.endpoint);
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
workspace = await init_1.default.run(initArgs);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
throw new errors_1.CLIError(`Could not create a StepZen workspace in the ${flags.dir ? directory : 'current'} directory.\n` + error.message);
|
|
44
|
+
}
|
|
36
45
|
}
|
|
37
46
|
// If you have overridden the endpoint, set it
|
|
38
47
|
if (flags.endpoint) {
|
|
@@ -46,13 +46,8 @@ exports.parseCurlHeaderString = (header) => {
|
|
|
46
46
|
};
|
|
47
47
|
const isAFlagArg = (arg) => curlFlagRegex.test(arg);
|
|
48
48
|
const isAURL = (arg) => httpURLRegex.test(arg);
|
|
49
|
-
const parseHeaderFlag = (
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
error: `The '${argv[i]}' curl flag requires a value`,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
const headerOrError = exports.parseCurlHeaderString(argv[i + 1]);
|
|
49
|
+
const parseHeaderFlag = (value, partialCurlArgs) => {
|
|
50
|
+
const headerOrError = exports.parseCurlHeaderString(value);
|
|
56
51
|
if (headerOrError && 'error' in headerOrError) {
|
|
57
52
|
return headerOrError; // error
|
|
58
53
|
}
|
|
@@ -65,26 +60,31 @@ const parseHeaderFlag = (argv, i, partialCurlArgs) => {
|
|
|
65
60
|
}
|
|
66
61
|
return {
|
|
67
62
|
result: Object.assign(Object.assign({}, partialCurlArgs), { headers }),
|
|
68
|
-
skip: 1,
|
|
69
63
|
};
|
|
70
64
|
};
|
|
71
|
-
const parseDataFlag = (
|
|
72
|
-
if (
|
|
73
|
-
return {
|
|
74
|
-
error: `The '${argv[i]}' curl flag requires a value`,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
if (argv[i] !== '--data-raw' && argv[i + 1].charAt(0) === '@') {
|
|
65
|
+
const parseDataFlag = (value, partialCurlArgs, match) => {
|
|
66
|
+
if (match !== '--data-raw' && value.charAt(0) === '@') {
|
|
78
67
|
return {
|
|
79
68
|
error: `Reading request data from local files in not currently supported ` +
|
|
80
|
-
`by StepZen CLI (${
|
|
69
|
+
`by StepZen CLI (${match} ${value}). If this is a blocker ` +
|
|
81
70
|
`for you, please let us know on Discord (${constants_1.STEPZEN_DISCORD_URL})`,
|
|
82
71
|
};
|
|
83
72
|
}
|
|
84
|
-
const data = (partialCurlArgs.data ? partialCurlArgs.data + '&' : '') +
|
|
73
|
+
const data = (partialCurlArgs.data ? partialCurlArgs.data + '&' : '') + value;
|
|
85
74
|
return {
|
|
86
75
|
result: Object.assign(Object.assign({}, partialCurlArgs), { data }),
|
|
87
|
-
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
const parseMethodFlag = (value, partialCurlArgs) => {
|
|
79
|
+
const lowercaseMethod = value.toLowerCase();
|
|
80
|
+
if (lowercaseMethod !== 'post' && lowercaseMethod !== 'get') {
|
|
81
|
+
return {
|
|
82
|
+
error: `The method ${value} is currently not supported.`,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
const method = lowercaseMethod === 'post' ? 'Post' : 'Get';
|
|
86
|
+
return {
|
|
87
|
+
result: Object.assign(Object.assign({}, partialCurlArgs), { method }),
|
|
88
88
|
};
|
|
89
89
|
};
|
|
90
90
|
const flags = [
|
|
@@ -96,7 +96,34 @@ const flags = [
|
|
|
96
96
|
matches: ['-d', '--data', '--data-ascii', '--data-raw', '--data-binary'],
|
|
97
97
|
parse: parseDataFlag,
|
|
98
98
|
},
|
|
99
|
+
{
|
|
100
|
+
matches: ['-X', '--request'],
|
|
101
|
+
parse: parseMethodFlag,
|
|
102
|
+
},
|
|
99
103
|
];
|
|
104
|
+
const tryMatchCurlFlag = (matches, argv, i) => {
|
|
105
|
+
for (const match of matches) {
|
|
106
|
+
const isShortFlag = match.length === 2;
|
|
107
|
+
if (isShortFlag && argv[i].startsWith(match) && argv[i].length > 2) {
|
|
108
|
+
return {
|
|
109
|
+
value: argv[i].substring(2),
|
|
110
|
+
match,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
if (argv[i] === match) {
|
|
114
|
+
if (i + 1 >= argv.length) {
|
|
115
|
+
return {
|
|
116
|
+
error: `The '${argv[i]}' curl flag requires a value`,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
value: argv[i + 1],
|
|
121
|
+
match,
|
|
122
|
+
skip: 1,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
};
|
|
100
127
|
/**
|
|
101
128
|
* Parse a curl command line arguments array to a JSON structure consumable by
|
|
102
129
|
* the StepZen introspection service backend.
|
|
@@ -120,16 +147,27 @@ exports.parseCurlArgv = (argv) => {
|
|
|
120
147
|
let result = {};
|
|
121
148
|
for (let i = 0; i < argv.length; i++) {
|
|
122
149
|
if (isAFlagArg(argv[i])) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
if (
|
|
127
|
-
|
|
150
|
+
let isKnownFlag = false;
|
|
151
|
+
for (const flag of flags) {
|
|
152
|
+
const matcherResult = tryMatchCurlFlag(flag.matches, argv, i);
|
|
153
|
+
if (!matcherResult) {
|
|
154
|
+
// no match => try matching the next flag
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
if ('error' in matcherResult) {
|
|
158
|
+
// flag matched but it requies a value which is missing
|
|
159
|
+
return matcherResult;
|
|
160
|
+
}
|
|
161
|
+
const parserResult = flag.parse(matcherResult.value, result, matcherResult.match);
|
|
162
|
+
if ('error' in parserResult) {
|
|
163
|
+
return parserResult;
|
|
128
164
|
}
|
|
129
|
-
result =
|
|
130
|
-
i +=
|
|
165
|
+
result = parserResult.result;
|
|
166
|
+
i += matcherResult.skip || 0;
|
|
167
|
+
isKnownFlag = true;
|
|
168
|
+
break;
|
|
131
169
|
}
|
|
132
|
-
|
|
170
|
+
if (!isKnownFlag) {
|
|
133
171
|
return {
|
|
134
172
|
error: `The '${argv[i]}' curl flag is not currently supported by StepZen CLI.` +
|
|
135
173
|
` If this is a blocker for you, please let us know on Discord (${constants_1.STEPZEN_DISCORD_URL})`,
|
|
@@ -159,7 +197,7 @@ exports.parseCurlArgv = (argv) => {
|
|
|
159
197
|
};
|
|
160
198
|
}
|
|
161
199
|
result.headers = result.headers || [];
|
|
162
|
-
result.method = result.method || result.data ? 'Post' : 'Get';
|
|
200
|
+
result.method = result.method || (result.data ? 'Post' : 'Get');
|
|
163
201
|
// Add the default content-type header if the request has any data
|
|
164
202
|
// in it, and no content-type header is explicitly provided.
|
|
165
203
|
if (result.headers.findIndex(header => header.name.toLowerCase() === 'content-type') === -1 &&
|
package/lib/shared/moniker.d.ts
CHANGED
package/lib/shared/moniker.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Copyright (c) 2020,2021,2022, StepZen, Inc.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.getRandomDescriptor = exports.getRandomAnimal = void 0;
|
|
4
5
|
const lodash_1 = require("lodash");
|
|
5
6
|
const animals = [
|
|
6
7
|
'aardvark',
|
|
@@ -637,8 +638,6 @@ const descriptors = [
|
|
|
637
638
|
'zinc',
|
|
638
639
|
'zooming',
|
|
639
640
|
];
|
|
640
|
-
exports.
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
return `${descriptor}-${animal}`;
|
|
644
|
-
};
|
|
641
|
+
exports.getRandomAnimal = () => animals[lodash_1.random(0, animals.length - 1)];
|
|
642
|
+
exports.getRandomDescriptor = () => descriptors[lodash_1.random(0, descriptors.length - 1)];
|
|
643
|
+
exports.default = () => `${exports.getRandomDescriptor()}-${exports.getRandomAnimal()}`;
|
package/lib/shared/types.d.ts
CHANGED
|
@@ -3,11 +3,20 @@ export interface MachineConfiguration {
|
|
|
3
3
|
adminkey: string;
|
|
4
4
|
apikey?: string;
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* On-disk representation of a workspace config file, `stepzen.config.json`
|
|
8
|
+
*/
|
|
6
9
|
export interface WorkspaceConfiguration {
|
|
7
|
-
directory?: string;
|
|
8
10
|
endpoint: string;
|
|
9
11
|
root?: string;
|
|
10
|
-
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* In-memory representation of a workspace config
|
|
15
|
+
*/
|
|
16
|
+
export interface Workspace {
|
|
17
|
+
endpoint: string;
|
|
18
|
+
directory: string;
|
|
19
|
+
schema: string;
|
|
11
20
|
}
|
|
12
21
|
export interface ZenCtlResponse {
|
|
13
22
|
errors?: Array<string>;
|
package/lib/shared/utils.js
CHANGED
|
@@ -68,11 +68,12 @@ exports.ensureApiKey = async () => {
|
|
|
68
68
|
exports.getDirectory = (d = process.cwd()) => {
|
|
69
69
|
let directory = d;
|
|
70
70
|
// If it starts with `~`, expand this
|
|
71
|
-
if (directory.startsWith('~'))
|
|
71
|
+
if (directory.startsWith('~')) {
|
|
72
72
|
directory = directory.replace('~', os.homedir());
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
}
|
|
74
|
+
// If it does not now start with `/`, then get the absolute path.
|
|
75
|
+
// Also, remove any `..` and `.` segments.
|
|
76
|
+
directory = path.resolve(directory);
|
|
76
77
|
// If the path does not exist, throw an error
|
|
77
78
|
if (!fs.existsSync(directory)) {
|
|
78
79
|
throw new errors_1.CLIError(`Cannot find ${directory}`);
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { Workspace } from './types';
|
|
2
|
+
export declare const getWorkspace: (directory: string) => Workspace | null;
|
package/lib/shared/workspace.js
CHANGED
|
@@ -4,50 +4,53 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.getWorkspace = void 0;
|
|
5
5
|
const errors_1 = require("@oclif/errors");
|
|
6
6
|
const fs = require("fs");
|
|
7
|
+
const os = require("os");
|
|
7
8
|
const path = require("path");
|
|
8
9
|
const utils_1 = require("./utils");
|
|
9
10
|
exports.getWorkspace = (directory) => {
|
|
10
|
-
let
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
// Loop through this and all parent directories to find the root
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const d = `${parts.join(path.sep)}`.replace(/\/*$/, '');
|
|
11
|
+
let workspaceRoot;
|
|
12
|
+
const parts = path
|
|
13
|
+
// Remove trailing slashes and any `..` and `.` segments
|
|
14
|
+
.resolve(directory)
|
|
15
|
+
// split into segments
|
|
16
|
+
.split(path.sep);
|
|
17
|
+
// Loop through this and all parent directories up to $HOME to find the root
|
|
18
|
+
for (; parts.length > 0; parts.pop()) {
|
|
19
|
+
const d = parts.join(path.sep);
|
|
20
20
|
const f = path.join(d, 'stepzen.config.json');
|
|
21
21
|
if (fs.existsSync(f)) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
parts.pop();
|
|
26
|
-
} while (parts.length > 0);
|
|
27
|
-
// If it's found a workspace, then parse the configuration file
|
|
28
|
-
if (workspace.directory) {
|
|
29
|
-
const filepath = path.join(workspace.directory, 'stepzen.config.json');
|
|
30
|
-
const file = fs.readFileSync(filepath, 'utf8');
|
|
31
|
-
try {
|
|
32
|
-
const config = JSON.parse(file);
|
|
33
|
-
workspace = Object.assign(Object.assign({}, workspace), config);
|
|
22
|
+
workspaceRoot = d;
|
|
23
|
+
break;
|
|
34
24
|
}
|
|
35
|
-
|
|
36
|
-
|
|
25
|
+
if (d === os.homedir()) {
|
|
26
|
+
break;
|
|
37
27
|
}
|
|
38
28
|
}
|
|
39
|
-
|
|
40
|
-
|
|
29
|
+
if (!workspaceRoot) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
const filepath = path.join(workspaceRoot, 'stepzen.config.json');
|
|
33
|
+
const file = fs.readFileSync(filepath, 'utf8');
|
|
34
|
+
let config;
|
|
35
|
+
try {
|
|
36
|
+
config = JSON.parse(file);
|
|
37
|
+
}
|
|
38
|
+
catch (_a) {
|
|
39
|
+
throw new errors_1.CLIError(`Cannot parse configuration from ${filepath}`);
|
|
40
|
+
}
|
|
41
41
|
// Validate the workspace
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
const error = utils_1.validateEndpoint(config.endpoint);
|
|
43
|
+
if (typeof error === 'string') {
|
|
44
|
+
throw new errors_1.CLIError(error);
|
|
45
|
+
}
|
|
46
|
+
// Add the 'schema' property, which is the directory + the 'root'
|
|
47
|
+
const schema = path.join(workspaceRoot, config.root || '');
|
|
48
|
+
if (!fs.existsSync(schema)) {
|
|
49
|
+
throw new errors_1.CLIError(`Cannot find workspace schema folder ${schema}`);
|
|
50
50
|
}
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
return {
|
|
52
|
+
directory: workspaceRoot,
|
|
53
|
+
endpoint: config.endpoint,
|
|
54
|
+
schema: schema,
|
|
55
|
+
};
|
|
53
56
|
};
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"0.
|
|
1
|
+
{"version":"0.13.0-beta.1","commands":{"deploy":{"id":"deploy","description":"deploy to stepzen","pluginName":"stepzen","pluginType":"core","aliases":[],"flags":{"configurationsets":{"name":"configurationsets","type":"option","description":"Configurationsets to use","default":""},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"schema":{"name":"schema","type":"option","description":"Schema to use","required":true},"silent":{"name":"silent","type":"boolean","allowNo":false}},"args":[{"name":"destination","description":"destination","required":true}]},"import":{"id":"import","description":"Import a schema for an external data source or a API endpoint to your GraphQL API.","pluginName":"stepzen","pluginType":"core","aliases":[],"flags":{"dir":{"name":"dir","type":"option","description":"working directory"},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"silent":{"name":"silent","type":"boolean","hidden":true,"allowNo":false},"name":{"name":"name","type":"option","description":"subfolder inside the workspace folder to save the imported schema files, defaults to the imported schema name"},"prefix":{"name":"prefix","type":"option","description":"[curl] prefix to add every type in the generated schema."},"query-name":{"name":"query-name","type":"option","description":"[curl] property name to add to the Query type as a way to access the imported cURL endpoint."},"query-type":{"name":"query-type","type":"option","description":"[curl] name for the type returned by the cURL endpoint in the generated schema. The name specified by --query-type is not prefixed by --prefix if both flags are present."},"path-params":{"name":"path-params","type":"option","description":"[curl] specifies path parameters in the URL path. Can be formed by taking the original path and replacing the variable segments with $paramName placeholders.\n\nExample:\nstepzen import curl https://example.com/users/jane/posts/12 --path-params '/users/$userId/posts/$postId'"}},"args":[{"name":"schemas","required":true}]},"init":{"id":"init","description":"stepzen init","pluginName":"stepzen","pluginType":"core","hidden":true,"aliases":[],"flags":{"endpoint":{"name":"endpoint","type":"option","hidden":true},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"yes":{"name":"yes","type":"boolean","hidden":true,"allowNo":false}},"args":[{"name":"directory","hidden":true}]},"lint":{"id":"lint","description":"stepzen lint","pluginName":"stepzen","pluginType":"core","hidden":true,"aliases":[],"flags":{"dir":{"name":"dir","type":"option","hidden":true},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"list":{"id":"list","description":"list your items","pluginName":"stepzen","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[{"name":"type","description":"type","required":true,"options":["configurationsets","schemas"]}]},"login":{"id":"login","description":"log in to stepzen","pluginName":"stepzen","pluginType":"core","aliases":[],"flags":{"account":{"name":"account","type":"option","char":"a","hidden":true},"adminkey":{"name":"adminkey","type":"option","char":"k","hidden":true},"config":{"name":"config","type":"option","hidden":true},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"logout":{"id":"logout","description":"log out of stepzen","pluginName":"stepzen","pluginType":"core","aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[]},"start":{"id":"start","description":"upload and deploy your schema","pluginName":"stepzen","pluginType":"core","aliases":[],"flags":{"dir":{"name":"dir","type":"option","description":"working directory"},"endpoint":{"name":"endpoint","type":"option","description":"Override workspace endpoint"},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"no-console":{"name":"no-console","type":"boolean","hidden":true,"allowNo":false},"no-dashboard":{"name":"no-dashboard","type":"boolean","hidden":true,"allowNo":false},"no-init":{"name":"no-init","type":"boolean","hidden":true,"allowNo":false},"no-server":{"name":"no-server","type":"boolean","hidden":true,"allowNo":false},"no-validate":{"name":"no-validate","type":"boolean","hidden":true,"allowNo":false},"no-watcher":{"name":"no-watcher","type":"boolean","hidden":true,"allowNo":false},"port":{"name":"port","type":"option","default":5001}},"args":[]},"transpile":{"id":"transpile","description":"transpile a graphql schema","pluginName":"stepzen","pluginType":"core","hidden":true,"aliases":[],"flags":{"config":{"name":"config","type":"option","hidden":true},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"hide-output":{"name":"hide-output","type":"boolean","hidden":true,"allowNo":false},"inspect":{"name":"inspect","type":"boolean","char":"i","hidden":true,"allowNo":false},"inspect-after":{"name":"inspect-after","type":"boolean","hidden":true,"allowNo":false},"output-configuration":{"name":"output-configuration","type":"boolean","allowNo":false},"silent":{"name":"silent","type":"boolean","allowNo":false}},"args":[{"name":"folder","required":true}]},"upload":{"id":"upload","description":"upload to stepzen","pluginName":"stepzen","pluginType":"core","aliases":[],"flags":{"dir":{"name":"dir","type":"option","description":"A directory to upload"},"file":{"name":"file","type":"option","description":"A file to upload"},"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"silent":{"name":"silent","type":"boolean","allowNo":false}},"args":[{"name":"type","description":"type","required":true,"options":["configurationset","schema"]},{"name":"destination","description":"destination","required":true}]},"validate":{"id":"validate","description":"validate a graphql schema","pluginName":"stepzen","pluginType":"core","hidden":true,"aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false}},"args":[{"name":"folder","required":true}]},"whoami":{"id":"whoami","description":"stepzen whoami","pluginName":"stepzen","pluginType":"core","hidden":true,"aliases":[],"flags":{"help":{"name":"help","type":"boolean","char":"h","description":"show CLI help","allowNo":false},"showkeys":{"name":"showkeys","type":"boolean","allowNo":false},"apikey":{"name":"apikey","type":"boolean","allowNo":false},"adminkey":{"name":"adminkey","type":"boolean","allowNo":false}},"args":[]}}}
|