├── .circleci └── config.yml ├── .editorconfig ├── .eslintrc.json ├── .gitignore ├── .prettierignore ├── .prettierrc ├── .vscode └── extensions.json ├── LICENSE ├── README.md ├── jest.config.js ├── jest.preset.js ├── logo.png ├── nx.json ├── package.json ├── packages ├── gatsby-plugin-e2e │ ├── jest.config.js │ ├── tests │ │ └── gatsby-plugin.test.ts │ ├── tsconfig.e2e.json │ ├── tsconfig.json │ └── tsconfig.spec.json └── gatsby-plugin │ ├── .eslintrc.json │ ├── LICENSE │ ├── README.md │ ├── babel.ts │ ├── builders.json │ ├── collection.json │ ├── jest.config.js │ ├── package.json │ ├── plugins │ └── nx-gatsby-ext-plugin │ │ ├── gatsby-config.ts │ │ ├── gatsby-node.ts │ │ └── package.json │ ├── publish.sh │ ├── src │ ├── builders │ │ ├── build │ │ │ ├── builder.ts │ │ │ ├── schema.d.ts │ │ │ └── schema.json │ │ └── server │ │ │ ├── builder.ts │ │ │ ├── schema.d.ts │ │ │ └── schema.json │ ├── index.ts │ ├── schematics │ │ ├── application │ │ │ ├── application.ts │ │ │ ├── files │ │ │ │ ├── .babelrc.template │ │ │ │ ├── .gitignore │ │ │ │ ├── .prettierignore │ │ │ │ ├── .prettierrc │ │ │ │ ├── LICENSE │ │ │ │ ├── README.md │ │ │ │ ├── gatsby-browser.js │ │ │ │ ├── gatsby-config.js.template │ │ │ │ ├── gatsby-node.js │ │ │ │ ├── gatsby-ssr.js │ │ │ │ ├── package.json │ │ │ │ ├── src │ │ │ │ │ ├── images │ │ │ │ │ │ └── logo.png │ │ │ │ │ └── pages │ │ │ │ │ │ ├── 404.js │ │ │ │ │ │ ├── index.__style__.template │ │ │ │ │ │ ├── index.spec.tsx.template │ │ │ │ │ │ ├── index.tsx.template │ │ │ │ │ │ ├── logo.svg │ │ │ │ │ │ └── star.svg │ │ │ │ └── tsconfig.json │ │ │ ├── schema.d.ts │ │ │ └── schema.json │ │ ├── component │ │ │ ├── component.ts │ │ │ └── schema.json │ │ ├── init │ │ │ ├── init.ts │ │ │ ├── schema.d.ts │ │ │ └── schema.json │ │ └── page │ │ │ ├── page.ts │ │ │ └── schema.json │ └── utils │ │ ├── get-project-root.ts │ │ ├── styles.ts │ │ └── versions.ts │ ├── tsconfig.json │ ├── tsconfig.lib.json │ └── tsconfig.spec.json ├── tools ├── generators │ └── .gitkeep ├── scripts │ ├── publish.js │ └── publish.sh └── tsconfig.tools.json ├── tsconfig.base.json ├── workspace.json └── yarn.lock /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | orbs: 2 | node: circleci/node@2.0.2 3 | 4 | version: 2.1 5 | 6 | commands: 7 | yarn_install: 8 | description: 'Install Dependencies' 9 | steps: 10 | - run: yarn install --frozen-lockfile --non-interactive 11 | - save_cache: 12 | key: yarn-{{ checksum "yarn.lock" }} 13 | paths: 14 | - ~/.cache/yarn 15 | restore_yarn_cache: 16 | description: 'Restore Cached Dependencies' 17 | steps: 18 | - restore_cache: 19 | keys: 20 | - yarn-{{ checksum "yarn.lock" }} 21 | # fallback to using the latest cache if no exact match is found 22 | - yarn- 23 | 24 | jobs: 25 | install: 26 | docker: 27 | - image: circleci/node:12-browsers 28 | steps: 29 | - checkout 30 | - restore_yarn_cache 31 | - yarn_install 32 | - persist_to_workspace: 33 | root: ~/project 34 | paths: . 35 | lint-and-test: 36 | docker: 37 | - image: circleci/node:12-browsers 38 | steps: 39 | - checkout 40 | - attach_workspace: 41 | at: ~/project 42 | - run: 43 | name: Lint 44 | command: yarn lint 45 | - run: 46 | name: Run Unit Tests 47 | command: yarn test 48 | end-to-end-tests: 49 | docker: 50 | - image: circleci/node:12-browsers 51 | steps: 52 | - checkout 53 | - attach_workspace: 54 | at: ~/project 55 | - run: 56 | name: E2E 57 | command: yarn e2e 58 | no_output_timeout: 30m 59 | 60 | workflows: 61 | version: 2.1 62 | default_workflow: 63 | jobs: 64 | - install 65 | - lint-and-test: 66 | requires: 67 | - install 68 | - end-to-end-tests: 69 | requires: 70 | - install 71 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "parser": "@typescript-eslint/parser", 4 | "parserOptions": { 5 | "ecmaVersion": 2018, 6 | "sourceType": "module", 7 | "project": "./tsconfig.*?.json" 8 | }, 9 | "ignorePatterns": ["**/*"], 10 | "plugins": ["@typescript-eslint", "@nrwl/nx"], 11 | "extends": [ 12 | "eslint:recommended", 13 | "plugin:@typescript-eslint/eslint-recommended", 14 | "plugin:@typescript-eslint/recommended", 15 | "prettier", 16 | "prettier/@typescript-eslint" 17 | ], 18 | "rules": { 19 | "@typescript-eslint/explicit-member-accessibility": "off", 20 | "@typescript-eslint/explicit-function-return-type": "off", 21 | "@typescript-eslint/no-parameter-properties": "off", 22 | "@typescript-eslint/no-use-before-define": "off", 23 | "@nrwl/nx/enforce-module-boundaries": [ 24 | "error", 25 | { 26 | "enforceBuildableLibDependency": true, 27 | "allow": [], 28 | "depConstraints": [ 29 | { "sourceTag": "*", "onlyDependOnLibsWithTags": ["*"] } 30 | ] 31 | } 32 | ] 33 | }, 34 | "overrides": [ 35 | { 36 | "files": ["*.tsx"], 37 | "rules": { 38 | "@typescript-eslint/no-unused-vars": "off" 39 | } 40 | } 41 | ] 42 | } 43 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | 8 | # dependencies 9 | /node_modules 10 | 11 | # IDEs and editors 12 | /.idea 13 | .project 14 | .classpath 15 | .c9/ 16 | *.launch 17 | .settings/ 18 | *.sublime-workspace 19 | 20 | # IDE - VSCode 21 | .vscode/* 22 | !.vscode/settings.json 23 | !.vscode/tasks.json 24 | !.vscode/launch.json 25 | !.vscode/extensions.json 26 | 27 | # misc 28 | /.sass-cache 29 | /connect.lock 30 | /coverage 31 | /libpeerconnection.log 32 | npm-debug.log 33 | yarn-error.log 34 | testem.log 35 | /typings 36 | 37 | # System Files 38 | .DS_Store 39 | Thumbs.db 40 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | # Add files here to ignore them from prettier formatting 2 | 3 | /dist 4 | /coverage 5 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true 3 | } 4 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "nrwl.angular-console", 4 | "ms-vscode.vscode-typescript-tslint-plugin", 5 | "esbenp.prettier-vscode", 6 | "firsttris.vscode-jest-runner" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | (The MIT License) 2 | 3 | Copyright (c) 2017-2020 Narwhal Technologies Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | 'Software'), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **MOVED:** This repo has been moved into the main Nx monorepo (https://github.com/nrwl/nx). 2 | -------------------------------------------------------------------------------- /jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | projects: ['/packages/gatsby-plugin'], 3 | }; 4 | -------------------------------------------------------------------------------- /jest.preset.js: -------------------------------------------------------------------------------- 1 | const nxPreset = require('@nrwl/jest/preset'); 2 | module.exports = { 3 | ...nxPreset, 4 | testMatch: ['**/+(*.)+(spec|test).+(ts|js)?(x)'], 5 | transform: { 6 | '^.+\\.(ts|js|html)$': 'ts-jest', 7 | }, 8 | resolver: '@nrwl/jest/plugins/resolver', 9 | moduleFileExtensions: ['ts', 'js', 'html'], 10 | coverageReporters: ['html'], 11 | }; 12 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nrwl/gatsby/5a24e8ff28fbfeaee60e9350f049fd9cf9585c25/logo.png -------------------------------------------------------------------------------- /nx.json: -------------------------------------------------------------------------------- 1 | { 2 | "npmScope": "nrwl", 3 | "implicitDependencies": { 4 | "workspace.json": "*", 5 | "package.json": { 6 | "dependencies": "*", 7 | "devDependencies": "*" 8 | }, 9 | "tslint.json": "*", 10 | "nx.json": "*", 11 | "tsconfig.base.json": "*", 12 | ".eslintrc.json": "*" 13 | }, 14 | "workspaceLayout": { 15 | "appsDir": "packages", 16 | "lisDir": "packages" 17 | }, 18 | "projects": { 19 | "gatsby-plugin": { 20 | "tags": [] 21 | }, 22 | "gatsby-plugin-e2e": { 23 | "tags": [], 24 | "implicitDependencies": ["gatsby-plugin"] 25 | } 26 | }, 27 | "tasksRunnerOptions": { 28 | "default": { 29 | "runner": "@nrwl/nx-cloud", 30 | "options": { 31 | "accessToken": "MDYzNzNlYjUtZDQzOS00NzNiLWI2MmItNDU0NDQxMmZmODMyfHJlYWQ=", 32 | "cacheableOperations": ["build", "test", "lint", "e2e"], 33 | "canTrackAnalytics": false, 34 | "showUsageWarnings": true 35 | } 36 | } 37 | }, 38 | "affected": { 39 | "defaultBase": "master" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nrwl", 3 | "version": "0.0.0", 4 | "license": "MIT", 5 | "scripts": { 6 | "nx": "nx", 7 | "release": "./tools/scripts/publish.sh", 8 | "start": "nx serve", 9 | "build": "nx build gatsby-plugin", 10 | "test": "nx run-many --target=test --all --parallel", 11 | "lint": "nx workspace-lint && nx run-many --target=lint --all --parallel", 12 | "e2e": "nx e2e gatsby-plugin-e2e", 13 | "affected": "nx affected", 14 | "format": "nx format:write", 15 | "format:write": "nx format:write", 16 | "format:check": "nx format:check", 17 | "update": "nx migrate latest", 18 | "dep-graph": "nx dep-graph", 19 | "help": "nx help", 20 | "workspace-generator": "nx workspace-generator" 21 | }, 22 | "private": true, 23 | "dependencies": { 24 | "@nrwl/nx-cloud": "10.1.10", 25 | "@nrwl/nx-plugin": "11.0.18", 26 | "@nrwl/react": "11.0.18" 27 | }, 28 | "devDependencies": { 29 | "@nrwl/cli": "11.0.18", 30 | "@nrwl/eslint-plugin-nx": "11.0.18", 31 | "@nrwl/jest": "11.0.18", 32 | "@nrwl/tao": "11.0.18", 33 | "@nrwl/workspace": "11.0.18", 34 | "@types/jest": "26.0.19", 35 | "@types/node": "12.12.38", 36 | "@typescript-eslint/eslint-plugin": "4.11.0", 37 | "@typescript-eslint/parser": "4.11.0", 38 | "dotenv": "8.2.0", 39 | "eslint": "7.16.0", 40 | "eslint-config-prettier": "7.1.0", 41 | "gatsby": "2.29.1", 42 | "jest": "26.6.3", 43 | "prettier": "2.2.1", 44 | "ts-jest": "26.4.4", 45 | "ts-node": "9.1.1", 46 | "tslint": "6.1.3", 47 | "typescript": "4.0.5" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /packages/gatsby-plugin-e2e/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | name: 'react-native-e2e', 3 | preset: '../../jest.preset.js', 4 | globals: { 5 | 'ts-jest': { 6 | tsConfig: '/tsconfig.spec.json', 7 | }, 8 | }, 9 | transform: { 10 | '^.+\\.[tj]s$': 'ts-jest', 11 | }, 12 | moduleFileExtensions: ['ts', 'js', 'html'], 13 | coverageDirectory: '../../coverage/e2e/gatsby-plugin-e2e', 14 | }; 15 | -------------------------------------------------------------------------------- /packages/gatsby-plugin-e2e/tests/gatsby-plugin.test.ts: -------------------------------------------------------------------------------- 1 | import { 2 | checkFilesExist, 3 | ensureNxProject, 4 | runNxCommandAsync, 5 | uniq, 6 | updateFile, 7 | } from '@nrwl/nx-plugin/testing'; 8 | 9 | describe('gatsby-plugin e2e', () => { 10 | test('generates a valid gatsby application', async () => { 11 | const app = uniq('app'); 12 | ensureNxProject('@nrwl/gatsby', 'dist/packages/gatsby-plugin'); 13 | await runNxCommandAsync(`generate @nrwl/gatsby:app ${app}`); 14 | await runNxCommandAsync( 15 | `generate @nrwl/gatsby:component header --project ${app}` 16 | ); 17 | 18 | checkFilesExist( 19 | `apps/${app}/package.json`, 20 | `apps/${app}/src/components/header.tsx`, 21 | `apps/${app}/src/components/header.spec.tsx`, 22 | `apps/${app}/src/pages/index.tsx`, 23 | `apps/${app}/src/pages/index.spec.tsx` 24 | ); 25 | 26 | updateFile(`apps/${app}/src/pages/index.tsx`, (content) => { 27 | let updated = `import Header from '../components/header';\n${content}`; 28 | updated = updated.replace('
', '
'); 29 | return updated; 30 | }); 31 | 32 | let result = await runNxCommandAsync(`build ${app}`); 33 | expect(result.stdout).toContain('Done building in'); 34 | 35 | result = await runNxCommandAsync(`lint ${app}`); 36 | expect(result.stdout).not.toMatch('Lint errors found in the listed files'); 37 | 38 | result = await runNxCommandAsync(`test ${app}`); 39 | expect(result.stderr).toContain('Test Suites: 2 passed, 2 total'); 40 | 41 | // result = await runNxCommandAsync(`e2e ${app}-e2e`); 42 | // expect(result.stdout).toContain('All specs passed'); 43 | }, 120000); 44 | 45 | test('supports --js option', async () => { 46 | const app = uniq('app'); 47 | ensureNxProject('@nrwl/gatsby', 'dist/packages/gatsby-plugin'); 48 | await runNxCommandAsync(`generate @nrwl/gatsby:app ${app} --js`); 49 | 50 | checkFilesExist( 51 | `apps/${app}/package.json`, 52 | `apps/${app}/src/pages/index.js`, 53 | `apps/${app}/src/pages/index.spec.js` 54 | ); 55 | 56 | const result = await runNxCommandAsync(`build ${app}`); 57 | expect(result.stdout).toContain('Done building in'); 58 | }, 120000); 59 | }); 60 | -------------------------------------------------------------------------------- /packages/gatsby-plugin-e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../../dist/out-tsc", 5 | "module": "commonjs", 6 | "types": ["jest", "node"] 7 | }, 8 | "include": ["**/*.test.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /packages/gatsby-plugin-e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "files": [], 4 | "include": [], 5 | "references": [ 6 | { 7 | "path": "./tsconfig.e2e.json" 8 | }, 9 | { 10 | "path": "./tsconfig.spec.json" 11 | } 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /packages/gatsby-plugin-e2e/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../../dist/out-tsc", 5 | "module": "commonjs", 6 | "types": ["jest", "node"] 7 | }, 8 | "include": ["**/*.spec.ts", "**/*.d.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { "extends": "../../.eslintrc", "rules": {}, "ignorePatterns": ["!**/*"] } 2 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/LICENSE: -------------------------------------------------------------------------------- 1 | (The MIT License) 2 | 3 | Copyright (c) 2017-2020 Narwhal Technologies Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | 'Software'), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/README.md: -------------------------------------------------------------------------------- 1 | # Gatsby Plugin for Nx 2 | 3 |

