Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/buildandesm #49

Merged
merged 8 commits into from
Nov 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 79 additions & 65 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,67 +1,81 @@
{
"name": "@lymeodev/apollon",
"version": "1.1.5",
"description": "Project apollon's goal is to simplify GraphQl API development and to offer a modulable structure to start building an API in minutes.",
"main": "src/index.js",
"scripts": {
"start": "node src/index.js prod",
"dev": "node src/index.js dev",
"nodemon": "nodemon -e js,json,gql src/index.js dev",
"schema": "node src/schemaGenerator.js",
"update": "node src/updates",
"test": "node src/index.js test"
},
"keywords": [],
"author": "lymeo",
"license": "ISC",
"dependencies": {
"@babel/cli": "^7.7.0",
"@babel/core": "^7.7.2",
"@babel/plugin-proposal-class-properties": "^7.7.0",
"@babel/plugin-proposal-decorators": "^7.7.0",
"@babel/plugin-proposal-do-expressions": "^7.0.0-beta.55",
"@babel/plugin-proposal-export-default-from": "^7.0.0-beta.55",
"@babel/plugin-proposal-export-namespace-from": "^7.0.0-beta.55",
"@babel/plugin-proposal-function-bind": "^7.0.0-beta.55",
"@babel/plugin-proposal-function-sent": "^7.7.0",
"@babel/plugin-proposal-json-strings": "^7.0.0-beta.55",
"@babel/plugin-proposal-logical-assignment-operators": "^7.0.0-beta.55",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0-beta.55",
"@babel/plugin-proposal-numeric-separator": "^7.0.0-beta.55",
"@babel/plugin-proposal-object-rest-spread": "7.2.0",
"@babel/plugin-proposal-optional-chaining": "^7.0.0-beta.55",
"@babel/plugin-proposal-pipeline-operator": "^7.0.0-beta.55",
"@babel/plugin-proposal-throw-expressions": "^7.0.0-beta.55",
"@babel/plugin-syntax-dynamic-import": "^7.0.0-beta.55",
"@babel/plugin-syntax-import-meta": "^7.0.0-beta.55",
"@babel/polyfill": "^7.7.0",
"@babel/preset-env": "^7.7.1",
"@babel/preset-stage-0": "^7.0.0-beta.51",
"@babel/register": "^7.7.0",
"apollo-server-express": "^1.3.6",
"apollo-upload-server": "^6.0.0-alpha.1",
"babel-plugin-transform-function-bind": "^6.22.0",
"body-parser": "^1.18.3",
"callback-to-async-iterator": "^1.1.1",
"cors": "^2.8.4",
"express": "^4.16.3",
"fs": "0.0.1-security",
"glob": "^7.1.6",
"graphql": "^0.13.2",
"graphql-subscriptions": "^0.5.8",
"graphql-tools": "^3.0.4",
"http": "0.0.0",
"path": "^0.12.7",
"require-dir": "^1.0.0",
"bunyan": "^1.8.12",
"graphql-playground-middleware-express": "^1.7.2",
"subscriptions-transport-ws": "^0.9.12"
},
"devDependencies": {
"graphql-client": "^2.0.1",
"jasmine-node": "^1.15.0",
"nodemon": "^1.18.3",
"shelljs": "^0.8.2",
"tape": "^4.9.1"
}
"name": "@lymeodev/apollon",
"version": "1.1.6",
"description": "Project apollon's goal is to simplify GraphQl API development and to offer a modulable structure to start building an API in minutes.",
"main": "src/index.js",
"scripts": {
"start": "node src/index.js prod",
"dev": "node src/index.js dev",
"nodemon": "nodemon -e js,json,gql src/index.js dev",
"schema": "node src/schemaGenerator.js",
"update": "node src/updates",
"test": "node src/index.js test"
},
"keywords": [],
"author": "lymeo",
"license": "ISC",
"dependencies": {
"@babel/cli": "^7.7.0",
"@babel/core": "^7.7.2",
"@babel/plugin-proposal-class-properties": "^7.7.0",
"@babel/plugin-proposal-decorators": "^7.7.0",
"@babel/plugin-proposal-do-expressions": "^7.0.0-beta.55",
"@babel/plugin-proposal-export-default-from": "^7.0.0-beta.55",
"@babel/plugin-proposal-export-namespace-from": "^7.0.0-beta.55",
"@babel/plugin-proposal-function-bind": "^7.0.0-beta.55",
"@babel/plugin-proposal-function-sent": "^7.7.0",
"@babel/plugin-proposal-json-strings": "^7.0.0-beta.55",
"@babel/plugin-proposal-logical-assignment-operators": "^7.0.0-beta.55",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0-beta.55",
"@babel/plugin-proposal-numeric-separator": "^7.0.0-beta.55",
"@babel/plugin-proposal-object-rest-spread": "7.2.0",
"@babel/plugin-proposal-optional-chaining": "^7.0.0-beta.55",
"@babel/plugin-proposal-pipeline-operator": "^7.0.0-beta.55",
"@babel/plugin-proposal-throw-expressions": "^7.0.0-beta.55",
"@babel/plugin-syntax-dynamic-import": "^7.0.0-beta.55",
"@babel/plugin-syntax-import-meta": "^7.0.0-beta.55",
"@babel/polyfill": "^7.7.0",
"@babel/preset-env": "^7.7.4",
"@babel/preset-stage-0": "^7.0.0-beta.51",
"@babel/register": "^7.7.0",
"@std/esm": "^0.26.0",
"acorn": "^7.1.0",
"apollo-server-express": "^1.3.6",
"apollo-upload-server": "^6.0.0-alpha.1",
"astring": "^1.4.3",
"babel-plugin-transform-function-bind": "^6.22.0",
"bunyan": "^1.8.12",
"callback-to-async-iterator": "^1.1.1",
"cors": "^2.8.4",
"escodegen": "^1.12.0",
"esm": "^3.2.25",
"express": "^4.16.3",
"fs": "0.0.1-security",
"fs-extra": "^8.1.0",
"glob": "^7.1.6",
"graphql": "^0.13.2",
"graphql-playground-middleware-express": "^1.7.2",
"graphql-subscriptions": "^0.5.8",
"graphql-tools": "^3.0.4",
"http": "0.0.0",
"install": "^0.13.0",
"npm": "^6.13.1",
"path": "^0.12.7",
"require-dir": "^1.0.0",
"subscriptions-transport-ws": "^0.9.12"
},
"devDependencies": {
"graphql-client": "^2.0.1",
"jasmine-node": "^1.15.0",
"node-minify": "^3.6.0",
"nodemon": "^1.18.3",
"shelljs": "^0.8.2",
"tape": "^4.9.1",
"uglify-js": "^3.7.0",
"uglify-js-es6": "^2.8.9"
},
"esm": {
"cjs": true,
"await": true
}
}
128 changes: 128 additions & 0 deletions src/build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import logger from "./logger";
import mergeDeep from "./helpers/deepMerge";

