diff --git a/.babelrc.js b/.babelrc.js
new file mode 100644
index 0000000..1d52d1e
--- /dev/null
+++ b/.babelrc.js
@@ -0,0 +1,59 @@
+"use strict";
+
+module.exports = function(api) {
+ api.cache.using(() => process.env.NODE_ENV);
+
+ const presets = [
+ [
+ "@babel/env",
+ {
+ modules: api.env("test") ? undefined : false,
+ useBuiltIns: "entry",
+ corejs: {
+ version: 3,
+ },
+ debug: false,
+ },
+ ],
+ "@babel/typescript",
+ "@babel/react",
+ ];
+
+ const plugins = [
+ "@babel/plugin-transform-runtime",
+ [
+ "@babel/plugin-proposal-decorators",
+ {
+ legacy: true,
+ },
+ ],
+ [
+ "@babel/plugin-proposal-class-properties",
+ {
+ loose: true,
+ },
+ ],
+ [
+ "import",
+ {
+ libraryName: "antd",
+ libraryDirectory: api.env("test") ? undefined : "es",
+ style: true,
+ },
+ ],
+ "@babel/plugin-proposal-optional-catch-binding",
+ "@babel/plugin-proposal-optional-chaining",
+ "@babel/plugin-syntax-dynamic-import",
+ "lodash",
+ ];
+
+ return {
+ presets: presets,
+ plugins: plugins,
+ env: {
+ test: {
+ presets: presets,
+ },
+ },
+ };
+};
diff --git a/.browserslistrc b/.browserslistrc
new file mode 100644
index 0000000..05bdd2f
--- /dev/null
+++ b/.browserslistrc
@@ -0,0 +1,7 @@
+> 1%
+last 2 versions
+safari >= 6
+not ie > 0
+not ie_mob > 0
+not edge <= 15
+not op_mini all
\ No newline at end of file
diff --git a/.bundlesizerc b/.bundlesizerc
new file mode 100644
index 0000000..a01cd89
--- /dev/null
+++ b/.bundlesizerc
@@ -0,0 +1,20 @@
+{
+ "files": [
+ {
+ "path": "./build/**/*.{js,ttf}",
+ "maxSize": "300 kB"
+ },
+ {
+ "path": "./build/**/*.{png,svg,jpg,jpeg}",
+ "maxSize": "250 kB"
+ },
+ {
+ "path": "./build/**/*.{css,scss}",
+ "maxSize": "50 kB"
+ },
+ {
+ "path": "./build/**/*.html",
+ "maxSize": "50 kB"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..b5ef85f
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,6 @@
+[*]
+charset = utf-8
+end_of_line = lf
+insert_final_newline = false
+indent_style = space
+indent_size = 2
\ No newline at end of file
diff --git a/.env b/.env
new file mode 100644
index 0000000..42cc166
--- /dev/null
+++ b/.env
@@ -0,0 +1,3 @@
+BUNDLE_NAME=IdeaSource
+BROWSERSLIST_CONFIG=.browserslistrc
+PORT=5000
\ No newline at end of file
diff --git a/.env.development b/.env.development
new file mode 100644
index 0000000..934767e
--- /dev/null
+++ b/.env.development
@@ -0,0 +1,2 @@
+GENERATE_SOURCEMAP=true
+REACT_APP_SERVER_BASE_URI=https://ideasource-staging.appspot.com/graphql
\ No newline at end of file
diff --git a/.env.production b/.env.production
new file mode 100644
index 0000000..4f79a0f
--- /dev/null
+++ b/.env.production
@@ -0,0 +1 @@
+GENERATE_SOURCEMAP=false
\ No newline at end of file
diff --git a/.eslintignore b/.eslintignore
new file mode 100644
index 0000000..1dd6ca8
--- /dev/null
+++ b/.eslintignore
@@ -0,0 +1,4 @@
+build/*
+.storybook_build/*
+node_modules/*
+typings/*
\ No newline at end of file
diff --git a/.eslintrc.js b/.eslintrc.js
new file mode 100644
index 0000000..35e6525
--- /dev/null
+++ b/.eslintrc.js
@@ -0,0 +1,33 @@
+module.exports = {
+ extends: ["plugin:@typescript-eslint/recommended", "prettier/@typescript-eslint", "plugin:prettier/recommended"], // "plugin:jsx-a11y/recommended", "plugin:jest/recommended"
+ parser: "@typescript-eslint/parser",
+ parserOptions: {
+ ecmaVersion: 2018,
+ sourceType: "module",
+ ecmaFeatures: {
+ jsx: true,
+ },
+ },
+ rules: {
+ "prettier/prettier": "warn",
+
+ "@typescript-eslint/ban-types": "off",
+ "@typescript-eslint/camelcase": "off",
+ "@typescript-eslint/explicit-function-return-type": "off",
+ "@typescript-eslint/explicit-member-accessibility": "off",
+ "@typescript-eslint/no-empty-interface": "off",
+ "@typescript-eslint/no-explicit-any": "off",
+ "@typescript-eslint/no-non-null-assertion": "off",
+ "@typescript-eslint/no-object-literal-type-assertion": "off",
+ "@typescript-eslint/no-parameter-properties": "off",
+ "@typescript-eslint/no-unused-vars": "off",
+ "@typescript-eslint/no-use-before-define": "off",
+ "@typescript-eslint/no-var-requires": "off",
+ "@typescript-eslint/prefer-interface": "off",
+ },
+ settings: {
+ react: {
+ version: "detect",
+ },
+ },
+};
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0d6f09d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,43 @@
+# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
+
+# dependencies
+/node_modules
+
+# testing
+/.temp/
+/coverage
+
+# production
+/.storybook_build/
+/build/
+
+# misc
+.DS_Store
+.env.local
+.env.development.local
+.env.test.local
+.env.production.local
+.env.release.local
+
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*
+
+# webstorm
+/.idea/
+/.idea/httpRequests
+/.idea/inspectionProfiles/profiles_settings.xml
+/.idea/usage.statistics.xml
+/.idea/workspace.xml
+
+# others
+.cache
+.Spotlight-V100
+.Trashes
+Thumbs.db
+Desktop.ini
+package-lock.json
+/src/**/*.d.ts
+
+/.server/cloud_sql_proxy
+/.server/*-client-key.json
\ No newline at end of file
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..bf4d038
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "src/services"]
+ path = src/services
+ url = https://github.com/orangeloops/phoenix-shared.git
diff --git a/.graphql/ideasource.schema.graphql b/.graphql/ideasource.schema.graphql
new file mode 100644
index 0000000..ab37b43
--- /dev/null
+++ b/.graphql/ideasource.schema.graphql
@@ -0,0 +1,228 @@
+# This file was generated based on ".graphqlconfig". Do not edit manually.
+
+schema {
+ query: Query
+ mutation: Mutation
+ subscription: Subscription
+}
+
+type Challenge {
+ closeDate: DateTime
+ createdBy: User!
+ createdDate: DateTime!
+ deletedBy: User
+ deletedDate: DateTime
+ description: String!
+ endDate: DateTime
+ id: ID!
+ ideas(createdById: String, createdByMe: Boolean = false, first: Int = 5, orderBy: ReactionOrder): IdeaConnection!
+ imageUrl: String
+ modifiedBy: User!
+ modifiedDate: DateTime!
+ myReaction: Reaction
+ privacyData: String
+ privacyMode: ChallengePrivacyMode!
+ reactions(createdById: String, createdByMe: Boolean = false, first: Int = 5, orderBy: ReactionOrder): ReactionConnection!
+ reactionsSummary(value: String): [ReactionsSummaryItem!]!
+ title: String!
+ topIdea(reactionValue: String): Idea
+}
+
+type ChallengeConnection {
+ edges: [ChallengeEdge!]!
+ pageInfo: ConnectionPageInfo!
+ totalCount: Int!
+}
+
+type ChallengeEdge {
+ cursor: String!
+ node: Challenge!
+}
+
+type CheckEmail {
+ isAvailable: Boolean
+ isBlacklisted: Boolean
+ isCorporate: Boolean
+}
+
+type ConnectionPageInfo {
+ endCursor: String
+ hasNextPage: Boolean!
+}
+
+type Idea {
+ challenge: Challenge
+ createdBy: User!
+ createdDate: DateTime!
+ deletedBy: User
+ deletedDate: DateTime
+ description: String
+ id: ID!
+ imageUrl: String
+ modifiedBy: User!
+ modifiedDate: DateTime!
+ myReaction: Reaction
+ reactions(createdById: String, createdByMe: Boolean = false, first: Int = 5, orderBy: ReactionOrder): ReactionConnection!
+ reactionsSummary(value: String): [ReactionsSummaryItem!]!
+ title: String!
+}
+
+type IdeaConnection {
+ edges: [IdeaEdge!]!
+ pageInfo: ConnectionPageInfo!
+ totalCount: Int!
+}
+
+type IdeaEdge {
+ cursor: String!
+ node: Idea!
+}
+
+type Mutation {
+ _: Boolean
+ checkEmail(email: String!): CheckEmail
+ confirmEmail(token: String!): Void
+ createChallenge(closeDate: DateTime, description: String, endDate: DateTime, privacyMode: ChallengePrivacyMode, title: String!, upload: Upload): Challenge
+ createIdea(challengeId: String!, description: String, title: String!, upload: Upload): Idea
+ createReaction(objectId: ID!, objectType: ReactionObjectType!, value: String!): Reaction
+ deleteChallenge(id: ID!): Boolean!
+ deleteIdea(id: ID!): Boolean!
+ deleteReaction(id: ID!, objectType: ReactionObjectType!): Boolean!
+ deleteUser(id: ID!): Boolean!
+ refreshTokens(token: String!): Tokens
+ requestResetPassword(email: String!): Void
+ resendEmailConfirmation(email: String!): Void
+ resetPassword(password: String!, token: String!): Void
+ signIn(email: String!, generateRefreshToken: Boolean = false, password: String!): Tokens
+ signUp(email: String!, name: String!, password: String!, upload: Upload): Void
+ updateChallenge(closeDate: DateTime, description: String, endDate: DateTime, id: ID!, privacyMode: ChallengePrivacyMode, title: String!, upload: Upload): Challenge
+ updateIdea(description: String, id: ID!, title: String!, upload: Upload): Idea
+ updateUser(id: ID!, name: String, upload: Upload): User
+}
+
+type Query {
+ _: Boolean
+ challenge(id: ID!): Challenge
+ challenges(after: String, createdById: String, createdByMe: Boolean = false, excludeClosed: Boolean = true, excludeEnded: Boolean = true, first: Int, orderBy: ChallengeOrder, withReactionByUserId: String): ChallengeConnection!
+ idea(id: ID!): Idea
+ ideas(after: String, challengeId: String, createdById: String, createdByMe: Boolean = false, first: Int, orderBy: IdeaOrder, withReactionByUserId: String): IdeaConnection!
+ me: User
+ reaction(id: ID!, objectType: ReactionObjectType!): Reaction
+ reactions(after: String, createdById: String, createdByMe: Boolean = false, first: Int, objectId: String, objectType: ReactionObjectType!, orderBy: ReactionOrder, value: String): ReactionConnection!
+ reactionsSummary(objectId: String!, objectType: ReactionObjectType!, value: String): [ReactionsSummaryItem!]!
+ reset: String
+ user(id: ID!): User
+ version: String
+}
+
+type Reaction {
+ createdBy: User!
+ createdDate: DateTime!
+ deletedBy: User
+ deletedDate: DateTime
+ id: ID!
+ modifiedBy: User!
+ modifiedDate: DateTime!
+ objectId: ID!
+ value: String!
+}
+
+type ReactionConnection {
+ edges: [ReactionEdge!]!
+ pageInfo: ConnectionPageInfo!
+ totalCount: Int!
+}
+
+type ReactionEdge {
+ cursor: String!
+ node: Reaction!
+}
+
+type ReactionsSummaryItem {
+ totalCount: Int!
+ value: String!
+}
+
+type Subscription {
+ _: Boolean
+}
+
+type Tokens {
+ refreshToken: String
+ token: String!
+}
+
+type User {
+ challenges(after: String, first: Int, orderBy: ChallengeOrder): ChallengeConnection!
+ createdDate: DateTime!
+ deletedDate: DateTime
+ email: String!
+ id: ID!
+ ideas(after: String, first: Int, orderBy: IdeaOrder): IdeaConnection!
+ imageUrl: String
+ modifiedDate: DateTime!
+ name: String!
+ status: UserStatus!
+}
+
+type Void {
+ _: Boolean
+}
+
+enum ChallengeOrderField {
+ CREATED_DATE
+ TITLE
+ UPDATED_DATE
+}
+
+enum ChallengePrivacyMode {
+ BYDOMAIN
+ PUBLIC
+}
+
+enum ConnectionOrderDirection {
+ ASC
+ DESC
+}
+
+enum IdeaOrderField {
+ CREATED_DATE
+ TITLE
+ UPDATED_DATE
+}
+
+enum ReactionObjectType {
+ CHALLENGE
+ IDEA
+}
+
+enum ReactionOrderField {
+ CREATED_DATE
+ UPDATED_DATE
+}
+
+enum UserStatus {
+ ACTIVE
+ BLOCKED
+ PENDING
+}
+
+input ChallengeOrder {
+ direction: ConnectionOrderDirection!
+ field: ChallengeOrderField!
+}
+
+input IdeaOrder {
+ direction: ConnectionOrderDirection!
+ field: IdeaOrderField!
+}
+
+input ReactionOrder {
+ direction: ConnectionOrderDirection!
+ field: ReactionOrderField!
+}
+
+"A date-time string at UTC, such as 2007-12-03T10:15:30Z, compliant with the `date-time` format outlined in section 5.6 of the RFC 3339 profile of the ISO 8601 standard for representation of dates and times using the Gregorian calendar."
+scalar DateTime
+
+scalar Upload
diff --git a/.graphqlconfig b/.graphqlconfig
new file mode 100644
index 0000000..e5dff10
--- /dev/null
+++ b/.graphqlconfig
@@ -0,0 +1,15 @@
+{
+ "name": "IdeaSource v1 Schema",
+ "schemaPath": ".graphql/ideasource.schema.graphql",
+ "extensions": {
+ "endpoints": {
+ "production": {
+ "url": "https://ideasource.io/graphql",
+ "introspect": true
+ },
+ "localhost": {
+ "url": "http://localhost:5000/graphql"
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/.huskyrc.js b/.huskyrc.js
new file mode 100644
index 0000000..9edb3cb
--- /dev/null
+++ b/.huskyrc.js
@@ -0,0 +1,5 @@
+module.exports = {
+ hooks: {
+ "pre-commit": "lint-staged",
+ },
+};
diff --git a/.lintstagedrc.js b/.lintstagedrc.js
new file mode 100644
index 0000000..4701074
--- /dev/null
+++ b/.lintstagedrc.js
@@ -0,0 +1,4 @@
+module.exports = {
+ "src/**/*.{js,jsx,ts,tsx}": ["prettier --write", "eslint --fix", "git add"],
+ "**/*.{css,scss}": ["prettier --write", "git add"], // "stylelint --fix"
+};
\ No newline at end of file
diff --git a/.prettierignore b/.prettierignore
new file mode 100644
index 0000000..1ab1b2a
--- /dev/null
+++ b/.prettierignore
@@ -0,0 +1,6 @@
+build
+.storybook_build
+node_modules/
+src/**/__snapshots__/
+package.json
+package-lock.json
\ No newline at end of file
diff --git a/.prettierrc.js b/.prettierrc.js
new file mode 100644
index 0000000..835b70e
--- /dev/null
+++ b/.prettierrc.js
@@ -0,0 +1,6 @@
+module.exports = {
+ printWidth: 240,
+ bracketSpacing: false,
+ jsxBracketSameLine: true,
+ trailingComma: "es5",
+};
diff --git a/.stylelintignore b/.stylelintignore
new file mode 100644
index 0000000..e89a005
--- /dev/null
+++ b/.stylelintignore
@@ -0,0 +1,2 @@
+build/*
+node_modules/*
diff --git a/.stylelintrc.js b/.stylelintrc.js
new file mode 100644
index 0000000..63de420
--- /dev/null
+++ b/.stylelintrc.js
@@ -0,0 +1,14 @@
+module.exports = {
+ extends: ["stylelint-config-recommended-scss"], // "stylelint-a11y/recommended"
+ plugins: ["stylelint-prettier"], // "stylelint-a11y"
+ rules: {
+ "prettier/prettier": null,
+
+ "declaration-block-no-duplicate-properties": null,
+ "font-family-no-missing-generic-family-keyword": null,
+ "indentation": null,
+ "max-empty-lines": 1,
+ "no-descending-specificity": null,
+ "no-duplicate-selectors": null,
+ },
+};
\ No newline at end of file
diff --git a/README.md b/README.md
index f19d0a1..c00c7b7 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,46 @@
-# public-phoenix-web
-OrangeLoops IdeaSource Project
+# IdeaSource Web Project
+
+## What's IdeaSource?
+
+[IdeaSource](https://ideasource.io/) is an open-source platform to gather, manage and organize ideas for creative problem solving. We used it internally as a sandbox to research React Native development front to back.
+
+## Why IdeaSource?
+
+Coming up with good ideas can be hard, especially after a while when echo chambers tend to appear in teams, groupthink takes over and creative solutions are left out of the conversation. We wished to introduce an easy way to share and manage ideas generated by a larger pool of people than those directly tasked with coming up with a solution, providing mechanisms for everyone to vote to sort the proposed ideas.
+
+## How does it work?
+
+Ideas are gathered around challenges, which can be problems, aspects or topics a group or organization may need to fix or improve. In order to create a challenge you must enter a description, upload an image and set a deadline. Challenges can be either private or public. Private challenges are only available to users registered using the same corporate email domain, while open challenges are open for every user in IdeaSource. Once a challenge is submitted, everyone can start contributing ideas, and votes for ideas already shared.
+
+## Getting Started
+
+Run the following commands in your terminal
+
+```bash
+git clone https://github.com/orangeloops/public-phoenix-web.git
+cd public-phoenix-web
+npm install
+npm run start
+```
+
+Then open [http://localhost:5000/](http://localhost:5000/) on your web browser.
+
+### Testing
+
+Run `npm test` for test.
+
+## Deploying
+
+For deployment, run `npm run build` and upload `build/` to your server.
+
+## License
+>You can check out the full license [here](https://github.com/orangeloops/public-phoenix-web/blob/develop/LICENSE)
+
+This project is licensed under the terms of the MIT license.
+
+---
+
+[orangeloops.com](https://www.orangeloops.com/) ·
+[twitter](https://twitter.com/orangeloopsinc/) ·
+[blog](https://orangeloops.com/blog/) ·
+[IdeaSource](https://ideasource.io/)
diff --git a/config/env.js b/config/env.js
new file mode 100644
index 0000000..42973a9
--- /dev/null
+++ b/config/env.js
@@ -0,0 +1,105 @@
+"use strict";
+
+const fs = require("fs");
+const path = require("path");
+const paths = require("./paths");
+
+// Make sure that including paths.js after env.js will read .env variables.
+delete require.cache[require.resolve("./paths")];
+
+const NODE_ENV = process.env.NODE_ENV;
+if (!NODE_ENV) {
+ throw new Error("The NODE_ENV environment variable is required but was not specified.");
+}
+
+// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
+var dotenvFiles = [
+ `${paths.dotenv}.${NODE_ENV}.local`,
+ `${paths.dotenv}.${NODE_ENV}`,
+ // Don't include `.env.local` for `test` environment
+ // since normally you expect tests to produce the same
+ // results for everyone
+ NODE_ENV !== "test" && `${paths.dotenv}.local`,
+ paths.dotenv,
+].filter(Boolean);
+
+// Load environment variables from .env* files. Suppress warnings using silent
+// if this file is missing. dotenv will never modify any environment variables
+// that have already been set. Variable expansion is supported in .env files.
+// https://github.com/motdotla/dotenv
+// https://github.com/motdotla/dotenv-expand
+dotenvFiles.forEach(dotenvFile => {
+ if (fs.existsSync(dotenvFile)) {
+ require("dotenv-expand")(
+ require("dotenv").config({
+ path: dotenvFile,
+ })
+ );
+ }
+});
+
+// We support resolving modules according to `NODE_PATH`.
+// This lets you use absolute paths in imports inside large monorepos:
+// https://github.com/facebook/create-react-app/issues/253.
+// It works similar to `NODE_PATH` in Node itself:
+// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
+// Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored.
+// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims.
+// https://github.com/facebook/create-react-app/issues/1023#issuecomment-265344421
+// We also resolve them to make sure all tools using them work consistently.
+const appDirectory = fs.realpathSync(process.cwd());
+process.env.NODE_PATH = (process.env.NODE_PATH || "")
+ .split(path.delimiter)
+ .filter(folder => folder && !path.isAbsolute(folder))
+ .map(folder => path.resolve(appDirectory, folder))
+ .join(path.delimiter);
+
+// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
+// injected into the application via DefinePlugin in Webpack configuration.
+const REACT_APP = /^REACT_APP_/i;
+
+const appPackage = require(paths.appPackageJson);
+
+function getClientEnvironment(publicUrl) {
+ const raw = Object.keys(process.env)
+ .filter(key => REACT_APP.test(key))
+ .reduce(
+ (env, key) => {
+ env[key] = process.env[key];
+ return env;
+ },
+ {
+ // Useful for determining whether we’re running in production mode.
+ // Most importantly, it switches React into the correct mode.
+ NODE_ENV: process.env.NODE_ENV || "development",
+ // Useful for resolving the correct path to static assets in `public`.
+ // For example, .
+ // This should only be used as an escape hatch. Normally you would put
+ // images into the `src` and `import` them in code to get their paths.
+ PUBLIC_URL: publicUrl,
+
+ STORYBOOK_ENV: process.env.STORYBOOK_ENV,
+
+ BUNDLE_TYPE: process.env.BUNDLE_TYPE || "app",
+ BUNDLE_NAME: process.env.BUNDLE_NAME || appPackage.name,
+
+ PACKAGE_NAME: appPackage.name,
+ PACKAGE_VERSION: appPackage.version,
+
+ WEBPACK_CONFIG: process.env.WEBPACK_CONFIG,
+ STYLESHEETS_CONFIG: process.env.STYLESHEETS_CONFIG,
+ BROWSERSLIST_CONFIG: process.env.BROWSERSLIST_CONFIG,
+ }
+ );
+ // Stringify all values so we can feed into Webpack DefinePlugin
+ const stringified = {
+ "process.env": Object.keys(raw).reduce((env, key) => {
+ env[key] = JSON.stringify(raw[key]);
+ return env;
+ }, {}),
+ };
+
+ return {raw, stringified};
+}
+
+module.exports = getClientEnvironment;
diff --git a/config/helper.js b/config/helper.js
new file mode 100644
index 0000000..070221d
--- /dev/null
+++ b/config/helper.js
@@ -0,0 +1,16 @@
+"use strict";
+
+const ModuleDependencyWarning = require("webpack/lib/ModuleDependencyWarning");
+
+module.exports = {
+ IgnoreNotFoundExportPlugin: class IgnoreNotFoundExportPlugin {
+ apply(compiler) {
+ const messageRegExp = /export '.*'( \(reexported as '.*'\))? was not found in/;
+
+ const doneHook = stats => (stats.compilation.warnings = stats.compilation.warnings.filter(warning => !(warning instanceof ModuleDependencyWarning && messageRegExp.test(warning.message))));
+
+ if (compiler.hooks) compiler.hooks.done.tap("IgnoreNotFoundExportPlugin", doneHook);
+ else compiler.plugin("done", doneHook);
+ }
+ },
+};
diff --git a/config/modules.js b/config/modules.js
new file mode 100644
index 0000000..8a5e300
--- /dev/null
+++ b/config/modules.js
@@ -0,0 +1,77 @@
+"use strict";
+
+const fs = require("fs");
+const path = require("path");
+const paths = require("./paths");
+const chalk = require("react-dev-utils/chalk");
+
+/**
+ * Get the baseUrl of a compilerOptions object.
+ *
+ * @param {Object} options
+ */
+function getAdditionalModulePaths(options = {}) {
+ const baseUrl = options.baseUrl;
+
+ // We need to explicitly check for null and undefined (and not a falsy value) because
+ // TypeScript treats an empty string as `.`.
+ if (baseUrl == null) {
+ // If there's no baseUrl set we respect NODE_PATH
+ // Note that NODE_PATH is deprecated and will be removed
+ // in the next major release of create-react-app.
+
+ const nodePath = process.env.NODE_PATH || "";
+ return nodePath.split(path.delimiter).filter(Boolean);
+ }
+
+ const baseUrlResolved = path.resolve(paths.appPath, baseUrl);
+
+ // We don't need to do anything if `baseUrl` is set to `node_modules`. This is
+ // the default behavior.
+ if (path.relative(paths.appNodeModules, baseUrlResolved) === "") {
+ return null;
+ }
+
+ // Allow the user set the `baseUrl` to `appSrc`.
+ if (path.relative(paths.appSrc, baseUrlResolved) === "") {
+ return [paths.appSrc];
+ }
+
+ // Otherwise, throw an error.
+ throw new Error(chalk.red.bold("Your project's `baseUrl` can only be set to `src` or `node_modules`." + " Create React App does not support other values at this time."));
+}
+
+function getModules() {
+ // Check if TypeScript is setup
+ const hasTsConfig = fs.existsSync(paths.appTsConfig);
+ const hasJsConfig = fs.existsSync(paths.appJsConfig);
+
+ if (hasTsConfig && hasJsConfig) {
+ throw new Error("You have both a tsconfig.json and a jsconfig.json. If you are using TypeScript please remove your jsconfig.json file.");
+ }
+
+ let config;
+
+ // If there's a tsconfig.json we assume it's a
+ // TypeScript project and set up the config
+ // based on tsconfig.json
+ if (hasTsConfig) {
+ config = require(paths.appTsConfig);
+ // Otherwise we'll check if there is jsconfig.json
+ // for non TS projects.
+ } else if (hasJsConfig) {
+ config = require(paths.appJsConfig);
+ }
+
+ config = config || {};
+ const options = config.compilerOptions || {};
+
+ const additionalModulePaths = getAdditionalModulePaths(options);
+
+ return {
+ additionalModulePaths: additionalModulePaths,
+ hasTsConfig,
+ };
+}
+
+module.exports = getModules();
diff --git a/config/paths.js b/config/paths.js
new file mode 100644
index 0000000..274098c
--- /dev/null
+++ b/config/paths.js
@@ -0,0 +1,76 @@
+"use strict";
+
+const path = require("path");
+const fs = require("fs");
+const url = require("url");
+
+// Make sure any symlinks in the project folder are resolved:
+// https://github.com/facebook/create-react-app/issues/637
+const appDirectory = fs.realpathSync(process.cwd());
+const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
+
+const envPublicUrl = process.env.PUBLIC_URL;
+
+function ensureSlash(inputPath, needsSlash) {
+ const hasSlash = inputPath.endsWith("/");
+ if (hasSlash && !needsSlash) {
+ return inputPath.substr(0, inputPath.length - 1);
+ } else if (!hasSlash && needsSlash) {
+ return `${inputPath}/`;
+ } else {
+ return inputPath;
+ }
+}
+
+const getPublicUrl = appPackageJson => envPublicUrl || require(appPackageJson).homepage;
+
+// We use `PUBLIC_URL` environment variable or "homepage" field to infer
+// "public path" at which the app is served.
+// Webpack needs to know it to put the right
+