4 | 5 |
6 | 7 | [![License](https://img.shields.io/npm/l/@nrwl/workspace.svg?style=flat-square)]() 8 | [![NPM Version](https://badge.fury.io/js/%40nrwl%2Fgatsby.svg)](https://www.npmjs.com/@nrwl/gatsby) 9 | [![Join the chat at https://gitter.im/nrwl-nx/community](https://badges.gitter.im/nrwl-nx/community.svg)](https://gitter.im/nrwl-nx/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 10 | [![Join us @nrwl/community on slack](https://img.shields.io/badge/slack-%40nrwl%2Fcommunity-brightgreen)](https://join.slack.com/t/nrwlcommunity/shared_invite/enQtNzU5MTE4OTQwOTk0LTgxY2E0ZWYzMWE0YzA5ZDA2MWM1NDVhNmI2ZWMyYmZhNWJiODk3MjkxZjY3MzU5ZjRmM2NmNWU1OTgyZmE4Mzc) 11 | 12 |
13 | 14 | 15 | ## Getting started 16 | 17 | ### Create a new Nx workspace: 18 | 19 | ``` 20 | > npx create-nx-workspace --cli=nx --preset=empty 21 | ``` 22 | 23 | ### Create an app 24 | 25 | 26 | ``` 27 | > npx nx g @nrwl/gatsby:app 28 | ``` 29 | 30 | When using Nx, you can create multiple applications and themes in the same workspace. If you don't want to prefix your commands with npx, install `@nrwl/cli` globally. 31 | 32 | 33 | ### Serve the app 34 | 35 | ``` 36 | > npx nx serve --open 37 | ``` 38 | 39 | In prod mode: 40 | 41 | ``` 42 | > npx nx serve --prod --open 43 | ``` 44 | 45 | 46 | ### Build/test/lint the app 47 | 48 | ``` 49 | > npx nx build 50 | > npx nx test 51 | > npx nx lint 52 | ``` 53 | 54 | ## Using components from React library 55 | 56 | You can use a component from React library generated using Nx package for React. Once you run: 57 | 58 | ``` 59 | > npx nx g @nrwl/react:lib ui-button --style=css 60 | ``` 61 | 62 | This will generate the `UiButton` component, which you can use in your app. 63 | 64 | ```jsx 65 | import { UiButton } from '@myorg/ui-button'; 66 | ``` 67 | 68 | ## Learn more 69 | 70 | Visit the [Nx Documentation](https://nx.dev) to learn more. 71 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/babel.ts: -------------------------------------------------------------------------------- 1 | /* 2 | * Babel preset to provide Gatsby support for Nx. 3 | */ 4 | module.exports = function(api, options) { 5 | api.assertVersion(7); 6 | return { 7 | presets: [[require.resolve('babel-preset-gatsby'), { useBuiltIns: true }]] 8 | }; 9 | }; 10 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/builders.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "../../node_modules/@angular-devkit/architect/src/builders-schema.json", 3 | "builders": { 4 | "build": { 5 | "implementation": "./src/builders/build/builder", 6 | "schema": "./src/builders/build/schema.json", 7 | "description": "Build a Gatsby app" 8 | }, 9 | "server": { 10 | "implementation": "./src/builders/server/builder", 11 | "schema": "./src/builders/server/schema.json", 12 | "description": "Starts server for app" 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/collection.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "../../node_modules/@angular-devkit/schematics/collection-schema.json", 3 | "name": "Nx Gatsby", 4 | "version": "0.1", 5 | "extends": ["@nrwl/react"], 6 | "schematics": { 7 | "init": { 8 | "factory": "./src/schematics/init/init", 9 | "schema": "./src/schematics/init/schema.json", 10 | "description": "Initialize the @nrwl/gatsby plugin", 11 | "hidden": true 12 | }, 13 | "application": { 14 | "factory": "./src/schematics/application/application", 15 | "schema": "./src/schematics/application/schema.json", 16 | "aliases": ["app"], 17 | "description": "Create an application" 18 | }, 19 | "component": { 20 | "factory": "./src/schematics/component/component", 21 | "schema": "./src/schematics/component/schema.json", 22 | "description": "Create a component" 23 | }, 24 | "page": { 25 | "factory": "./src/schematics/page/page", 26 | "schema": "./src/schematics/page/schema.json", 27 | "description": "Create a page" 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | preset: '../../jest.preset.js', 3 | transform: { 4 | '^.+\\.[tj]sx?$': 'ts-jest', 5 | }, 6 | moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'html'], 7 | coverageDirectory: '../../coverage/libs/gatsby-plugin', 8 | globals: { 'ts-jest': { tsConfig: '/tsconfig.spec.json' } }, 9 | displayName: 'gatsby-plugin', 10 | }; 11 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@nrwl/gatsby", 3 | "version": "11.0.0", 4 | "description": "Gatsby Plugin for Nx", 5 | "repository": { 6 | "type": "git", 7 | "url": "git+https://github.com/nrwl/gatsby.git" 8 | }, 9 | "keywords": [ 10 | "Monorepo", 11 | "Gatsby", 12 | "Web", 13 | "Jest", 14 | "Cypress", 15 | "CLI" 16 | ], 17 | "author": "Max Koretskyi", 18 | "license": "MIT", 19 | "bugs": { 20 | "url": "https://github.com/nrwl/gatsby/issues" 21 | }, 22 | "homepage": "https://nx.dev", 23 | "schematics": "./collection.json", 24 | "builders": "./builders.json", 25 | "peerDependencies": { 26 | "@nrwl/workspace": "*" 27 | }, 28 | "dependencies": { 29 | "@angular-devkit/schematics": "10.1.7", 30 | "gatsby-cli": "^2.14.1", 31 | "@nrwl/react": "^10.4.4", 32 | "@nrwl/cypress": "^10.4.4", 33 | "@nrwl/jest": "^10.4.4" 34 | } 35 | } -------------------------------------------------------------------------------- /packages/gatsby-plugin/plugins/nx-gatsby-ext-plugin/gatsby-config.ts: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: [ 3 | `gatsby-plugin-typescript` 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/plugins/nx-gatsby-ext-plugin/gatsby-node.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path'; 2 | import { appRootPath as workspaceRoot } from '@nrwl/workspace/src/utils/app-root'; 3 | import { readJsonFile } from '@nrwl/workspace'; 4 | 5 | function onCreateBabelConfig({ actions }, options) { 6 | const tsConfig = readJsonFile(path.join(workspaceRoot, 'tsconfig.base.json')); 7 | const tsConfigPaths: { [key: string]: Array } = 8 | tsConfig.compilerOptions.paths; 9 | 10 | const paths = Object.entries(tsConfigPaths).reduce((result, [key, paths]) => { 11 | return { 12 | ...result, 13 | [key]: paths.map((p) => path.join(workspaceRoot, p)), 14 | }; 15 | }, {}); 16 | 17 | actions.setBabelPlugin({ 18 | name: require.resolve(`babel-plugin-module-resolver`), 19 | options: { 20 | root: ['./src'], 21 | alias: paths, 22 | }, 23 | }); 24 | } 25 | 26 | export { onCreateBabelConfig }; 27 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/plugins/nx-gatsby-ext-plugin/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nx-gatsby-ext-plugin", 3 | "version": "1.0.0", 4 | "main": "gatsby-config.js", 5 | "author": "max koretskyi", 6 | "license": "MIT", 7 | "peerDependencies": { 8 | "gatsby": "^2.6.0" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/publish.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | echo "Publishing gatsby-plugin@$1" 3 | 4 | nx build gatsby-plugin 5 | cd dist/packages/gatsby-plugin 6 | 7 | if [[ "$OSTYPE" == "darwin"* ]]; then 8 | sed -i "" "s|0.0.1|$1|g" package.json 9 | else 10 | sed -i "s|0.0.1|$1|g" package.json 11 | fi 12 | 13 | npm adduser 14 | npm publish --access public --tag latest 15 | 16 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/builders/build/builder.ts: -------------------------------------------------------------------------------- 1 | import { 2 | BuilderContext, 3 | BuilderOutput, 4 | createBuilder, 5 | } from '@angular-devkit/architect'; 6 | import { fork } from 'child_process'; 7 | import { join } from 'path'; 8 | import { from, Observable } from 'rxjs'; 9 | import { concatMap } from 'rxjs/operators'; 10 | import { GatsbyPluginBuilderSchema } from './schema'; 11 | import { getProjectRoot } from '../../utils/get-project-root'; 12 | 13 | export function runBuilder( 14 | options: GatsbyPluginBuilderSchema, 15 | context: BuilderContext 16 | ): Observable { 17 | return from(getProjectRoot(context)).pipe( 18 | concatMap((projectRoot) => { 19 | return new Observable((subscriber) => { 20 | runGatsbyBuild(context.workspaceRoot, projectRoot, options) 21 | .then(() => { 22 | subscriber.next({ 23 | success: true, 24 | }); 25 | subscriber.complete(); 26 | }) 27 | .catch((err) => { 28 | context.logger.error('Error during build', err); 29 | subscriber.next({ 30 | success: false, 31 | }); 32 | subscriber.complete(); 33 | }); 34 | }); 35 | }) 36 | ); 37 | } 38 | 39 | export function runGatsbyBuild( 40 | workspaceRoot: string, 41 | projectRoot: string, 42 | options: GatsbyPluginBuilderSchema 43 | ) { 44 | return new Promise((resolve, reject) => { 45 | const cp = fork( 46 | require.resolve('gatsby-cli'), 47 | ['build', ...createGatsbyBuildOptions(options)], 48 | { 49 | cwd: join(workspaceRoot, projectRoot), 50 | } 51 | ); 52 | 53 | cp.on('error', (err) => { 54 | reject(err); 55 | }); 56 | 57 | cp.on('exit', (code) => { 58 | if (code === 0) { 59 | resolve(); 60 | } else { 61 | reject(code); 62 | } 63 | }); 64 | }); 65 | } 66 | 67 | function createGatsbyBuildOptions(options: GatsbyPluginBuilderSchema) { 68 | return Object.keys(options).reduce((acc, k) => { 69 | const val = options[k]; 70 | if (typeof val === 'undefined') return acc; 71 | switch (k) { 72 | case 'prefixPaths': 73 | return val ? acc.concat(`--prefix-paths`) : acc; 74 | case 'uglify': 75 | return val ? acc : acc.concat('--no-uglify'); 76 | case 'color': 77 | return val ? acc : acc.concat('--no-color'); 78 | case 'profile': 79 | return val ? acc.concat('--profile') : acc; 80 | case 'openTracingConfigFile': 81 | return val ? acc.concat([`--open-tracing-config-file`, val]) : acc; 82 | case 'graphqlTracing': 83 | return val ? acc.concat('--graphql-tracing') : acc; 84 | case 'serve': 85 | case 'host': 86 | case 'port': 87 | default: 88 | return acc; 89 | } 90 | }, []); 91 | } 92 | 93 | export default createBuilder(runBuilder); 94 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/builders/build/schema.d.ts: -------------------------------------------------------------------------------- 1 | import { JsonObject } from '@angular-devkit/core'; 2 | 3 | export interface GatsbyPluginBuilderSchema extends JsonObject { 4 | prefixPaths?: boolean; 5 | uglify: boolean; 6 | profile?: boolean; 7 | openTracingConfigFile?: string; 8 | graphqlTracing?: boolean; 9 | color: boolean; 10 | } 11 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/builders/build/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/schema", 3 | "title": "GatsbyPlugin builder", 4 | "description": "", 5 | "type": "object", 6 | "properties": { 7 | "prefixPaths": { 8 | "type": "boolean", 9 | "description": "Build site with link paths prefixed (set pathPrefix in your config)." 10 | }, 11 | "uglify": { 12 | "type": "boolean", 13 | "description": "Build site without uglifying JS bundles (true by default).", 14 | "default": true 15 | }, 16 | "profile": { 17 | "type": "boolean", 18 | "description": "Build site with react profiling." 19 | }, 20 | "openTracingConfigFile": { 21 | "type": "string", 22 | "description": "Tracer configuration file (OpenTracing compatible)." 23 | }, 24 | "graphqlTracing": { 25 | "type": "boolean", 26 | "description": "Trace every graphql resolver, may have performance implications." 27 | }, 28 | "color": { 29 | "type": "boolean", 30 | "description": "Enable colored terminal output.", 31 | "default": true 32 | } 33 | }, 34 | "required": [] 35 | } -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/builders/server/builder.ts: -------------------------------------------------------------------------------- 1 | import { 2 | BuilderContext, 3 | BuilderOutput, 4 | createBuilder, 5 | targetFromTargetString, 6 | } from '@angular-devkit/architect'; 7 | import { fork } from 'child_process'; 8 | import { join } from 'path'; 9 | import { from, Observable, of } from 'rxjs'; 10 | import { catchError, concatMap, withLatestFrom } from 'rxjs/operators'; 11 | import { GatsbyPluginBuilderSchema } from './schema'; 12 | import { runGatsbyBuild } from '../build/builder'; 13 | import { GatsbyPluginBuilderSchema as BuildBuilderSchema } from '../build/schema'; 14 | import { getProjectRoot } from '../../utils/get-project-root'; 15 | 16 | export function runBuilder( 17 | options: GatsbyPluginBuilderSchema, 18 | context: BuilderContext 19 | ): Observable { 20 | const buildTarget = targetFromTargetString(options.buildTarget); 21 | const baseUrl = `${options.https ? 'https' : 'http'}://${options.host}:${ 22 | options.port 23 | }`; 24 | return from(getProjectRoot(context)).pipe( 25 | concatMap((projectRoot) => { 26 | return from(context.getTargetOptions(buildTarget)).pipe( 27 | concatMap((buildOptions: BuildBuilderSchema) => { 28 | return new Observable((subscriber) => { 29 | if (context.target.configuration === 'production') { 30 | runGatsbyBuild(context.workspaceRoot, projectRoot, buildOptions) 31 | .then(() => 32 | runGatsbyServe(context.workspaceRoot, projectRoot, options) 33 | ) 34 | .then(() => { 35 | subscriber.next({ 36 | success: true, 37 | }); 38 | }) 39 | .catch((err) => { 40 | context.logger.error('Error during serve', err); 41 | }); 42 | } else { 43 | runGatsbyDevelop( 44 | context.workspaceRoot, 45 | projectRoot, 46 | createGatsbyOptions(options) 47 | ) 48 | .then((success) => { 49 | subscriber.next({ 50 | baseUrl, 51 | success, 52 | }); 53 | }) 54 | .catch((err) => { 55 | context.logger.error('Error during serve', err?.message); 56 | subscriber.next({ 57 | success: false, 58 | }); 59 | subscriber.complete(); 60 | }); 61 | } 62 | }); 63 | }), 64 | catchError((err) => { 65 | context.logger.error(err); 66 | return of({ success: false }); 67 | }) 68 | ); 69 | }) 70 | ); 71 | } 72 | 73 | function createGatsbyOptions(options) { 74 | return Object.keys(options).reduce((acc, k) => { 75 | if (k === 'port' || k === 'host' || k === 'https' || k === 'open') 76 | acc.push(`--${k}=${options[k]}`); 77 | return acc; 78 | }, []); 79 | } 80 | 81 | async function runGatsbyDevelop(workspaceRoot, projectRoot, options) { 82 | return new Promise((resolve, reject) => { 83 | const cp = fork(require.resolve('gatsby-cli'), ['develop', ...options], { 84 | cwd: join(workspaceRoot, projectRoot), 85 | env: { 86 | ...process.env, 87 | }, 88 | stdio: ['inherit', 'inherit', 'inherit', 'ipc'], 89 | }); 90 | 91 | // Ensure the child process is killed when the parent exits 92 | process.on('exit', () => cp.kill()); 93 | 94 | cp.on('message', ({ action }) => { 95 | if ( 96 | action?.type === 'ACTIVITY_END' && 97 | action?.payload?.status === 'SUCCESS' && 98 | action?.payload?.id === 'webpack-develop' 99 | ) { 100 | resolve(true); 101 | } 102 | }); 103 | 104 | cp.on('error', (err) => { 105 | reject(err); 106 | }); 107 | 108 | cp.on('exit', (code) => { 109 | if (code !== 0) { 110 | reject(code); 111 | } 112 | }); 113 | }); 114 | } 115 | 116 | function runGatsbyServe( 117 | workspaceRoot: string, 118 | projectRoot: string, 119 | options: GatsbyPluginBuilderSchema 120 | ) { 121 | return new Promise((resolve, reject) => { 122 | const cp = fork( 123 | require.resolve('gatsby-cli'), 124 | ['serve', ...createGatsbyServeOptions(options)], 125 | { cwd: join(workspaceRoot, projectRoot) } 126 | ); 127 | 128 | cp.on('error', (err) => { 129 | reject(err); 130 | }); 131 | 132 | cp.on('exit', (code) => { 133 | if (code === 0) { 134 | resolve(code); 135 | } else { 136 | reject(code); 137 | } 138 | }); 139 | }); 140 | } 141 | 142 | function createGatsbyServeOptions(options: GatsbyPluginBuilderSchema) { 143 | return Object.keys(options).reduce((acc, k) => { 144 | const val = options[k]; 145 | if (typeof val === 'undefined') return acc; 146 | switch (k) { 147 | case 'host': 148 | return val ? acc.concat([`--host`, val]) : acc; 149 | case 'open': 150 | return val ? acc.concat(`--open`) : acc; 151 | case 'prefixPaths': 152 | return val ? acc.concat(`--prefix-paths`) : acc; 153 | case 'port': 154 | return val ? acc.concat([`--port`, val]) : acc; 155 | default: 156 | return acc; 157 | } 158 | }, []); 159 | } 160 | 161 | export default createBuilder(runBuilder); 162 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/builders/server/schema.d.ts: -------------------------------------------------------------------------------- 1 | import { JsonObject } from '@angular-devkit/core'; 2 | 3 | export interface GatsbyPluginBuilderSchema extends JsonObject { 4 | buildTarget: string; 5 | host: string; 6 | port: string; 7 | open: boolean; 8 | https: boolean; 9 | } 10 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/builders/server/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "title": "Gatsby development server", 3 | "description": "Gatsby development server", 4 | "type": "object", 5 | "properties": { 6 | "buildTarget": { 7 | "type": "string", 8 | "description": "Target which builds the application" 9 | }, 10 | "port": { 11 | "type": "number", 12 | "description": "Port to listen on.", 13 | "default": 4200 14 | }, 15 | "host": { 16 | "type": "string", 17 | "description": "Host to listen on.", 18 | "default": "localhost" 19 | }, 20 | "https": { 21 | "type": "boolean", 22 | "description": "Serve using HTTPS.", 23 | "default": false 24 | }, 25 | "open": { 26 | "type": "boolean", 27 | "description": "Open the site in your (default) browser for you." 28 | } 29 | }, 30 | "required": [] 31 | } -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/index.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nrwl/gatsby/5a24e8ff28fbfeaee60e9350f049fd9cf9585c25/packages/gatsby-plugin/src/index.ts -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/schematics/application/application.ts: -------------------------------------------------------------------------------- 1 | import { join, normalize } from '@angular-devkit/core'; 2 | import { 3 | apply, 4 | applyTemplates, 5 | chain, 6 | externalSchematic, 7 | filter, 8 | mergeWith, 9 | move, 10 | noop, 11 | Rule, 12 | SchematicContext, 13 | Tree, 14 | url, 15 | } from '@angular-devkit/schematics'; 16 | import { 17 | addLintFiles, 18 | addProjectToNxJsonInTree, 19 | formatFiles, 20 | generateProjectLint, 21 | Linter, 22 | names, 23 | projectRootDir, 24 | ProjectType, 25 | toFileName, 26 | updateJsonInTree, 27 | updateWorkspaceInTree, 28 | } from '@nrwl/workspace'; 29 | 30 | import init from '../init/init'; 31 | import { GatsbyPluginSchematicSchema } from './schema'; 32 | import { appsDir } from '@nrwl/workspace/src/utils/ast-utils'; 33 | import { updateJestConfigContent } from '@nrwl/react/src/utils/jest-utils'; 34 | import { toJS } from '@nrwl/workspace/src/utils/rules/to-js'; 35 | import { 36 | assertValidStyle, 37 | extraEslintDependencies, 38 | reactEslintJson, 39 | } from '@nrwl/react'; 40 | import { addStyleDependencies } from '../../utils/styles'; 41 | 42 | const projectType = ProjectType.Application; 43 | 44 | interface NormalizedSchema extends GatsbyPluginSchematicSchema { 45 | projectName: string; 46 | projectRoot: string; 47 | projectDirectory: string; 48 | parsedTags: string[]; 49 | styledModule: null | string; 50 | } 51 | 52 | export default function (options: GatsbyPluginSchematicSchema): Rule { 53 | const normalizedOptions = normalizeOptions(options); 54 | return chain([ 55 | init({ 56 | ...options, 57 | skipFormat: true, 58 | }), 59 | addLintFiles(normalizedOptions.projectRoot, Linter.EsLint, { 60 | localConfig: { 61 | ...reactEslintJson, 62 | overrides: [ 63 | { 64 | files: ['*.tsx', '*.ts'], 65 | rules: { 66 | '@typescript-eslint/camelcase': 'off', 67 | }, 68 | }, 69 | ], 70 | }, 71 | extraPackageDeps: extraEslintDependencies, 72 | }), 73 | addProject(normalizedOptions), 74 | addProjectToNxJsonInTree(normalizedOptions.projectName, { 75 | tags: normalizedOptions.parsedTags, 76 | }), 77 | createApplicationFiles(normalizedOptions), 78 | addStyleDependencies(options.style), 79 | addJest(normalizedOptions), 80 | updateJestConfig(normalizedOptions), 81 | updateEslintConfig(normalizedOptions), 82 | addCypress(normalizedOptions), 83 | addPrettierIgnoreEntry(normalizedOptions), 84 | addGitIgnoreEntry(normalizedOptions), 85 | formatFiles(), 86 | ]); 87 | } 88 | 89 | function normalizeOptions( 90 | options: GatsbyPluginSchematicSchema 91 | ): NormalizedSchema { 92 | const name = toFileName(options.name); 93 | const projectDirectory = options.directory 94 | ? `${toFileName(options.directory)}/${name}` 95 | : name; 96 | const projectName = projectDirectory.replace(new RegExp('/', 'g'), '-'); 97 | const projectRoot = `${projectRootDir(projectType)}/${projectDirectory}`; 98 | const parsedTags = options.tags 99 | ? options.tags.split(',').map((s) => s.trim()) 100 | : []; 101 | 102 | const styledModule = /^(css|scss|less|styl)$/.test(options.style) 103 | ? null 104 | : options.style; 105 | 106 | assertValidStyle(options.style); 107 | 108 | return { 109 | ...options, 110 | styledModule, 111 | projectName, 112 | projectRoot, 113 | projectDirectory, 114 | parsedTags, 115 | }; 116 | } 117 | 118 | function createApplicationFiles(options: NormalizedSchema): Rule { 119 | return mergeWith( 120 | apply(url(`./files`), [ 121 | applyTemplates({ 122 | ...options, 123 | ...names(options.name), 124 | }), 125 | options.styledModule 126 | ? filter((file) => !file.endsWith(`.${options.style}`)) 127 | : noop(), 128 | move(options.projectRoot), 129 | options.js ? toJS() : noop(), 130 | ]) 131 | ); 132 | } 133 | 134 | function addProject(options: NormalizedSchema): Rule { 135 | return updateWorkspaceInTree((json) => { 136 | const architect: { [key: string]: any } = {}; 137 | 138 | architect.build = { 139 | builder: '@nrwl/gatsby:build', 140 | options: { 141 | outputPath: `${options.projectRoot}/public`, 142 | uglify: true, 143 | color: true, 144 | profile: false, 145 | }, 146 | configurations: { 147 | production: {}, 148 | }, 149 | }; 150 | 151 | architect.serve = { 152 | builder: '@nrwl/gatsby:server', 153 | options: { 154 | buildTarget: `${options.projectName}:build`, 155 | }, 156 | configurations: { 157 | production: { 158 | buildTarget: `${options.projectName}:build:production`, 159 | }, 160 | }, 161 | }; 162 | 163 | architect.lint = generateProjectLint( 164 | normalize(options.projectRoot), 165 | join(normalize(options.projectRoot), 'tsconfig.json'), 166 | Linter.EsLint, 167 | [`${options.projectRoot}/**/*.{ts,tsx,js,jsx}`] 168 | ); 169 | 170 | json.projects[options.projectName] = { 171 | root: options.projectRoot, 172 | sourceRoot: `${options.projectRoot}/src`, 173 | projectType, 174 | schematics: {}, 175 | architect, 176 | }; 177 | 178 | json.defaultProject = json.defaultProject || options.projectName; 179 | 180 | return json; 181 | }); 182 | } 183 | 184 | function addCypress(options: NormalizedSchema): Rule { 185 | return options.e2eTestRunner === 'cypress' 186 | ? externalSchematic('@nrwl/cypress', 'cypress-project', { 187 | ...options, 188 | name: options.name + '-e2e', 189 | directory: options.directory, 190 | project: options.projectName, 191 | }) 192 | : noop(); 193 | } 194 | 195 | function addJest(options: NormalizedSchema): Rule { 196 | return options.unitTestRunner === 'jest' 197 | ? externalSchematic('@nrwl/jest', 'jest-project', { 198 | project: options.projectName, 199 | supportTsx: true, 200 | skipSerializers: true, 201 | setupFile: 'none', 202 | babelJest: false, 203 | }) 204 | : noop(); 205 | } 206 | 207 | function addPrettierIgnoreEntry(options: NormalizedSchema) { 208 | return (tree: Tree, context: SchematicContext) => { 209 | let prettierIgnoreFile = tree.read('.prettierignore')?.toString('utf-8'); 210 | if (prettierIgnoreFile) { 211 | prettierIgnoreFile = 212 | prettierIgnoreFile + 213 | `\n/apps/${options.projectName}/node_modules\n/apps/${options.projectName}/public\n/apps/${options.projectName}/.cache\n`; 214 | tree.overwrite('.prettierignore', prettierIgnoreFile); 215 | } else { 216 | context.logger.warn(`Couldn't find .prettierignore file to update`); 217 | } 218 | }; 219 | } 220 | 221 | function addGitIgnoreEntry(options: NormalizedSchema) { 222 | return (tree: Tree, context: SchematicContext) => { 223 | let gitIgnoreFile = tree.read('.gitignore')?.toString('utf-8'); 224 | if (gitIgnoreFile) { 225 | gitIgnoreFile = 226 | gitIgnoreFile + 227 | `\n/apps/${options.projectName}/node_modules\n/apps/${options.projectName}/public\n/apps/${options.projectName}/.cache\n`; 228 | tree.overwrite('.gitignore', gitIgnoreFile); 229 | } else { 230 | context.logger.warn(`Couldn't find .gitignore file to update`); 231 | } 232 | }; 233 | } 234 | 235 | function updateJestConfig(options: NormalizedSchema) { 236 | return options.unitTestRunner === 'none' 237 | ? noop() 238 | : (host) => { 239 | const appDirectory = options.directory 240 | ? `${toFileName(options.directory)}/${toFileName(options.name)}` 241 | : toFileName(options.name); 242 | const appProjectRoot = `${appsDir(host)}/${appDirectory}`; 243 | const configPath = `${appProjectRoot}/jest.config.js`; 244 | const originalContent = host.read(configPath).toString(); 245 | const content = updateJestConfigContent(originalContent); 246 | host.overwrite(configPath, content); 247 | }; 248 | } 249 | function updateEslintConfig(options: NormalizedSchema) { 250 | const appDirectory = options.directory 251 | ? `${toFileName(options.directory)}/${toFileName(options.name)}` 252 | : toFileName(options.name); 253 | return (host) => { 254 | const appProjectRoot = `${appsDir(host)}/${appDirectory}`; 255 | const configPath = `${appProjectRoot}/.eslintrc.json`; 256 | return updateJsonInTree(configPath, (json) => { 257 | json.ignorePatterns = ['!**/*', 'public', '.cache']; 258 | return json; 259 | }); 260 | }; 261 | } 262 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/schematics/application/files/.babelrc.template: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["@nrwl/gatsby/babel"], 3 | "plugins": [] 4 | } 5 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/schematics/application/files/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (http://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # Typescript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # dotenv environment variable files 55 | .env* 56 | 57 | # gatsby files 58 | .cache/ 59 | public 60 | 61 | # Mac files 62 | .DS_Store 63 | 64 | # Yarn 65 | yarn-error.log 66 | .pnp/ 67 | .pnp.js 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/schematics/application/files/.prettierignore: -------------------------------------------------------------------------------- 1 | .cache 2 | package.json 3 | package-lock.json 4 | public 5 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/schematics/application/files/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "arrowParens": "avoid", 3 | "semi": false 4 | } 5 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/schematics/application/files/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 gatsbyjs 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/schematics/application/files/README.md: -------------------------------------------------------------------------------- 1 | 2 |

3 | 4 | Gatsby 5 | 6 |

7 |

8 | Gatsby's default starter 9 |

10 | 11 | Kick off your project with this default boilerplate. This starter ships with the main Gatsby configuration files you might need to get up and running blazing fast with the blazing fast app generator for React. 12 | 13 | _Have another more specific idea? You may want to check out our vibrant collection of [official and community-created starters](https://www.gatsbyjs.org/docs/gatsby-starters/)._ 14 | 15 | ## 🚀 Quick start 16 | 17 | 1. **Create a Gatsby site.** 18 | 19 | Use the Gatsby CLI to create a new site, specifying the default starter. 20 | 21 | ```shell 22 | # create a new Gatsby site using the default starter 23 | gatsby new my-default-starter https://github.com/gatsbyjs/gatsby-starter-default 24 | ``` 25 | 26 | 1. **Start developing.** 27 | 28 | Navigate into your new site’s directory and start it up. 29 | 30 | ```shell 31 | cd my-default-starter/ 32 | gatsby develop 33 | ``` 34 | 35 | 1. **Open the source code and start editing!** 36 | 37 | Your site is now running at `http://localhost:8000`! 38 | 39 | _Note: You'll also see a second link: _`http://localhost:8000/___graphql`_. This is a tool you can use to experiment with querying your data. Learn more about using this tool in the [Gatsby tutorial](https://www.gatsbyjs.org/tutorial/part-five/#introducing-graphiql)._ 40 | 41 | Open the `my-default-starter` directory in your code editor of choice and edit `src/pages/index.js`. Save your changes and the browser will update in real time! 42 | 43 | ## 🧐 What's inside? 44 | 45 | A quick look at the top-level files and directories you'll see in a Gatsby project. 46 | 47 | . 48 | ├── node_modules 49 | ├── src 50 | ├── .gitignore 51 | ├── .prettierrc 52 | ├── gatsby-browser.js 53 | ├── gatsby-config.js 54 | ├── gatsby-node.js 55 | ├── gatsby-ssr.js 56 | ├── LICENSE 57 | ├── package-lock.json 58 | ├── package.json 59 | └── README.md 60 | 61 | 1. **`/node_modules`**: This directory contains all of the modules of code that your project depends on (npm packages) are automatically installed. 62 | 63 | 2. **`/src`**: This directory will contain all of the code related to what you will see on the front-end of your site (what you see in the browser) such as your site header or a page template. `src` is a convention for “source code”. 64 | 65 | 3. **`.gitignore`**: This file tells git which files it should not track / not maintain a version history for. 66 | 67 | 4. **`.prettierrc`**: This is a configuration file for [Prettier](https://prettier.io/). Prettier is a tool to help keep the formatting of your code consistent. 68 | 69 | 5. **`gatsby-browser.js`**: This file is where Gatsby expects to find any usage of the [Gatsby browser APIs](https://www.gatsbyjs.org/docs/browser-apis/) (if any). These allow customization/extension of default Gatsby settings affecting the browser. 70 | 71 | 6. **`gatsby-config.js`**: This is the main configuration file for a Gatsby site. This is where you can specify information about your site (metadata) like the site title and description, which Gatsby plugins you’d like to include, etc. (Check out the [config docs](https://www.gatsbyjs.org/docs/gatsby-config/) for more detail). 72 | 73 | 7. **`gatsby-node.js`**: This file is where Gatsby expects to find any usage of the [Gatsby Node APIs](https://www.gatsbyjs.org/docs/node-apis/) (if any). These allow customization/extension of default Gatsby settings affecting pieces of the site build process. 74 | 75 | 8. **`gatsby-ssr.js`**: This file is where Gatsby expects to find any usage of the [Gatsby server-side rendering APIs](https://www.gatsbyjs.org/docs/ssr-apis/) (if any). These allow customization of default Gatsby settings affecting server-side rendering. 76 | 77 | 9. **`LICENSE`**: Gatsby is licensed under the MIT license. 78 | 79 | 10. **`package-lock.json`** (See `package.json` below, first). This is an automatically generated file based on the exact versions of your npm dependencies that were installed for your project. **(You won’t change this file directly).** 80 | 81 | 11. **`package.json`**: A manifest file for Node.js projects, which includes things like metadata (the project’s name, author, etc). This manifest is how npm knows which packages to install for your project. 82 | 83 | 12. **`README.md`**: A text file containing useful reference information about your project. 84 | 85 | ## 🎓 Learning Gatsby 86 | 87 | Looking for more guidance? Full documentation for Gatsby lives [on the website](https://www.gatsbyjs.org/). Here are some places to start: 88 | 89 | - **For most developers, we recommend starting with our [in-depth tutorial for creating a site with Gatsby](https://www.gatsbyjs.org/tutorial/).** It starts with zero assumptions about your level of ability and walks through every step of the process. 90 | 91 | - **To dive straight into code samples, head [to our documentation](https://www.gatsbyjs.org/docs/).** In particular, check out the _Guides_, _API Reference_, and _Advanced Tutorials_ sections in the sidebar. 92 | 93 | ## 💫 Deploy 94 | 95 | [![Deploy to Netlify](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/gatsbyjs/gatsby-starter-default) 96 | 97 | [![Deploy with ZEIT Now](https://zeit.co/button)](https://zeit.co/import/project?template=https://github.com/gatsbyjs/gatsby-starter-default) 98 | 99 | 100 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/schematics/application/files/gatsby-browser.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Implement Gatsby's Browser APIs in this file. 3 | * 4 | * See: https://www.gatsbyjs.org/docs/browser-apis/ 5 | */ 6 | 7 | // You can delete this file if you're not using it 8 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/schematics/application/files/gatsby-config.js.template: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | siteMetadata: { 3 | title: `<%= name %>`, 4 | description: `This is a gatsby application created by Nx.` 5 | }, 6 | plugins: [ 7 | <% if (style === 'less') { %>'gatsby-plugin-less',<% } %> 8 | <% if (style === 'scss') { %>'gatsby-plugin-sass',<% } %> 9 | <% if (style === 'styl') { %>'gatsby-plugin-stylus',<% } %> 10 | <% if (style === 'styled-components') { %>'gatsby-plugin-styled-components',<% } %> 11 | <% if (style === '@emotion/styled') { %>'gatsby-plugin-emotion',<% } %> 12 | { 13 | resolve: 'gatsby-plugin-svgr', 14 | options: { 15 | svgo: false, 16 | ref: true 17 | } 18 | }, 19 | `gatsby-plugin-react-helmet`, 20 | { 21 | resolve: `gatsby-source-filesystem`, 22 | options: { 23 | name: `images`, 24 | path: `${__dirname}/src/images` 25 | } 26 | }, 27 | `gatsby-transformer-sharp`, 28 | { 29 | resolve: require.resolve(`@nrwl/gatsby/plugins/nx-gatsby-ext-plugin`), 30 | options: { 31 | path: __dirname 32 | } 33 | }, 34 | `gatsby-plugin-sharp`, 35 | { 36 | resolve: `gatsby-plugin-manifest`, 37 | options: { 38 | name: `<%= name %>`, 39 | short_name: `starter`, 40 | start_url: `/`, 41 | background_color: `#663399`, 42 | theme_color: `#663399`, 43 | display: `minimal-ui`, 44 | icon: `src/images/logo.png` 45 | } 46 | } 47 | ] 48 | }; 49 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/schematics/application/files/gatsby-node.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Implement Gatsby's Node APIs in this file. 3 | * 4 | * See: https://www.gatsbyjs.org/docs/node-apis/ 5 | */ 6 | 7 | // You can delete this file if you're not using it 8 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/schematics/application/files/gatsby-ssr.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Implement Gatsby's SSR (Server Side Rendering) APIs in this file. 3 | * 4 | * See: https://www.gatsbyjs.org/docs/ssr-apis/ 5 | */ 6 | 7 | // You can delete this file if you're not using it 8 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/schematics/application/files/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gatsby-starter-default", 3 | "private": true, 4 | "description": "A simple starter to get up and developing quickly with Gatsby", 5 | "version": "0.0.0", 6 | "license": "MIT", 7 | "dependencies": { 8 | "gatsby": "*" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/schematics/application/files/src/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nrwl/gatsby/5a24e8ff28fbfeaee60e9350f049fd9cf9585c25/packages/gatsby-plugin/src/schematics/application/files/src/images/logo.png -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/schematics/application/files/src/pages/404.js: -------------------------------------------------------------------------------- 1 | import React from "react" 2 | 3 | const NotFoundPage = () =>

NOT FOUND

4 | 5 | export default NotFoundPage 6 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/schematics/application/files/src/pages/index.__style__.template: -------------------------------------------------------------------------------- 1 | /* 2 | * Remove template code below 3 | */ 4 | 5 | .app { 6 | font-family: sans-serif; 7 | min-width: 300px; 8 | max-width: 600px; 9 | margin: 50px auto; 10 | } 11 | 12 | .app .gutter-left { 13 | margin-left: 9px; 14 | } 15 | 16 | .app .col-span-2 { 17 | grid-column: span 2; 18 | } 19 | 20 | .app .flex { 21 | display: flex; 22 | align-items: center; 23 | justify-content: center; 24 | } 25 | 26 | .app header { 27 | background-color: #143055; 28 | color: white; 29 | padding: 5px; 30 | border-radius: 3px; 31 | } 32 | 33 | .app main { 34 | padding: 0 36px; 35 | } 36 | 37 | .app p { 38 | text-align: center; 39 | } 40 | 41 | .app h1 { 42 | text-align: center; 43 | margin-left: 18px; 44 | font-size: 24px; 45 | } 46 | 47 | .app h2 { 48 | text-align: center; 49 | font-size: 20px; 50 | margin: 40px 0 10px 0; 51 | } 52 | 53 | .app .resources { 54 | text-align: center; 55 | list-style: none; 56 | padding: 0; 57 | display: grid; 58 | grid-gap: 9px; 59 | grid-template-columns: 1fr 1fr; 60 | } 61 | 62 | .app .resource { 63 | color: #0094ba; 64 | height: 36px; 65 | background-color: rgba(0, 0, 0, 0); 66 | border: 1px solid rgba(0, 0, 0, 0.12); 67 | border-radius: 4px; 68 | padding: 3px 9px; 69 | text-decoration: none; 70 | } 71 | 72 | .app .resource:hover { 73 | background-color: rgba(68, 138, 255, 0.04); 74 | } 75 | 76 | .app pre { 77 | padding: 9px; 78 | border-radius: 4px; 79 | background-color: black; 80 | color: #eee; 81 | } 82 | 83 | .app details { 84 | border-radius: 4px; 85 | color: #333; 86 | background-color: rgba(0, 0, 0, 0); 87 | border: 1px solid rgba(0, 0, 0, 0.12); 88 | padding: 3px 9px; 89 | margin-bottom: 9px; 90 | } 91 | 92 | .app summary { 93 | outline: none; 94 | height: 36px; 95 | line-height: 36px; 96 | } 97 | 98 | .app .github-star-container { 99 | margin-top: 12px; 100 | line-height: 20px; 101 | } 102 | 103 | .app .github-star-container a { 104 | display: flex; 105 | align-items: center; 106 | text-decoration: none; 107 | color: #333; 108 | } 109 | 110 | .app .github-star-badge { 111 | color: #24292e; 112 | display: flex; 113 | align-items: center; 114 | font-size: 12px; 115 | padding: 3px 10px; 116 | border: 1px solid rgba(27, 31, 35, 0.2); 117 | border-radius: 3px; 118 | background-image: linear-gradient(-180deg, #fafbfc, #eff3f6 90%); 119 | margin-left: 4px; 120 | font-weight: 600; 121 | } 122 | 123 | .app .github-star-badge:hover { 124 | background-image: linear-gradient(-180deg, #f0f3f6, #e6ebf1 90%); 125 | border-color: rgba(27, 31, 35, 0.35); 126 | background-position: -0.5em; 127 | } 128 | .app .github-star-badge .material-icons { 129 | height: 16px; 130 | width: 16px; 131 | margin-right: 4px; 132 | } 133 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/schematics/application/files/src/pages/index.spec.tsx.template: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render } from '@testing-library/react'; 3 | 4 | import Index from './index'; 5 | 6 | describe('Index', () => { 7 | it('should render successfully', () => { 8 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 9 | const props: any = {}; 10 | const { getByText } = render(); 11 | expect(getByText('Welcome to <%= projectName %>!')).toBeTruthy(); 12 | }); 13 | }); 14 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/schematics/application/files/src/pages/index.tsx.template: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | <% if (styledModule) { 3 | var wrapper = 'StyledApp'; 4 | %>import styled from '<%= styledModule %>';<% } else { 5 | var wrapper = 'div'; 6 | %> 7 | 8 | import './index.<%= style %>'; 9 | 10 | <% } 11 | %> 12 | 13 | import { ReactComponent as Logo } from './logo.svg'; 14 | import star from './star.svg'; 15 | 16 | <% if (styledModule) { %> 17 | const StyledApp = styled.div` 18 | /* 19 | * Remove template code below 20 | */ 21 | 22 | font-family: sans-serif; 23 | min-width: 300px; 24 | max-width: 600px; 25 | margin: 50px auto; 26 | 27 | .gutter-left { 28 | margin-left: 9px; 29 | } 30 | 31 | .col-span-2 { 32 | grid-column: span 2; 33 | } 34 | 35 | .flex { 36 | display: flex; 37 | align-items: center; 38 | justify-content: center; 39 | } 40 | 41 | header { 42 | background-color: #143055; 43 | color: white; 44 | padding: 5px; 45 | border-radius: 3px; 46 | } 47 | 48 | main { 49 | padding: 0 36px; 50 | } 51 | 52 | p { 53 | text-align: center; 54 | } 55 | 56 | h1 { 57 | text-align: center; 58 | margin-left: 18px; 59 | font-size: 24px; 60 | } 61 | 62 | h2 { 63 | text-align: center; 64 | font-size: 20px; 65 | margin: 40px 0 10px 0; 66 | } 67 | 68 | .resources { 69 | text-align: center; 70 | list-style: none; 71 | padding: 0; 72 | display: grid; 73 | grid-gap: 9px; 74 | grid-template-columns: 1fr 1fr; 75 | } 76 | 77 | .resource { 78 | color: #0094ba; 79 | height: 36px; 80 | background-color: rgba(0, 0, 0, 0); 81 | border: 1px solid rgba(0, 0, 0, 0.12); 82 | border-radius: 4px; 83 | padding: 3px 9px; 84 | text-decoration: none; 85 | } 86 | 87 | .resource:hover { 88 | background-color: rgba(68, 138, 255, 0.04); 89 | } 90 | 91 | pre { 92 | padding: 9px; 93 | border-radius: 4px; 94 | background-color: black; 95 | color: #eee; 96 | } 97 | 98 | details { 99 | border-radius: 4px; 100 | color: #333; 101 | background-color: rgba(0, 0, 0, 0); 102 | border: 1px solid rgba(0, 0, 0, 0.12); 103 | padding: 3px 9px; 104 | margin-bottom: 9px; 105 | } 106 | 107 | summary { 108 | outline: none; 109 | height: 36px; 110 | line-height: 36px; 111 | } 112 | 113 | .github-star-container { 114 | margin-top: 12px; 115 | line-height: 20px; 116 | } 117 | 118 | .github-star-container a { 119 | display: flex; 120 | align-items: center; 121 | text-decoration: none; 122 | color: #333; 123 | } 124 | 125 | .github-star-badge { 126 | color: #24292e; 127 | display: flex; 128 | align-items: center; 129 | font-size: 12px; 130 | padding: 3px 10px; 131 | border: 1px solid rgba(27,31,35,.2); 132 | border-radius: 3px; 133 | background-image: linear-gradient(-180deg,#fafbfc,#eff3f6 90%); 134 | margin-left: 4px; 135 | font-weight: 600; 136 | } 137 | 138 | .github-star-badge:hover { 139 | background-image: linear-gradient(-180deg,#f0f3f6,#e6ebf1 90%); 140 | border-color: rgba(27,31,35,.35); 141 | background-position: -.5em; 142 | } 143 | .github-star-badge .material-icons { 144 | height: 16px; 145 | width: 16px; 146 | margin-right: 4px; 147 | } 148 | `; 149 | <% }%> 150 | 151 | <% 152 | var innerJsx = ` 153 |
154 | 155 |

Welcome to ${name}!

156 |
157 |
158 |

Resources & Tools

159 |

160 | Thank you for using and showing some ♥ for Nx. 161 |

162 | 170 |

171 | Here are some links to help you get started. 172 |

173 | 211 |

Next Steps

212 |

213 | Here are some things you can do with Nx. 214 |

215 |
216 | Add UI library 217 |
{\`# Generate UI lib
218 | nx g @nrwl/react:lib ui
219 | 
220 | # Add a component
221 | nx g @nrwl/react:component xyz --project ui\`}
222 |
223 |
224 | View dependency graph 225 |
{\`nx dep-graph\`}
226 |
227 |
228 | Run affected commands 229 |
{\`# see what's been affected by changes
230 | nx affected:dep-graph
231 | 
232 | # run tests for current changes
233 | nx affected:test
234 | 
235 | # run e2e tests for current changes
236 | nx affected:e2e
237 | \`}
238 |
239 |
240 | `; 241 | %> 242 | 243 | export const Index = () => { 244 | /* 245 | * Replace the elements below with your own. 246 | * 247 | * Note: The corresponding styles are in the ./${fileName}.${style} file. 248 | */ 249 | return ( 250 | <<%= wrapper %><% if (!styledModule) {%> className="app"<% } %>> 251 | <%= innerJsx %> 252 | > 253 | ); 254 | }; 255 | 256 | export default Index; 257 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/schematics/application/files/src/pages/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/schematics/application/files/src/pages/star.svg: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/schematics/application/files/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "jsx": "react", 5 | "allowJs": true, 6 | "esModuleInterop": true, 7 | "allowSyntheticDefaultImports": true, 8 | "types": ["node", "jest"] 9 | }, 10 | "files": [ 11 | "../../node_modules/@nrwl/react/typings/cssmodule.d.ts", 12 | "../../node_modules/@nrwl/react/typings/image.d.ts" 13 | ], 14 | "include": ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"] 15 | } 16 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/schematics/application/schema.d.ts: -------------------------------------------------------------------------------- 1 | export interface GatsbyPluginSchematicSchema { 2 | name: string; 3 | tags?: string; 4 | style: string; 5 | directory?: string; 6 | unitTestRunner: 'jest' | 'none'; 7 | e2eTestRunner: 'cypress' | 'none'; 8 | js: boolean; 9 | } 10 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/schematics/application/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/schema", 3 | "id": "NxGatsbyApp", 4 | "title": "", 5 | "type": "object", 6 | "properties": { 7 | "name": { 8 | "type": "string", 9 | "description": "", 10 | "$default": { 11 | "$source": "argv", 12 | "index": 0 13 | }, 14 | "x-prompt": "What name would you like to use?" 15 | }, 16 | "tags": { 17 | "type": "string", 18 | "description": "Add tags to the project (used for linting)", 19 | "alias": "t" 20 | }, 21 | "directory": { 22 | "type": "string", 23 | "description": "A directory where the project is placed", 24 | "alias": "d" 25 | }, 26 | "unitTestRunner": { 27 | "description": "Adds the specified unit test runner", 28 | "type": "string", 29 | "enum": [ 30 | "jest", 31 | "none" 32 | ], 33 | "default": "jest" 34 | }, 35 | "e2eTestRunner": { 36 | "description": "Adds the specified e2e test runner", 37 | "type": "string", 38 | "enum": [ 39 | "cypress", 40 | "none" 41 | ], 42 | "default": "cypress" 43 | }, 44 | "style": { 45 | "description": "The file extension to be used for style files.", 46 | "type": "string", 47 | "alias": "s", 48 | "default": "css", 49 | "x-prompt": { 50 | "message": "Which stylesheet format would you like to use?", 51 | "type": "list", 52 | "items": [ 53 | { 54 | "value": "css", 55 | "label": "CSS" 56 | }, 57 | { 58 | "value": "scss", 59 | "label": "SASS(.scss) [ http://sass-lang.com ]" 60 | }, 61 | { 62 | "value": "styl", 63 | "label": "Stylus(.styl) [ http://stylus-lang.com ]" 64 | }, 65 | { 66 | "value": "less", 67 | "label": "LESS [ http://lesscss.org ]" 68 | }, 69 | { 70 | "value": "styled-components", 71 | "label": "styled-components [ https://styled-components.com ]" 72 | }, 73 | { 74 | "value": "@emotion/styled", 75 | "label": "emotion [ https://emotion.sh ]" 76 | }, 77 | { 78 | "value": "none", 79 | "label": "None" 80 | } 81 | ] 82 | } 83 | }, 84 | "js": { 85 | "type": "boolean", 86 | "description": "Generate JavaScript files rather than TypeScript files", 87 | "default": false 88 | } 89 | }, 90 | "required": [ 91 | "name" 92 | ] 93 | } -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/schematics/component/component.ts: -------------------------------------------------------------------------------- 1 | import { chain, externalSchematic, Rule } from '@angular-devkit/schematics'; 2 | import { addStyleDependencies } from '../../utils/styles'; 3 | 4 | interface Schema { 5 | name: string; 6 | project: string; 7 | style: string; 8 | directory?: string; 9 | flat?: boolean; 10 | } 11 | 12 | /* 13 | * This schematic is basically the React one, but for Next we need 14 | * extra dependencies for css, sass, less, styl style options. 15 | */ 16 | export default function (options: Schema): Rule { 17 | return chain([ 18 | externalSchematic('@nrwl/react', 'component', { 19 | ...options, 20 | directory: options.directory || 'components', 21 | pascalCaseFiles: false, 22 | export: false, 23 | classComponent: false, 24 | routing: false, 25 | flat: true, 26 | }), 27 | addStyleDependencies(options.style), 28 | ]); 29 | } 30 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/schematics/component/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/schema", 3 | "id": "NxReactApp", 4 | "title": "Create a React Component for Gatsby", 5 | "type": "object", 6 | "examples": [ 7 | { 8 | "command": "g component my-component --project=mylib", 9 | "description": "Generate a component in the mylib library" 10 | }, 11 | { 12 | "command": "g component my-component --project=mylib --classComponent", 13 | "description": "Generate a class component in the mylib library" 14 | } 15 | ], 16 | "properties": { 17 | "project": { 18 | "type": "string", 19 | "description": "The name of the project.", 20 | "alias": "p", 21 | "$default": { 22 | "$source": "projectName" 23 | }, 24 | "x-prompt": "What is the name of the project for this component?" 25 | }, 26 | "name": { 27 | "type": "string", 28 | "description": "The name of the component.", 29 | "$default": { 30 | "$source": "argv", 31 | "index": 0 32 | }, 33 | "x-prompt": "What name would you like to use for the component?" 34 | }, 35 | "style": { 36 | "description": "The file extension to be used for style files.", 37 | "type": "string", 38 | "alias": "s", 39 | "default": "css", 40 | "x-prompt": { 41 | "message": "Which stylesheet format would you like to use?", 42 | "type": "list", 43 | "items": [ 44 | { 45 | "value": "css", 46 | "label": "CSS" 47 | }, 48 | { 49 | "value": "scss", 50 | "label": "SASS(.scss) [ http://sass-lang.com ]" 51 | }, 52 | { 53 | "value": "styl", 54 | "label": "Stylus(.styl) [ http://stylus-lang.com ]" 55 | }, 56 | { 57 | "value": "less", 58 | "label": "LESS [ http://lesscss.org ]" 59 | }, 60 | { 61 | "value": "styled-components", 62 | "label": "styled-components [ https://styled-components.com ]" 63 | }, 64 | { 65 | "value": "@emotion/styled", 66 | "label": "emotion [ https://emotion.sh ]" 67 | }, 68 | { 69 | "value": "none", 70 | "label": "None" 71 | } 72 | ] 73 | } 74 | }, 75 | "skipTests": { 76 | "type": "boolean", 77 | "description": "When true, does not create \"spec.ts\" test files for the new component.", 78 | "default": false 79 | }, 80 | "directory": { 81 | "type": "string", 82 | "description": "Create the component under this directory (can be nested).", 83 | "alias": "d" 84 | }, 85 | "export": { 86 | "type": "boolean", 87 | "description": "When true, the component is exported from the project index.ts (if it exists).", 88 | "alias": "e", 89 | "default": false 90 | }, 91 | "js": { 92 | "type": "boolean", 93 | "description": "Generate JavaScript files rather than TypeScript files.", 94 | "default": false 95 | }, 96 | "flat": { 97 | "type": "boolean", 98 | "description": "Create component at the source root rather than its own directory.", 99 | "default": false 100 | } 101 | }, 102 | "required": [ 103 | "name", 104 | "project" 105 | ] 106 | } -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/schematics/init/init.ts: -------------------------------------------------------------------------------- 1 | import { JsonObject } from '@angular-devkit/core'; 2 | import { chain, noop, Rule } from '@angular-devkit/schematics'; 3 | import { 4 | addDepsToPackageJson, 5 | addPackageWithInit, 6 | updateWorkspace, 7 | } from '@nrwl/workspace'; 8 | import { setDefaultCollection } from '@nrwl/workspace/src/utils/rules/workspace'; 9 | import { 10 | babelPluginModuleResolverVersion, 11 | babelPresetGatsbyVersion, 12 | gatsbyImageVersion, 13 | gatsbyPluginManifestVersion, 14 | gatsbyPluginOfflineVersion, 15 | gatsbyPluginReactHelmetVersion, 16 | gatsbyPluginSharpVersion, 17 | gatsbyPluginSvgrVersion, 18 | gatsbyPluginTypescriptVersion, 19 | gatsbySourceFilesystemVersion, 20 | gatsbyTransformerSharpVersion, 21 | gatsbyVersion, 22 | nxVersion, 23 | propTypesVersion, 24 | reactDomVersion, 25 | reactHelmetVersion, 26 | reactVersion, 27 | testingLibraryReactVersion, 28 | } from '../../utils/versions'; 29 | import { Schema } from './schema'; 30 | 31 | function jsonIdentity(x: any): JsonObject { 32 | return x as JsonObject; 33 | } 34 | 35 | function setDefault(): Rule { 36 | const updateProjectWorkspace = updateWorkspace((workspace) => { 37 | workspace.extensions.schematics = 38 | jsonIdentity(workspace.extensions.schematics) || {}; 39 | 40 | const gatsbySchematics = 41 | jsonIdentity(workspace.extensions.schematics['@nrwl/gatsby']) || {}; 42 | 43 | workspace.extensions.schematics = { 44 | ...workspace.extensions.schematics, 45 | '@nrwl/gatsby': { 46 | application: { 47 | ...jsonIdentity(gatsbySchematics.application), 48 | }, 49 | }, 50 | }; 51 | }); 52 | return chain([setDefaultCollection('@nrwl/gatsby'), updateProjectWorkspace]); 53 | } 54 | 55 | export default function (schema: Schema) { 56 | return chain([ 57 | setDefault(), 58 | schema.unitTestRunner === 'jest' 59 | ? addPackageWithInit('@nrwl/jest') 60 | : noop(), 61 | schema.e2eTestRunner === 'cypress' 62 | ? addPackageWithInit('@nrwl/cypress') 63 | : noop(), 64 | addDepsToPackageJson( 65 | { 66 | gatsby: gatsbyVersion, 67 | 'gatsby-image': gatsbyImageVersion, 68 | 'gatsby-plugin-svgr': gatsbyPluginSvgrVersion, 69 | 'gatsby-plugin-manifest': gatsbyPluginManifestVersion, 70 | 'gatsby-plugin-offline': gatsbyPluginOfflineVersion, 71 | 'gatsby-plugin-react-helmet': gatsbyPluginReactHelmetVersion, 72 | 'gatsby-plugin-sharp': gatsbyPluginSharpVersion, 73 | 'gatsby-source-filesystem': gatsbySourceFilesystemVersion, 74 | 'gatsby-transformer-sharp': gatsbyTransformerSharpVersion, 75 | 'prop-types': propTypesVersion, 76 | react: reactVersion, 77 | 'react-dom': reactDomVersion, 78 | 'react-helmet': reactHelmetVersion, 79 | 'gatsby-plugin-typescript': gatsbyPluginTypescriptVersion, 80 | }, 81 | { 82 | '@nrwl/react': nxVersion, 83 | '@testing-library/react': testingLibraryReactVersion, 84 | 'babel-plugin-module-resolver': babelPluginModuleResolverVersion, 85 | 'babel-preset-gatsby': babelPresetGatsbyVersion, 86 | } 87 | ), 88 | ]); 89 | } 90 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/schematics/init/schema.d.ts: -------------------------------------------------------------------------------- 1 | export interface Schema { 2 | unitTestRunner: 'jest' | 'none'; 3 | e2eTestRunner: 'cypress' | 'none'; 4 | skipFormat: boolean; 5 | } 6 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/schematics/init/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/schema", 3 | "id": "NxGatsbyInit", 4 | "title": "Add Nx Gatsby Schematics", 5 | "type": "object", 6 | "properties": { 7 | "unitTestRunner": { 8 | "description": "Adds the specified unit test runner", 9 | "type": "string", 10 | "enum": [ 11 | "jest", 12 | "none" 13 | ], 14 | "default": "jest" 15 | }, 16 | "e2eTestRunner": { 17 | "description": "Adds the specified e2e test runner", 18 | "type": "string", 19 | "enum": [ 20 | "cypress", 21 | "none" 22 | ], 23 | "default": "cypress" 24 | }, 25 | "skipFormat": { 26 | "description": "Skip formatting files", 27 | "type": "boolean", 28 | "default": false 29 | } 30 | }, 31 | "required": [] 32 | } -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/schematics/page/page.ts: -------------------------------------------------------------------------------- 1 | import { chain, externalSchematic, Rule } from '@angular-devkit/schematics'; 2 | import { addStyleDependencies } from '../../utils/styles'; 3 | 4 | interface Schema { 5 | name: string; 6 | project: string; 7 | style: string; 8 | directory?: string; 9 | flat?: boolean; 10 | } 11 | 12 | /* 13 | * This schematic is basically the React one, but for Gatsby we need 14 | * extra dependencies for css, sass, less, styl style options. 15 | */ 16 | export default function(options: Schema): Rule { 17 | return chain([ 18 | externalSchematic('@nrwl/react', 'component', { 19 | ...options, 20 | directory: options.directory || 'pages', 21 | pascalCaseFiles: false, 22 | export: false, 23 | classComponent: false, 24 | routing: false, 25 | flat: true 26 | }), 27 | addStyleDependencies(options.style) 28 | ]); 29 | } 30 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/schematics/page/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/schema", 3 | "id": "NxReactApp", 4 | "title": "Create a React Page for Gatsby", 5 | "type": "object", 6 | "examples": [ 7 | { 8 | "command": "g page my-page --project=mylib", 9 | "description": "Generate a page in the mylib library" 10 | }, 11 | { 12 | "command": "g page my-page --project=mylib --classComponent", 13 | "description": "Generate a class component in the mylib library" 14 | } 15 | ], 16 | "properties": { 17 | "project": { 18 | "type": "string", 19 | "description": "The name of the project.", 20 | "alias": "p", 21 | "$default": { 22 | "$source": "projectName" 23 | }, 24 | "x-prompt": "What is the name of the project for this component?" 25 | }, 26 | "name": { 27 | "type": "string", 28 | "description": "The name of the component.", 29 | "$default": { 30 | "$source": "argv", 31 | "index": 0 32 | }, 33 | "x-prompt": "What name would you like to use for the component?" 34 | }, 35 | "style": { 36 | "description": "The file extension to be used for style files.", 37 | "type": "string", 38 | "alias": "s", 39 | "default": "css", 40 | "x-prompt": { 41 | "message": "Which stylesheet format would you like to use?", 42 | "type": "list", 43 | "items": [ 44 | { 45 | "value": "css", 46 | "label": "CSS" 47 | }, 48 | { 49 | "value": "scss", 50 | "label": "SASS(.scss) [ http://sass-lang.com ]" 51 | }, 52 | { 53 | "value": "styl", 54 | "label": "Stylus(.styl) [ http://stylus-lang.com ]" 55 | }, 56 | { 57 | "value": "less", 58 | "label": "LESS [ http://lesscss.org ]" 59 | }, 60 | { 61 | "value": "styled-components", 62 | "label": "styled-components [ https://styled-components.com ]" 63 | }, 64 | { 65 | "value": "@emotion/styled", 66 | "label": "emotion [ https://emotion.sh ]" 67 | }, 68 | { 69 | "value": "none", 70 | "label": "None" 71 | } 72 | ] 73 | } 74 | }, 75 | "skipTests": { 76 | "type": "boolean", 77 | "description": "When true, does not create \"spec.ts\" test files for the new component.", 78 | "default": false 79 | }, 80 | "directory": { 81 | "type": "string", 82 | "description": "Create the component under this directory (can be nested).", 83 | "alias": "d" 84 | }, 85 | "export": { 86 | "type": "boolean", 87 | "description": "When true, the component is exported from the project index.ts (if it exists).", 88 | "alias": "e", 89 | "default": false 90 | }, 91 | "js": { 92 | "type": "boolean", 93 | "description": "Generate JavaScript files rather than TypeScript files.", 94 | "default": false 95 | }, 96 | "flat": { 97 | "type": "boolean", 98 | "description": "Create component at the source root rather than its own directory.", 99 | "default": false 100 | } 101 | }, 102 | "required": [ 103 | "name", 104 | "project" 105 | ] 106 | } -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/utils/get-project-root.ts: -------------------------------------------------------------------------------- 1 | import { BuilderContext } from '@angular-devkit/architect'; 2 | 3 | export async function getProjectRoot(context: BuilderContext): Promise { 4 | const projectMeta = await context.getProjectMetadata(context.target.project); 5 | if (projectMeta.root) { 6 | return projectMeta.root as string; 7 | } else { 8 | context.reportStatus('Error'); 9 | const message = `${context.target.project} does not have a sourceRoot. Please define one.`; 10 | context.logger.error(message); 11 | throw new Error(message); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/utils/styles.ts: -------------------------------------------------------------------------------- 1 | import { noop, Rule } from '@angular-devkit/schematics'; 2 | import { addDepsToPackageJson } from '@nrwl/workspace'; 3 | import { CSS_IN_JS_DEPENDENCIES } from '@nrwl/react'; 4 | import { 5 | gatsbyPluginStyledComponentsVersion, 6 | gatsbyPluginEmotionVersion, 7 | gatsbyPluginLessVersion, 8 | nodeSassVersion, 9 | gatsbyPluginSassVersion, 10 | gatsbyPluginStylusVersion, 11 | } from './versions'; 12 | 13 | export const NEXT_SPECIFIC_STYLE_DEPENDENCIES = { 14 | 'styled-components': { 15 | dependencies: CSS_IN_JS_DEPENDENCIES['styled-components'].dependencies, 16 | devDependencies: { 17 | 'gatsby-plugin-styled-components': gatsbyPluginStyledComponentsVersion, 18 | }, 19 | }, 20 | '@emotion/styled': { 21 | dependencies: CSS_IN_JS_DEPENDENCIES['@emotion/styled'].dependencies, 22 | devDependencies: { 23 | 'gatsby-plugin-emotion': gatsbyPluginEmotionVersion, 24 | }, 25 | }, 26 | scss: { 27 | dependencies: {}, 28 | devDependencies: { 29 | 'node-sass': nodeSassVersion, 30 | 'gatsby-plugin-sass': gatsbyPluginSassVersion, 31 | }, 32 | }, 33 | less: { 34 | dependencies: {}, 35 | devDependencies: { 36 | 'gatsby-plugin-less': gatsbyPluginLessVersion, 37 | }, 38 | }, 39 | styl: { 40 | dependencies: {}, 41 | devDependencies: { 42 | 'gatsby-plugin-stylus': gatsbyPluginStylusVersion, 43 | }, 44 | }, 45 | }; 46 | 47 | export function addStyleDependencies(style: string): Rule { 48 | const extraDependencies = NEXT_SPECIFIC_STYLE_DEPENDENCIES[style]; 49 | return extraDependencies 50 | ? addDepsToPackageJson( 51 | extraDependencies.dependencies, 52 | extraDependencies.devDependencies 53 | ) 54 | : noop(); 55 | } 56 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/src/utils/versions.ts: -------------------------------------------------------------------------------- 1 | export const nxVersion = '10.4.4'; 2 | 3 | export const gatsbyVersion = '2.27.4'; 4 | export const gatsbyImageVersion = '2.6.0'; 5 | export const gatsbyPluginManifestVersion = '2.6.1'; 6 | export const gatsbyPluginOfflineVersion = '3.4.0'; 7 | export const gatsbyPluginReactHelmetVersion = '3.4.0'; 8 | export const gatsbyPluginSharpVersion = '2.8.0'; 9 | export const gatsbySourceFilesystemVersion = '2.5.0'; 10 | export const gatsbyTransformerSharpVersion = '2.6.0'; 11 | export const propTypesVersion = '15.7.2'; 12 | export const reactVersion = '17.0.1'; 13 | export const reactDomVersion = '17.0.1'; 14 | export const reactHelmetVersion = '6.1.0'; 15 | export const gatsbyPluginTypescriptVersion = '2.7.0'; 16 | export const babelPluginModuleResolverVersion = '4.0.0'; 17 | export const babelPresetGatsbyVersion = '0.7.0'; 18 | export const testingLibraryReactVersion = '11.2.2'; 19 | export const gatsbyPluginEmotionVersion = '4.5.0'; 20 | export const gatsbyPluginStyledComponentsVersion = '3.5.0'; 21 | export const gatsbyPluginSassVersion = '2.6.0'; 22 | export const gatsbyPluginLessVersion = '4.2.0'; 23 | export const gatsbyPluginStylusVersion = '2.5.0'; 24 | export const nodeSassVersion = '4.14.1'; 25 | export const gatsbyPluginSvgrVersion = '2.0.2'; 26 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "types": ["node", "jest"] 5 | }, 6 | "include": [], 7 | "files": [], 8 | "references": [ 9 | { 10 | "path": "./tsconfig.lib.json" 11 | }, 12 | { 13 | "path": "./tsconfig.spec.json" 14 | } 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/tsconfig.lib.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "module": "commonjs", 5 | "outDir": "../../dist/out-tsc", 6 | "declaration": true, 7 | "types": ["node"] 8 | }, 9 | "exclude": ["**/*.spec.ts"], 10 | "include": ["**/*.ts"] 11 | } 12 | -------------------------------------------------------------------------------- /packages/gatsby-plugin/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../../dist/out-tsc", 5 | "module": "commonjs", 6 | "types": ["jest", "node"] 7 | }, 8 | "include": [ 9 | "**/*.spec.ts", 10 | "**/*.spec.tsx", 11 | "**/*.spec.js", 12 | "**/*.spec.jsx", 13 | "**/*.d.ts" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /tools/generators/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nrwl/gatsby/5a24e8ff28fbfeaee60e9350f049fd9cf9585c25/tools/generators/.gitkeep -------------------------------------------------------------------------------- /tools/scripts/publish.js: -------------------------------------------------------------------------------- 1 | const { execSync } = require('child_process'); 2 | 3 | const { readFileSync, writeFileSync, existsSync } = require('fs'); 4 | 5 | const { join } = require('path'); 6 | 7 | function publish(dir, tag) { 8 | execSync(`npm publish ${dir} --access public --tag ${tag}`); 9 | } 10 | 11 | function updatePackageJson(packageJsonPath, version) { 12 | const packageJson = JSON.parse(readFileSync(packageJsonPath).toString()); 13 | packageJson.version = version; 14 | writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2)); 15 | } 16 | 17 | function getProject(project) { 18 | const workspaceJson = JSON.parse(readFileSync('workspace.json').toString()); 19 | return workspaceJson.projects[project]; 20 | } 21 | 22 | const [_, _2, project] = process.argv; 23 | const version = process.env.VERSION 24 | const tag = process.env.TAG || 'next' 25 | 26 | if (!project) { 27 | throw new Error('Need the project'); 28 | } 29 | if (!version) { 30 | throw new Error('Need the version'); 31 | } 32 | const projectMeta = getProject(project); 33 | const outputPath = projectMeta.architect.build.options.outputPath; 34 | if (!existsSync(outputPath)) { 35 | throw new Error('Must build the project first'); 36 | } 37 | 38 | const root = projectMeta.root; 39 | updatePackageJson(join(root, 'package.json'), version); 40 | updatePackageJson(join(outputPath, 'package.json'), version); 41 | publish(outputPath, tag); 42 | -------------------------------------------------------------------------------- /tools/scripts/publish.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | VERSION=$1 4 | TAG=$2 5 | LOCAL=$3 6 | 7 | NPM_REGISTRY=`npm config get registry` 8 | 9 | if [ "$TAG" = "--local" ]; then 10 | TAG="next" 11 | LOCAL="--local" 12 | fi 13 | 14 | echo "Publishing to registry:" 15 | 16 | echo $NPM_REGISTRY 17 | 18 | if [ "$LOCAL" = "--local" ]; then 19 | if [[ ! $NPM_REGISTRY == http://localhost* ]]; then 20 | echo "------------------" 21 | echo "💣 WARNING 💣 => $NPM_REGISTRY does not look like a local registry!" 22 | echo "You may want to set registry with 'npm config set registry ...'" 23 | echo "------------------" 24 | exit 1 25 | fi 26 | fi 27 | 28 | read -p "Continue? (y/n)" -n 1 -r 29 | echo 30 | if [[ ! $REPLY =~ ^[Yy]$ ]]; then 31 | [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell 32 | fi 33 | 34 | if [ "$LOCAL" = "--local" ]; then 35 | echo "Local Publish: Skipping Login" 36 | else 37 | echo "Logging into npm" 38 | npm login 39 | fi 40 | 41 | export VERSION=$VERSION 42 | export TAG=$TAG 43 | 44 | nx run-many --target publish --all --parallel 45 | 46 | if [ "$LOCAL" = "--local" ]; then 47 | echo "Published Locally" 48 | else 49 | echo "Published to npm" 50 | npm logout 51 | echo "Logged out of npm" 52 | fi 53 | -------------------------------------------------------------------------------- /tools/tsconfig.tools.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.base.json", 3 | "compilerOptions": { 4 | "outDir": "../dist/out-tsc/tools", 5 | "rootDir": ".", 6 | "module": "commonjs", 7 | "target": "es5", 8 | "types": ["node"] 9 | }, 10 | "include": ["**/*.ts"] 11 | } 12 | -------------------------------------------------------------------------------- /tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "rootDir": ".", 5 | "sourceMap": true, 6 | "declaration": false, 7 | "moduleResolution": "node", 8 | "emitDecoratorMetadata": true, 9 | "experimentalDecorators": true, 10 | "importHelpers": true, 11 | "target": "es2015", 12 | "module": "esnext", 13 | "typeRoots": ["node_modules/@types"], 14 | "lib": ["es2017", "dom"], 15 | "skipLibCheck": true, 16 | "skipDefaultLibCheck": true, 17 | "baseUrl": ".", 18 | "paths": { 19 | "@nrwl/gatsby-plugin": ["packages/gatsby-plugin/src/index.ts"] 20 | } 21 | }, 22 | "exclude": ["node_modules", "tmp"] 23 | } 24 | -------------------------------------------------------------------------------- /workspace.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "projects": { 4 | "gatsby-plugin": { 5 | "root": "packages/gatsby-plugin", 6 | "sourceRoot": "packages/gatsby-plugin/src", 7 | "projectType": "library", 8 | "schematics": {}, 9 | "architect": { 10 | "lint": { 11 | "builder": "@nrwl/linter:eslint", 12 | "options": { 13 | "lintFilePatterns": [ 14 | "packages/gatsby-plugin/**/*.ts", 15 | "packages/gatsby-plugin/**/*.spec.ts", 16 | "packages/gatsby-plugin/**/*.spec.tsx", 17 | "packages/gatsby-plugin/**/*.spec.js", 18 | "packages/gatsby-plugin/**/*.spec.jsx", 19 | "packages/gatsby-plugin/**/*.d.ts" 20 | ] 21 | } 22 | }, 23 | "test": { 24 | "builder": "@nrwl/jest:jest", 25 | "options": { 26 | "jestConfig": "packages/gatsby-plugin/jest.config.js", 27 | "passWithNoTests": true, 28 | "tsConfig": "packages/gatsby-plugin/tsconfig.spec.json" 29 | }, 30 | "outputs": [ 31 | "coverage/packages/gatsby-plugin" 32 | ] 33 | }, 34 | "build": { 35 | "builder": "@nrwl/node:package", 36 | "options": { 37 | "outputPath": "dist/packages/gatsby-plugin", 38 | "tsConfig": "packages/gatsby-plugin/tsconfig.lib.json", 39 | "packageJson": "packages/gatsby-plugin/package.json", 40 | "main": "packages/gatsby-plugin/src/index.ts", 41 | "assets": [ 42 | "packages/gatsby-plugin/README.md", 43 | "packages/gatsby-plugin/LICENSE", 44 | { 45 | "input": "./packages/gatsby-plugin/src", 46 | "glob": "**/.babelrc*", 47 | "output": "./src" 48 | }, 49 | { 50 | "input": "./packages/gatsby-plugin/src", 51 | "glob": "**/*.!(ts)", 52 | "output": "./src" 53 | }, 54 | { 55 | "input": "./packages/gatsby-plugin/plugins", 56 | "glob": "**/*.!(ts)", 57 | "output": "./plugins" 58 | }, 59 | { 60 | "input": "./packages/gatsby-plugin", 61 | "glob": "collection.json", 62 | "output": "." 63 | }, 64 | { 65 | "input": "./packages/gatsby-plugin", 66 | "glob": "builders.json", 67 | "output": "." 68 | } 69 | ], 70 | "srcRootForCompilationRoot": "packages/gatsby-plugin" 71 | }, 72 | "outputs": [ 73 | "{options.outputPath}" 74 | ] 75 | }, 76 | "publish": { 77 | "builder": "@nrwl/workspace:run-commands", 78 | "options": { 79 | "command": "node tools/scripts/publish.js gatsby-plugin" 80 | } 81 | } 82 | } 83 | }, 84 | "gatsby-plugin-e2e": { 85 | "projectType": "application", 86 | "root": "packages/gatsby-plugin-e2e", 87 | "sourceRoot": "packages/gatsby-plugin-e2e/src", 88 | "architect": { 89 | "e2e": { 90 | "builder": "@nrwl/nx-plugin:e2e", 91 | "options": { 92 | "target": "gatsby-plugin:build", 93 | "npmPackageName": "@nrwl/gatsby", 94 | "pluginOutputPath": "dist/packages/gatsby-plugin", 95 | "jestConfig": "packages/gatsby-plugin-e2e/jest.config.js" 96 | } 97 | } 98 | } 99 | } 100 | }, 101 | "cli": { 102 | "defaultCollection": "@nrwl/workspace" 103 | }, 104 | "schematics": { 105 | "@nrwl/workspace": { 106 | "library": { 107 | "linter": "eslint" 108 | } 109 | }, 110 | "@nrwl/cypress": { 111 | "cypress-project": { 112 | "linter": "eslint" 113 | } 114 | }, 115 | "@nrwl/react": { 116 | "application": { 117 | "linter": "eslint" 118 | }, 119 | "library": { 120 | "linter": "eslint" 121 | } 122 | }, 123 | "@nrwl/next": { 124 | "application": { 125 | "linter": "eslint" 126 | } 127 | }, 128 | "@nrwl/web": { 129 | "application": { 130 | "linter": "eslint" 131 | } 132 | }, 133 | "@nrwl/node": { 134 | "application": { 135 | "linter": "eslint" 136 | }, 137 | "library": { 138 | "linter": "eslint" 139 | } 140 | }, 141 | "@nrwl/nx-plugin": { 142 | "plugin": { 143 | "linter": "eslint" 144 | } 145 | }, 146 | "@nrwl/nest": { 147 | "application": { 148 | "linter": "eslint" 149 | } 150 | }, 151 | "@nrwl/express": { 152 | "application": { 153 | "linter": "eslint" 154 | } 155 | } 156 | } 157 | } 158 | --------------------------------------------------------------------------------