import fse from "fs-extra";

import glob from "glob";
import path from "path";
import express from "express";
import { execute, subscribe } from "graphql";
import cors from "cors";
import bodyParser from "body-parser";
import { apolloUploadExpress } from "apollo-upload-server";
import expressPlayground from "graphql-playground-middleware-express";
import { SubscriptionServer } from "subscriptions-transport-ws";

// CJS compatibility
import apollo_server_express from "apollo-server-express";
const { graphqlExpress } = apollo_server_express;

import http from "http";
const { createServer } = http;

import subscriptions from "graphql-subscriptions";
const { PubSub } = subscriptions;

//Initial config
import config from "./config.mjs";

const pubsub = new PubSub();

// Scope exporting functions
function setConfig(p_newConfig) {
return mergeDeep(config, p_newConfig || {});
}

let initialisation = async function initialisation(context, start) {
return start();
};

function setInitilisation(p_newIniliser) {
initialisation = p_newIniliser;
}

// Bootstrapper function
const start = async p_config => {
logger.info("Welcome to Apollon building process");
logger.info("Apollon will start building production ready");

// Changing CWD to match potential root configuration
logger.debug(`- Defining project root => ${config.root}`);
process.chdir(config.root.toString());

// Creating dist foleder
logger.debug(`Creating dist folder`);
await fse.remove("../.tmp.apollon.dist");
await fse.remove("./dist");
await fse.move("./node_modules", "../.tmp.apollon.node_modules");
await fse.copy("./", "../.tmp.apollon.dist");
await fse.move("../.tmp.apollon.dist", "./dist");
await fse.move("../.tmp.apollon.node_modules", "./node_modules");

//Take into account post-start settings
mergeDeep(config, p_config);

// Set up the final config
logger.info("- Preparing config");
const configFiles = glob.sync(config.sources.config);
const configs = configFiles.map(filepath => {
logger.debug({ filepath }, `-- Importing config file`);
return import(path.join(process.cwd(), filepath));
});
mergeDeep(config, ...(await Promise.all(configs)).map(e => e.default));

//Setting up child logger
logger.debug("- Setting up logging");
let childLogger = logger.child({ scope: "userland" });
childLogger.domain = function(obj, potMessage) {
const domain = { scope: "domain" };
if (potMessage) {
childLogger.info(Object.assign(obj, domain), potMessage);
} else {
childLogger.info(domain, obj);
}
};

// Setting up schema
logger.info("Building schema");
let dataFromSchema;
const schema = await (await import("./schema_develop")).default(
config,
data => (dataFromSchema = data)
);

logger.info("- Outputting schemas");
await fse.outputFile("dist/schema.gql", dataFromSchema.typeDefs);
await fse.outputFile(
"dist/schema.mjs",
`export default \`${dataFromSchema.typeDefs}\``
);

logger.info("Preparing implementation dependencies");
config.$apollon_project_implementations = {
types: dataFromSchema.typeFiles,
directives: dataFromSchema.directivesFiles,
middlewares: glob.sync(config.sources.middlewares),
resolvers: dataFromSchema.resolverFiles,
connectors: glob.sync(config.sources.connectors)
};

logger.info("Writting config");
const confToWrite = Object.assign({}, config);
delete confToWrite.root;
delete confToWrite.sources;
await fse.outputFile("dist/config.json", JSON.stringify(confToWrite));

logger.info("Cleaning config files");
await Promise.all(
configFiles.map(filepath => fse.unlink(path.join("./dist/", filepath)))
);
logger.info("Cleaning schema files");
await Promise.all(
glob
.sync(config.sources.schema)
.map(filepath => fse.unlink(path.join("./dist/", filepath)))
);
};

