Skip to content

Commit

Permalink
Revert "[All frameworks] Execute correct detection of disconnected or…
Browse files Browse the repository at this point in the history
… connected mode (#732)"

This reverts commit 23bb5ec.
  • Loading branch information
illiakovalenko committed Jul 6, 2021
1 parent a731e3b commit 450a032
Show file tree
Hide file tree
Showing 18 changed files with 37 additions and 48 deletions.
1 change: 0 additions & 1 deletion packages/sitecore-jss-angular/src/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export { JssModule } from './lib.module';
export {
dataApi,
mediaApi,
constants,
isExperienceEditorActive,
resetExperienceEditorChromes,
LayoutServiceData,
Expand Down
2 changes: 2 additions & 0 deletions packages/sitecore-jss-nextjs/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const JSS_MODE_CONNECTED = 'connected';
export const JSS_MODE_DISCONNECTED = 'disconnected';
3 changes: 2 additions & 1 deletion packages/sitecore-jss-nextjs/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export {
dataApi,
mediaApi,
constants,
// generic data access
HttpDataFetcher,
HttpResponse,
Expand Down Expand Up @@ -42,6 +41,8 @@ export {

export { ManifestInstance } from '@sitecore-jss/sitecore-jss-manifest';

export * from './constants';

export {
ComponentPropsCollection,
GetStaticComponentProps,
Expand Down
1 change: 0 additions & 1 deletion packages/sitecore-jss-react/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export {
dataApi,
mediaApi,
constants,
isExperienceEditorActive,
resetExperienceEditorChromes,
DictionaryPhrases,
Expand Down
1 change: 0 additions & 1 deletion packages/sitecore-jss-vue/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export {
dataApi,
mediaApi,
constants,
isExperienceEditorActive,
resetExperienceEditorChromes,
LayoutServiceData,
Expand Down
5 changes: 0 additions & 5 deletions packages/sitecore-jss/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,3 @@ export enum SitecoreTemplateId {
// /sitecore/templates/System/Dictionary/Dictionary entry
DictionaryEntry = '6d1cd89719364a3aa511289a94c2a7b1',
}

export const JSS_MODE = {
CONNECTED: 'connected',
DISCONNECTED: 'disconnected',
};
9 changes: 5 additions & 4 deletions samples/angular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,18 @@
"lint": "ng lint JssAngularWeb && npm run lint:yml",
"e2e": "ng e2e",
"jss": "jss",
"start": "cross-env-shell JSS_MODE=disconnected \"npm-run-all --serial bootstrap --parallel start:angular start:proxy start:watch-components\"",
"start:connected": "scjss-verify-setup && npm-run-all --serial bootstrap start:angular start:watch-components",
"build": "npm-run-all --serial bootstrap --serial build:client build:server",
"start": "npm-run-all --serial bootstrap:disconnected --parallel start:angular start:proxy start:watch-components",
"start:connected": "scjss-verify-setup && npm-run-all --serial bootstrap:connected start:angular start:watch-components",
"build": "npm-run-all --serial bootstrap:connected --serial build:client build:server",
"scaffold": "ng generate @sitecore-jss/sitecore-jss-angular-schematics:jss-component",
"start:angular": "ng serve -o",
"start:proxy": "ts-node --project src/tsconfig.webpack-server.json scripts/disconnected-mode-proxy.ts",
"start:watch-components": "ts-node --project src/tsconfig.webpack-server.json scripts/generate-component-factory.ts --watch",
"build:client": "cross-env-shell ng build --prod --deploy-url $npm_package_config_sitecoreDistPath/browser/ --output-path=$npm_package_config_buildArtifactsPath/browser/",
"build:server": "cross-env-shell ng run JssAngularWeb:server:production --output-path=$npm_package_config_buildArtifactsPath/server --output-hashing=none --bundle-dependencies true",
"postbuild:server": "move-cli ./dist/server/main.js ./dist/server.bundle.js && del-cli ./dist/server",
"bootstrap": "ts-node --project src/tsconfig.webpack-server.json scripts/bootstrap.ts",
"bootstrap:connected": "ts-node --project src/tsconfig.webpack-server.json scripts/bootstrap.ts",
"bootstrap:disconnected": "ts-node --project src/tsconfig.webpack-server.json scripts/bootstrap.ts --disconnected",
"graphql:update": "ts-node --project src/tsconfig.webpack-server.json ./scripts/update-graphql-fragment-data.ts"
},
"private": true,
Expand Down
5 changes: 2 additions & 3 deletions samples/angular/proxy.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
See /scripts/disconnected-mode-proxy.ts for the proxy API server configuration.
*/
const { constants } = require('@sitecore-jss/sitecore-jss-angular');

const port = 3043;

const PROXY_CONFIG = process.env.JSS_MODE === constants.JSS_MODE.DISCONNECTED ? [
const PROXY_CONFIG = [
{
context: ['/data', '/sitecore'],
target: `http://localhost:${port}`,
secure: false,
},
] : undefined;
];

module.exports = PROXY_CONFIG;
4 changes: 2 additions & 2 deletions samples/angular/scripts/bootstrap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { constants } from '@sitecore-jss/sitecore-jss-angular';

import { generateConfig } from './generate-config';
const projects = require('../angular.json').projects;

Expand All @@ -9,7 +9,7 @@ const projects = require('../angular.json').projects;
and the global config module.
*/

const disconnected = process.env.JSS_MODE === constants.JSS_MODE.DISCONNECTED;
const disconnected = process.argv.some((arg) => arg === '--disconnected');

/*
CONFIG GENERATION
Expand Down
4 changes: 2 additions & 2 deletions samples/nextjs/next.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const jssConfig = require('./src/temp/config');
const packageConfig = require('./package.json').config;
const { constants, getPublicUrl } = require('@sitecore-jss/sitecore-jss-nextjs');
const { JSS_MODE_DISCONNECTED } = require('@sitecore-jss/sitecore-jss-nextjs');

const disconnectedServerUrl = `http://localhost:${process.env.PROXY_PORT || 3042}/`;
const isDisconnected = process.env.JSS_MODE === constants.JSS_MODE.DISCONNECTED;
const isDisconnected = process.env.JSS_MODE === JSS_MODE_DISCONNECTED;

// A public URL (and uses below) is required for Sitecore Experience Editor support.
// This is set to http://localhost:3000 by default. See .env for more details.
Expand Down
4 changes: 2 additions & 2 deletions samples/nextjs/scripts/bootstrap.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { generateConfig } from './generate-config';
import { constants } from '@sitecore-jss/sitecore-jss-nextjs';
import { JSS_MODE_DISCONNECTED } from '@sitecore-jss/sitecore-jss-nextjs';

/*
BOOTSTRAPPING
Expand All @@ -8,7 +8,7 @@ import { constants } from '@sitecore-jss/sitecore-jss-nextjs';
and the global config module.
*/

const disconnected = process.env.JSS_MODE === constants.JSS_MODE.DISCONNECTED;
const disconnected = process.env.JSS_MODE === JSS_MODE_DISCONNECTED;

/*
CONFIG GENERATION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
GetServerSideComponentProps,
GetStaticComponentProps,
useComponentProps,
constants,
JSS_MODE_DISCONNECTED,
GraphQLRequestClient,
} from '@sitecore-jss/sitecore-jss-nextjs';
import NextLink from 'next/link';
Expand Down Expand Up @@ -100,7 +100,7 @@ const GraphQLConnectedDemo = (props: StyleguideComponentProps): JSX.Element => {
* @param {GetStaticPropsContext} context
*/
export const getStaticProps: GetStaticComponentProps = async (rendering, layoutData) => {
if (process.env.JSS_MODE === constants.JSS_MODE.DISCONNECTED) {
if (process.env.JSS_MODE === JSS_MODE_DISCONNECTED) {
return null;
}

Expand All @@ -124,7 +124,7 @@ export const getStaticProps: GetStaticComponentProps = async (rendering, layoutD
* @param {GetServerSidePropsContext} context
*/
export const getServerSideProps: GetServerSideComponentProps = async (rendering, layoutData) => {
if (process.env.JSS_MODE === constants.JSS_MODE.DISCONNECTED) {
if (process.env.JSS_MODE === JSS_MODE_DISCONNECTED) {
return null;
}

Expand Down
15 changes: 8 additions & 7 deletions samples/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@
},
"scripts": {
"jss": "jss",
"start": "cross-env-shell JSS_MODE=disconnected \"npm-run-all --serial bootstrap --parallel start:react start:proxy start:watch-components\"",
"start:connected": "scjss-verify-setup && npm-run-all --serial bootstrap start:react start:watch-components",
"start:connected-ssr": "scjss-verify-setup && npm-run-all --serial bootstrap --parallel start:react start:watch-components start:http-renderer-holygrail",
"start:holygrail": "scjss-verify-setup && npm-run-all --serial bootstrap --parallel start:watch-components start:http-renderer-holygrail",
"start": "npm-run-all --serial bootstrap:disconnected --parallel start:react start:proxy start:watch-components",
"start:connected": "scjss-verify-setup && npm-run-all --serial bootstrap:connected start:react start:watch-components",
"start:connected-ssr": "scjss-verify-setup && npm-run-all --serial bootstrap:connected --parallel start:react start:watch-components start:http-renderer-holygrail",
"start:holygrail": "scjss-verify-setup && npm-run-all --serial bootstrap:connected --parallel start:watch-components start:http-renderer-holygrail",
"start:http-renderer-holygrail": "cross-env-shell NODE_ENV=development JSS_RENDER_ENGINE=http \"node scripts/holygrail.js\"",
"start:rendering-host": "cross-env-shell NODE_ENV=development JSS_RENDER_ENGINE=http \"node scripts/http-renderer.js\"",
"build": "npm-run-all --serial bootstrap build:client build:server",
"build:rendering-host": "npm-run-all --serial bootstrap build:client:rendering-host build:server afterbuild:rendering-host",
"build": "npm-run-all --serial bootstrap:connected build:client build:server",
"build:rendering-host": "npm-run-all --serial bootstrap:connected build:client:rendering-host build:server afterbuild:rendering-host",
"afterbuild:rendering-host": "del-cli build-rendering-host && move-cli build build-rendering-host",
"scaffold": "node scripts/scaffold-component.js",
"start:react": "react-scripts start",
Expand All @@ -110,7 +110,8 @@
"build:client": "cross-env-shell PUBLIC_URL=$npm_package_config_sitecoreDistPath \"react-scripts build\"",
"build:client:rendering-host": "cross-env-shell PUBLIC_URL=$npm_package_config_tunnelUrl \"react-scripts build\"",
"build:server": "cross-env-shell NODE_ENV=production \"webpack --config server/server.webpack.config.js\"",
"bootstrap": "node scripts/bootstrap.js",
"bootstrap:connected": "node scripts/bootstrap.js",
"bootstrap:disconnected": "node scripts/bootstrap.js --disconnected",
"graphql:update": "node -r babel-register ./scripts/update-graphql-fragment-data.js",
"test": "react-scripts test --env=jsdom",
"lint": "eslint ./src/**/*.js ./sitecore/definitions/**/*.js ./scripts/**/*.js ./server/**/*.js ./data/**/*.yml",
Expand Down
3 changes: 1 addition & 2 deletions samples/react/scripts/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const { constants } = require('@sitecore-jss/sitecore-jss-react');
const configGenerator = require('./generate-config');

/*
Expand All @@ -8,7 +7,7 @@ const configGenerator = require('./generate-config');
and the global config module.
*/

const disconnected = process.env.JSS_MODE === constants.JSS_MODE.DISCONNECTED;
const disconnected = process.argv.some((arg) => arg === '--disconnected');

/*
CONFIG GENERATION
Expand Down
3 changes: 1 addition & 2 deletions samples/react/src/util.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const config = require('./temp/config');
const { constants } = require('@sitecore-jss/sitecore-jss-react');

/**
* Check is disconnected mode started
* @returns {boolean}
*/
const isDisconnected = () => process.env.JSS_MODE === constants.JSS_MODE.DISCONNECTED;
const isDisconnected = () => /localhost/i.test(config.sitecoreApiHost);

module.exports.isDisconnected = isDisconnected;

Expand Down
9 changes: 5 additions & 4 deletions samples/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@
"license": "Apache-2.0",
"scripts": {
"jss": "jss",
"start": "cross-env-shell JSS_MODE=disconnected \"npm-run-all --serial bootstrap --parallel start:vue start:proxy start:watch-components\"",
"start:connected": "scjss-verify-setup && npm-run-all --serial bootstrap start:vue start:watch-components",
"build": "npm-run-all --serial bootstrap build:client build:server",
"start": "npm-run-all --serial bootstrap:disconnected --parallel start:vue start:proxy start:watch-components",
"start:connected": "scjss-verify-setup && npm-run-all --serial bootstrap:connected start:vue start:watch-components",
"build": "npm-run-all --serial bootstrap:connected build:client build:server",
"scaffold": "node scripts/scaffold-component.js",
"start:vue": "vue-cli-service serve --open",
"start:proxy": "node scripts/disconnected-mode-proxy.js",
"start:watch-components": "node scripts/generate-component-factory.js --watch",
"build:client": "cross-env-shell BUILD_TARGET_ENV=client PUBLIC_URL=$npm_package_config_sitecoreDistPath \"vue-cli-service build\"",
"build:server": "cross-env-shell BUILD_TARGET_ENV=server \"vue-cli-service build --no-clean\"",
"bootstrap": "node scripts/bootstrap.js",
"bootstrap:connected": "node scripts/bootstrap.js",
"bootstrap:disconnected": "node scripts/bootstrap.js --disconnected",
"graphql:update": "cross-env-shell VUE_CLI_BABEL_TRANSPILE_MODULES=true VUE_CLI_BABEL_TARGET_NODE=true \"node -r @babel/register ./scripts/update-graphql-fragment-data.js\"",
"lint": "vue-cli-service lint ./src/**/*.vue ./src/**/*.js ./sitecore/definitions/**/*.js ./scripts/**/*.js ./server/**/*.js ./data/**/*.yml"
},
Expand Down
3 changes: 1 addition & 2 deletions samples/vue/scripts/bootstrap.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const { constants } = require('@sitecore-jss/sitecore-jss-vue');
const configGenerator = require('./generate-config');
const vueConfig = require('../vue.config');

Expand All @@ -9,7 +8,7 @@ const vueConfig = require('../vue.config');
and the global config module.
*/

const disconnected = process.env.JSS_MODE === constants.JSS_MODE.DISCONNECTED;
const disconnected = process.argv.some((arg) => arg === '--disconnected');

/*
CONFIG GENERATION
Expand Down
7 changes: 1 addition & 6 deletions samples/vue/vue.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
let vueConfig = {};
const path = require('path');
const { constants } = require('@sitecore-jss/sitecore-jss-vue');

if (process.env.BUILD_TARGET_ENV === 'server') {
const serverConfig = require('./server/server.vue.config');
Expand Down Expand Up @@ -33,10 +31,7 @@ if (process.env.BUILD_TARGET_ENV === 'server') {
} else {
vueConfig.devServer = {
port: process.env.PORT || 3000,
proxy:
process.env.JSS_MODE === constants.JSS_MODE.DISCONNECTED
? `http://localhost:${process.env.PROXY_PORT || 3042}`
: undefined,
proxy: `http://localhost:${process.env.PROXY_PORT || 3042}`,
};
}

Expand Down

0 comments on commit 450a032

Please sign in to comment.