@takeshape/cli 8.89.2 → 8.96.0
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/lib/commands/types.d.ts +6 -0
- package/lib/commands/types.d.ts.map +1 -0
- package/lib/commands/types.js +30 -0
- package/lib/index.js +1 -0
- package/lib/main.d.ts.map +1 -1
- package/lib/main.js +1 -0
- package/lib/util/generate-types.d.ts +5 -0
- package/lib/util/generate-types.d.ts.map +1 -0
- package/lib/util/generate-types.js +63 -0
- package/lib/util/get-client-schema.d.ts +1 -0
- package/lib/util/get-client-schema.d.ts.map +1 -1
- package/lib/util/get-client-schema.js +6 -3
- package/package.json +10 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/commands/types.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,KAAK;IACpB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;;AAaD,wBAGG"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _linkedCommand = require("../util/linked-command");
|
|
9
|
+
|
|
10
|
+
var _generateTypes = require("../util/generate-types");
|
|
11
|
+
|
|
12
|
+
var _getClientSchema = require("../util/get-client-schema");
|
|
13
|
+
|
|
14
|
+
const DEFAULT_GENERATED_FILE = './takeshape.d.ts';
|
|
15
|
+
/*
|
|
16
|
+
takeshape types --to ./takeshape.d.ts
|
|
17
|
+
|
|
18
|
+
Generate TypeScript types from your TakeShape schema.
|
|
19
|
+
|
|
20
|
+
Options:
|
|
21
|
+
--in: if provided, will generate types used
|
|
22
|
+
--to: the path to save the download or the full file path, defaults to current directory
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
var _default = (0, _linkedCommand.linkedCommand)(async (command, params, flags) => {
|
|
26
|
+
const output = flags.to ?? DEFAULT_GENERATED_FILE;
|
|
27
|
+
void (0, _generateTypes.generateTypes)(_getClientSchema.SCHEMA_FILE_NAME, output);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
exports.default = _default;
|
package/lib/index.js
CHANGED
package/lib/main.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/main.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/main.js"],"names":[],"mappings":"AAkBA,qFAQC"}
|
package/lib/main.js
CHANGED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Uses [GraphQL Code Generator](https://www.graphql-code-generator.com/)
|
|
2
|
+
* to create TypeScript definitions from a GraphQL schema file.
|
|
3
|
+
*/
|
|
4
|
+
export declare function generateTypes(schemaFile: string, outputFile: string): Promise<void>;
|
|
5
|
+
//# sourceMappingURL=generate-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-types.d.ts","sourceRoot":"","sources":["../../../src/util/generate-types.ts"],"names":[],"mappings":"AAWA;;GAEG;AACH,wBAAsB,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA6BzF"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.generateTypes = generateTypes;
|
|
7
|
+
|
|
8
|
+
var _fsExtra = require("fs-extra");
|
|
9
|
+
|
|
10
|
+
var _path = require("path");
|
|
11
|
+
|
|
12
|
+
var _graphql = require("graphql");
|
|
13
|
+
|
|
14
|
+
var _core = require("@graphql-codegen/core");
|
|
15
|
+
|
|
16
|
+
var typescriptPlugin = _interopRequireWildcard(require("@graphql-codegen/typescript"));
|
|
17
|
+
|
|
18
|
+
var _load = require("@graphql-tools/load");
|
|
19
|
+
|
|
20
|
+
var _graphqlFileLoader = require("@graphql-tools/graphql-file-loader");
|
|
21
|
+
|
|
22
|
+
var _chalk = _interopRequireDefault(require("chalk"));
|
|
23
|
+
|
|
24
|
+
var _log = _interopRequireDefault(require("../log"));
|
|
25
|
+
|
|
26
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
|
+
|
|
28
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
29
|
+
|
|
30
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
31
|
+
|
|
32
|
+
/** Uses [GraphQL Code Generator](https://www.graphql-code-generator.com/)
|
|
33
|
+
* to create TypeScript definitions from a GraphQL schema file.
|
|
34
|
+
*/
|
|
35
|
+
async function generateTypes(schemaFile, outputFile) {
|
|
36
|
+
(0, _log.default)(`Generating types from ${schemaFile}…`);
|
|
37
|
+
const origin = (0, _path.join)(process.cwd(), schemaFile);
|
|
38
|
+
const destination = (0, _path.join)(process.cwd(), outputFile);
|
|
39
|
+
const schema = await (0, _load.loadSchema)(origin, {
|
|
40
|
+
loaders: [new _graphqlFileLoader.GraphQLFileLoader()]
|
|
41
|
+
});
|
|
42
|
+
const config = {
|
|
43
|
+
documents: [],
|
|
44
|
+
config: {},
|
|
45
|
+
// used by a plugin internally, although the 'typescript' plugin currently
|
|
46
|
+
// returns the string output, rather than writing to a file
|
|
47
|
+
filename: outputFile,
|
|
48
|
+
schema: (0, _graphql.parse)((0, _graphql.printSchema)(schema)),
|
|
49
|
+
plugins: [// Each plugin should be an object
|
|
50
|
+
{
|
|
51
|
+
typescript: {} // Here you can pass configuration to the plugin
|
|
52
|
+
|
|
53
|
+
}],
|
|
54
|
+
pluginMap: {
|
|
55
|
+
typescript: typescriptPlugin
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const output = await (0, _core.codegen)(config);
|
|
59
|
+
await (0, _fsExtra.ensureFile)(destination);
|
|
60
|
+
(0, _fsExtra.writeFile)(destination, output, () => {
|
|
61
|
+
(0, _log.default)(_chalk.default.green(`Success!`), `Saved generated types to ${outputFile}`);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-client-schema.d.ts","sourceRoot":"","sources":["../../../src/util/get-client-schema.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-client-schema.d.ts","sourceRoot":"","sources":["../../../src/util/get-client-schema.js"],"names":[],"mappings":"AAMA,+DAMC;AARD,2DAA4D"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = void 0;
|
|
6
|
+
exports.default = exports.SCHEMA_FILE_NAME = void 0;
|
|
7
7
|
exports.getClientSchema = getClientSchema;
|
|
8
8
|
|
|
9
9
|
var _graphql = require("graphql");
|
|
@@ -14,15 +14,18 @@ var _oraWrapper = _interopRequireDefault(require("./ora-wrapper"));
|
|
|
14
14
|
|
|
15
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
16
|
|
|
17
|
+
const SCHEMA_FILE_NAME = 'takeshape-project.graphql';
|
|
18
|
+
exports.SCHEMA_FILE_NAME = SCHEMA_FILE_NAME;
|
|
19
|
+
|
|
17
20
|
async function getClientSchema(connector) {
|
|
18
21
|
const res = await connector({
|
|
19
22
|
query: (0, _graphql.getIntrospectionQuery)()
|
|
20
23
|
});
|
|
21
24
|
const schema = (0, _graphql.buildClientSchema)(res.data);
|
|
22
25
|
const result = (0, _graphql.printSchema)(schema);
|
|
23
|
-
await _fsExtra.default.writeFile(
|
|
26
|
+
await _fsExtra.default.writeFile(SCHEMA_FILE_NAME, result);
|
|
24
27
|
}
|
|
25
28
|
|
|
26
|
-
var _default = (0, _oraWrapper.default)(getClientSchema, 'Getting client schema.',
|
|
29
|
+
var _default = (0, _oraWrapper.default)(getClientSchema, 'Getting client schema.', `Client schema saved as ${SCHEMA_FILE_NAME}.`, 'Failed while getting client schema.');
|
|
27
30
|
|
|
28
31
|
exports.default = _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@takeshape/cli",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.96.0",
|
|
4
4
|
"description": "TakeShape CLI",
|
|
5
5
|
"homepage": "https://www.takeshape.io",
|
|
6
6
|
"repository": {
|
|
@@ -20,10 +20,15 @@
|
|
|
20
20
|
"lib"
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@
|
|
24
|
-
"@
|
|
25
|
-
"@
|
|
26
|
-
"@
|
|
23
|
+
"@graphql-codegen/core": "^2.5.1",
|
|
24
|
+
"@graphql-codegen/plugin-helpers": "^2.4.1",
|
|
25
|
+
"@graphql-codegen/typescript": "^2.4.5",
|
|
26
|
+
"@graphql-tools/graphql-file-loader": "^7.3.3",
|
|
27
|
+
"@graphql-tools/load": "^7.5.1",
|
|
28
|
+
"@takeshape/schema": "8.96.0",
|
|
29
|
+
"@takeshape/ssg": "8.96.0",
|
|
30
|
+
"@takeshape/streams": "8.96.0",
|
|
31
|
+
"@takeshape/util": "8.96.0",
|
|
27
32
|
"archiver": "^1.3.0",
|
|
28
33
|
"async-retry": "^1.2.1",
|
|
29
34
|
"bluebird": "^3.4.6",
|