export { start, setConfig, setInitilisation };
38 changes: 0 additions & 38 deletions src/config.js

This file was deleted.

31 changes: 31 additions & 0 deletions src/config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const root = __dirname.replace("node_modules/@lymeodev/apollon/src", "");

export default {
port: 3000,
plugins: [],
root,

//Glob patterns used as sources for the different files
sources: {
resolvers:
"{resolvers/**/*.js,*.resolver.js,resolver.js,*.resolvers.js,resolvers.js,resolvers/**/*.mjs,*.resolver.mjs,resolver.mjs,*.resolvers.mjs,resolvers.mjs,!(node_modules/**/**)}",
connectors:
"{connectors/**/*.js,*.connector.js,,*.connectors.js,connectors/**/*.mjs,*.connector.mjs,,*.connectors.mjs,!(node_modules/**/**)}",
directives:
"{directives/**/*.js,*.directive.js*.directives.js,directives/**/*.mjs,*.directive.mjs*.directives.mjs,!(node_modules/**/**)}",
types:
"{types/**/*.js,*.type.js,*.types.js,types/**/*.mjs,*.type.mjs,*.types.mjs,!(node_modules/**/**)}",
schema: "{*.gql, !(node_modules)/*.gql}",
config:
"{config.js,config.mjs,config.json,*.config.js,*.config.mjs,*.config.json,config/**/*.js,config/**/*.mjs,config/**/*.json,!(node_modules/**/**)}",
middlewares: "{middlewares/**/*.js,!(node_modules/**/**)}"
},

//Default CORS settings
cors: {
origin: "*",
methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
preflightContinue: false,
optionsSuccessStatus: 204
}
};
Loading