Jelajahi Sumber

chore(server): Tidy up unused deps, scripts & update readme

Michael Bromley 7 tahun lalu
induk
melakukan
39eff3672a
4 mengubah file dengan 21 tambahan dan 815 penghapusan
  1. 12 2
      README.md
  2. 0 106
      generate-graphql-types.ts
  3. 1 3
      package.json
  4. 8 704
      yarn.lock

+ 12 - 2
README.md

@@ -16,6 +16,16 @@ the server is located in the `server` directory.
 We will ship with an administration UI which is a stand-alone web application which can be used to perform tasks such
 as inventory, order and customer management. The code for this is located in the `admin-ui` directory.
 
+```
+vendure/
+├── admin-ui/       # Source of the admin ui app (an Angular CLI project)
+├── codegen/        # Scripts used to generate TypeScript types from the GraphQL schemas & documents
+├── docs/           # Documentation source (not much there yet)
+├── server/         # Source for the Vendure server
+├── shared/         # Types and utils shared by the server & admin ui
+
+```
+
 ## Development
 
 ### Server
@@ -39,8 +49,8 @@ Vendure uses [TypeORM](http://typeorm.io), so it compatible will any database wh
 
 ### Code Generation
 
-[apollo-cli](https://github.com/apollographql/apollo-cli) is used to automatically create TypeScript interfaces
-for all GraphQL queries used in the admin ui. These generated interfaces are used in both the admin ui and the server.
+[graphql-code-generator](https://github.com/dotansimha/graphql-code-generator) is used to automatically create TypeScript interfaces
+for all GraphQL server operations and admin ui queries. These generated interfaces are used in both the admin ui and the server.
 
 Run `yarn generate-gql-types` to generate TypeScript interfaces based on these queries. The generated
 types are located at [`./shared/generated-types.ts`](./shared/generated-types.ts).

+ 0 - 106
generate-graphql-types.ts

@@ -1,106 +0,0 @@
-import { spawn } from 'child_process';
-import * as fs from 'fs';
-
-import { API_PATH, API_PORT } from './shared/shared-constants';
-
-// tslint:disable:no-console
-const API_URL = `http://localhost:${API_PORT}/${API_PATH}`;
-const SCHEMA_JSON_FILE = './schema.json';
-const CLIENT_SCHEMA_FILES = './admin-ui/src/app/data/client-state/client-types.graphql';
-const CLIENT_QUERY_FILES = '"./admin-ui/src/app/data/definitions/*.ts"';
-const TYPESCRIPT_DEFINITIONS_FILE = './shared/generated-types.ts';
-
-main().catch(e => {
-    console.log('Could not generate types!', e);
-    process.exitCode = 1;
-});
-
-/**
- * This script uses apollo-codegen to generate TypeScript interfaces for all
- * GraphQL queries defined in the admin-ui app. Run it via the package.json
- * script "generate-gql-types".
- */
-async function main(): Promise<void> {
-    try {
-        await downloadSchemaFromApi(API_URL, SCHEMA_JSON_FILE);
-    } catch {
-        console.log('Could not connect to Vendure server. Attempting to build typed from existing schema.json');
-    }
-    await generateTypeScriptTypesFromSchema(
-        SCHEMA_JSON_FILE,
-        CLIENT_SCHEMA_FILES,
-        CLIENT_QUERY_FILES,
-        TYPESCRIPT_DEFINITIONS_FILE,
-    );
-}
-
-/**
- * Downloads the schema from the provided GraphQL endpoint using the `apollo schema:download`
- * cli command and returns the result as an IntrospectionQuery object.
- */
-async function downloadSchemaFromApi(apiEndpoint: string, outputFile: string): Promise<void> {
-    console.log(`Downloading schema from ${API_URL}`);
-    const TEMP_API_SCHEMA = '../schema.temp.json';
-    await runCommand('yarn', ['apollo', 'schema:download', TEMP_API_SCHEMA, `--endpoint=${API_URL}`]);
-
-    console.log(`Downloaded schema from ${API_URL}`);
-
-    const schemaFromApi = fs.readFileSync(TEMP_API_SCHEMA, { encoding: 'utf8' });
-    fs.unlinkSync(TEMP_API_SCHEMA);
-    const introspectionSchema = JSON.parse(schemaFromApi);
-    fs.writeFileSync(
-        SCHEMA_JSON_FILE,
-        JSON.stringify({
-            __schema: introspectionSchema,
-        }),
-    );
-}
-
-/**
- * Generates TypeScript definitions from the provided schema json file sing the `apollo codegen:generate` cli command.
- */
-async function generateTypeScriptTypesFromSchema(
-    schemaFile: string,
-    clientSchemaFiles: string,
-    queryFiles: string,
-    outputFile: string,
-): Promise<number> {
-    return runCommand('yarn', [
-        'apollo',
-        'codegen:generate',
-        outputFile,
-        '--addTypename',
-        '--outputFlat',
-        '--target=typescript',
-        `--clientSchema=${clientSchemaFiles}`,
-        `--queries=${queryFiles}`,
-        `--schema=${schemaFile}`,
-    ]);
-}
-
-/**
- * Runs a command-line command and resolves when completed.
- */
-function runCommand(command: string, args: string[]): Promise<number> {
-    return new Promise((resolve, reject) => {
-        const cp = spawn(command, args, { shell: true });
-
-        cp.on('error', reject);
-        cp.stdout.on('data', data => {
-            if (4 < data.length) {
-                console.log(`${data}`);
-            }
-        });
-        cp.stderr.on('data', data => {
-            if (4 < data.length) {
-                console.log(`${data}`);
-            }
-        });
-        cp.on('close', code => {
-            if (code !== 0) {
-                reject(code);
-            }
-            resolve(code);
-        });
-    });
-}

+ 1 - 3
package.json

@@ -3,8 +3,7 @@
   "version": "0.1.0",
   "scripts": {
     "apollo": "apollo",
-    "generate-gql-types": "ts-node generate-graphql-types.ts",
-    "generate-gql-types2": "ts-node ./codegen/generate-graphql-types.ts",
+    "generate-gql-types": "ts-node ./codegen/generate-graphql-types.ts",
     "postinstall": "cd admin-ui && yarn && cd ../server && yarn",
     "test": "cd admin-ui && yarn test --watch=false --browsers=ChromeHeadlessCI --progress=false && cd ../server && yarn test && yarn test:e2e",
     "format": "prettier --write",
@@ -15,7 +14,6 @@
     "prepush": "yarn test && cd admin-ui && yarn build --prod"
   },
   "devDependencies": {
-    "apollo": "^1.7.1",
     "graphql": "^14.0.2",
     "graphql-code-generator": "^0.12.6",
     "graphql-codegen-typescript-template": "^0.12.6",

File diff ditekan karena terlalu besar
+ 8 - 704
yarn.lock


Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini