Merge branch 'next' into next-passport

This commit is contained in:
Wyatt Johnson
2018-08-01 13:13:54 -06:00
5 changed files with 100 additions and 61 deletions
+18 -13
View File
@@ -1,12 +1,8 @@
const loaderUtils = require("loader-utils");
const fs = require("fs");
const path = require("path");
const camelCase = require("lodash/camelCase");
const upperFirst = require("lodash/upperFirst");
const memoize = require("lodash/memoize");
const pascalCase = x => upperFirst(camelCase(x));
/**
* Default values for every param that can be passed in the loader query.
*/
@@ -37,7 +33,7 @@ const DEFAULT_QUERY_VALUES = {
};
function getFiles(target, pathToLocale, context) {
const { pathToLocales, commonFiles } = context;
const { commonFiles } = context;
const common = [];
const suffixes = [];
@@ -63,15 +59,16 @@ function generateTarget(target, context) {
defaultLocale,
fallbackLocale,
pathToLocales,
resourcePath,
locales,
commonFiles,
bundled,
} = context;
const getLocalePath = locale => path.join(pathToLocales, locale);
const getLocaleFiles = memoize(locale =>
getFiles(target, getLocalePath(locale), context)
);
const loadables = locales.filter(local => !bundled.includes(local));
const loadables = locales.filter(locale => !bundled.includes(locale));
return `
var ret = {
@@ -92,13 +89,15 @@ function generateTarget(target, context) {
${getLocaleFiles(locale)
.common.map(
file => `
contents.push(require('${getLocalePath(locale)}/${file}'));
contents.push(require(${JSON.stringify(
path.join(getLocalePath(locale), file).replace(/\\/g, "/")
)}));
`
)
.join("\n")}
contents = contents.concat(suffixes.map(function(suffix) { return require(\`${getLocalePath(
locale
)}/${target}\${suffix}\`); }));
contents = contents.concat(suffixes.map(function(suffix) { return require(\`${path
.join(getLocalePath(locale), target)
.replace(/\\/g, "/")}\${suffix}\`); }));
ret.bundled[${JSON.stringify(locale)}] = contents.join("\\n");
}
`
@@ -120,7 +119,9 @@ function generateTarget(target, context) {
/* webpackChunkName: ${JSON.stringify(
`${target}-locale-${locale}`
)}, webpackMode: "lazy" */
'${getLocalePath(locale)}/${file}'
${JSON.stringify(
path.join(getLocalePath(locale), file).replace(/\\/g, "/")
)}
)
);
`
@@ -131,7 +132,9 @@ function generateTarget(target, context) {
/* webpackChunkName: ${JSON.stringify(
`${target}-locale-${locale}`
)}, webpackMode: "lazy-once" */
\`${getLocalePath(locale)}/${target}\${suffix}\`
\`${path
.join(getLocalePath(locale), target)
.replace(/\\/g, "/")}\${suffix}\`
)
}));
return Promise.all(promises).then(function(modules) {
@@ -188,7 +191,9 @@ module.exports = function(source) {
}
const context = {
// Use relative paths because it fails on Windows.
pathToLocales,
resourcePath: this.resourcePath,
defaultLocale,
fallbackLocale,
commonFiles,
+12 -1
View File
@@ -6231,6 +6231,16 @@
"gud": "^1.0.0"
}
},
"cross-env": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/cross-env/-/cross-env-5.2.0.tgz",
"integrity": "sha512-jtdNFfFW1hB7sMhr/H6rW1Z45LFqyI431m3qU6bFXcQ3Eh7LtBuG3h74o7ohHZ3crrRkkqHlo4jYHFPcjroANg==",
"dev": true,
"requires": {
"cross-spawn": "^6.0.5",
"is-windows": "^1.0.0"
}
},
"cross-fetch": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-2.0.0.tgz",
@@ -20425,7 +20435,8 @@
"simulant": {
"version": "0.2.2",
"resolved": "https://registry.npmjs.org/simulant/-/simulant-0.2.2.tgz",
"integrity": "sha1-8bzlJxK2p6DaON392n6DsgsdoB4="
"integrity": "sha1-8bzlJxK2p6DaON392n6DsgsdoB4=",
"dev": true
},
"sinon": {
"version": "6.1.3",
+8 -8
View File
@@ -3,25 +3,24 @@
"version": "5.0.0",
"description": "A better commenting experience from Mozilla, The Washington Post, and The New York Times.",
"scripts": {
"build": "npm-run-all compile --parallel build:*",
"build:client": "node ./scripts/build.js",
"build:server": "tsc -p ./src/tsconfig.json",
"build": "npm-run-all compile --parallel build:*",
"compile:css-types": "tcm src/core/client/",
"compile:relay-stream": "relay-compiler --src ./src/core/client/stream --schema $(ts-node ./scripts/schemaPath.ts tenant) --language typescript --artifactDirectory ./src/core/client/stream/__generated__ --no-watchman",
"compile:schema": "node ./scripts/generateSchemaTypes.js",
"compile": "npm-run-all --parallel compile:*",
"docz:watch": "docz dev",
"compile:css-types": "tcm src/core/client/",
"compile:relay-stream": "ts-node ./scripts/compileRelay --src ./src/core/client/stream --schema tenant",
"compile:schema": "node ./scripts/generateSchemaTypes.js",
"docz": "docz",
"lint-fix": "npm run lint:server -- --fix && npm run lint:client -- --fix && npm run lint:scripts -- --fix",
"lint:client": "tslint --project ./src/core/client/tsconfig.json",
"lint:scripts": "tslint --project ./tsconfig.json",
"lint:server": "tslint --project ./src/tsconfig.json",
"lint": "npm-run-all --parallel lint:*",
"start:development": "NODE_ENV=development ts-node --project ./src/tsconfig.json -r tsconfig-paths/register ./src/index.ts",
"start:development": "cross-env NODE_ENV=development ts-node --project ./src/tsconfig.json -r tsconfig-paths/register ./src/index.ts",
"start:webpackDevServer": "node ./scripts/start.js",
"start": "node dist/index.js",
"test": "node scripts/test.js --env=jsdom",
"watch": "NODE_ENV=development ts-node ./scripts/watcher/bin/watcher.ts --config ./config/watcher.ts"
"watch": "cross-env NODE_ENV=development ts-node ./scripts/watcher/bin/watcher.ts --config ./config/watcher.ts"
},
"author": "",
"license": "Apache-2.0",
@@ -110,6 +109,7 @@
"classnames": "^2.2.5",
"commander": "^2.16.0",
"copy-webpack-plugin": "^4.5.1",
"cross-env": "^5.2.0",
"cross-spawn": "^6.0.5",
"css-loader": "^0.28.11",
"docz": "^0.5.8",
@@ -184,4 +184,4 @@
"webpack-hot-client": "^4.1.1",
"webpack-manifest-plugin": "^2.0.3"
}
}
}
+62
View File
@@ -0,0 +1,62 @@
#!/usr/bin/env ts-node
import program from "commander";
import spawn from "cross-spawn";
import fs from "fs";
import path from "path";
const config = JSON.parse(
fs.readFileSync(path.resolve(__dirname, "../.graphqlconfig"), "utf8")
);
program
.version("0.1.0")
.usage("--src ./src/core/client/stream --schema tenant")
.option("--src <folder>", "Find gql recursively in this folder")
.option("--schema <schema>", "Identifier of schema")
.description("Compile relay gql data")
.parse(process.argv);
if (!program.schema) {
// tslint:disable-next-line:no-console
console.error("Schema identifier not provided");
process.exit(1);
}
if (!program.src) {
// tslint:disable-next-line:no-console
console.error("Src not provided");
process.exit(1);
}
if (!config.projects) {
// tslint:disable-next-line:no-console
console.error("Missing projects key in .graphqconfig");
process.exit(1);
}
if (!config.projects[program.schema]) {
// tslint:disable-next-line:no-console
console.error(`Project ${program.schema} not found in .graphqconfig`);
process.exit(1);
}
if (!config.projects[program.schema].schemaPath) {
// tslint:disable-next-line:no-console
console.error(
`SchemaPath for project ${program.schema} not found in .graphqconfig`
);
process.exit(1);
}
const args = [
"--language",
"typescript",
"--no-watchman",
"--src",
program.src,
"--artifactDirectory",
`${program.src}/__generated__`,
"--schema",
config.projects[program.schema].schemaPath,
];
spawn.sync("relay-compiler", args, { stdio: "inherit" });
-39
View File
@@ -1,39 +0,0 @@
#!/usr/bin/env ts-node
import program from "commander";
import fs from "fs";
import path from "path";
const config = JSON.parse(
fs.readFileSync(path.resolve(__dirname, "../.graphqlconfig"), "utf8")
);
program
.version("0.1.0")
.usage("<project>")
.arguments("<project>")
.description(
"Returns the schema graph in `.graphqlconfig` based on <project>"
)
.action(project => {
if (!config.projects) {
// tslint:disable-next-line:no-console
console.error("Missing projects key in .graphqconfig");
process.exit(1);
}
if (!config.projects[project]) {
// tslint:disable-next-line:no-console
console.error(`Project ${project} not found in .graphqconfig`);
process.exit(1);
}
if (!config.projects[project].schemaPath) {
// tslint:disable-next-line:no-console
console.error(
`SchemaPath for project ${project} not found in .graphqconfig`
);
process.exit(1);
}
// tslint:disable-next-line:no-console
console.log(config.projects[project].schemaPath);
})
.parse(process.argv);