Skip to content

Commit

Permalink
[create-sitecore-jss] Use version template token instead of exact ver…
Browse files Browse the repository at this point in the history
…sion number
  • Loading branch information
illiakovalenko committed Oct 29, 2024
1 parent 0c5ee0c commit 8e4cc8f
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 44 deletions.
2 changes: 2 additions & 0 deletions packages/create-sitecore-jss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"@types/minimist": "^1.2.2",
"@types/mocha": "^10.0.1",
"@types/node": "^20.14.2",
"@types/proxyquire": "^1.3.31",
"@types/sinon": "10.0.6",
"@types/sinon-chai": "^3.2.9",
"chai": "^4.3.7",
Expand All @@ -58,6 +59,7 @@
"eslint": "^8.32.0",
"mocha": "^10.2.0",
"nyc": "^15.1.0",
"proxyquire": "^2.1.3",
"sinon": "^15.0.1",
"sinon-chai": "^3.7.0",
"ts-node": "^10.9.1",
Expand Down
47 changes: 36 additions & 11 deletions packages/create-sitecore-jss/src/common/processes/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import sinon, { SinonStub } from 'sinon';
import { currentPkg, partialPkg } from '../test-data/pkg';
import * as transform from './transform';
import * as helpers from '../utils/helpers';
import proxyquire from 'proxyquire';

const {
transformFilename,
Expand Down Expand Up @@ -507,7 +508,6 @@ describe('transform', () => {

globSyncStub = sinon.stub(glob, 'sync').returns([file]);
ejsRenderFileStub = sinon.stub(ejs, 'renderFile').returns(Promise.resolve(renderFileOutput));
diffAndWriteFilesStub = sinon.stub(transform, 'diffAndWriteFiles');

const answers = {
destination: destinationPath,
Expand All @@ -516,10 +516,17 @@ describe('transform', () => {
force: false,
};

await transformFunc(templatePath, answers);
const transformModule = proxyquire('./transform', {
'../../../package.json': { version: '22.2.1-canary.33' },
});

diffAndWriteFilesStub = sinon.stub(transformModule, 'diffAndWriteFiles');

await transformModule.transform(templatePath, answers);

expect(ejsRenderFileStub).to.have.been.calledOnceWith(path.join(templatePath, file), {
...answers,
version: '22.2.1-canary.33',
helper: {
isDev: false,
getPascalCaseName: helpers.getPascalCaseName,
Expand Down Expand Up @@ -629,8 +636,6 @@ describe('transform', () => {
fsExistsSyncStub = sinon.stub(fs, 'existsSync').returns(true);
openJsonFileStub = sinon.stub(helpers, 'openJsonFile').returns(currentPkg);
ejsRenderFileStub = sinon.stub(ejs, 'renderFile').returns(Promise.resolve(renderFileOutput));
mergeStub = sinon.stub(transform, 'merge').returns(mergedPkg);
diffAndWriteFilesStub = sinon.stub(transform, 'diffAndWriteFiles');

const answers = {
destination: destinationPath,
Expand All @@ -639,10 +644,18 @@ describe('transform', () => {
force: false,
};

await transformFunc(templatePath, answers);
const transformModule = proxyquire('./transform', {
'../../../package.json': { version: '22.2.1-canary.33' },
});

diffAndWriteFilesStub = sinon.stub(transformModule, 'diffAndWriteFiles');
mergeStub = sinon.stub(transformModule, 'merge').returns(mergedPkg);

await transformModule.transform(templatePath, answers);

expect(ejsRenderFileStub).to.have.been.calledOnceWith(path.join(templatePath, file), {
...answers,
version: '22.2.1-canary.33',
helper: {
isDev: false,
getPascalCaseName: helpers.getPascalCaseName,
Expand Down Expand Up @@ -670,8 +683,6 @@ describe('transform', () => {
fsExistsSyncStub = sinon.stub(fs, 'existsSync').returns(true);
openJsonFileStub = sinon.stub(helpers, 'openJsonFile').returns(currentJson);
ejsRenderFileStub = sinon.stub(ejs, 'renderFile').returns(Promise.resolve(renderFileOutput));
mergeStub = sinon.stub(transform, 'merge').returns(mergedPkg);
diffAndWriteFilesStub = sinon.stub(transform, 'diffAndWriteFiles');

const answers = {
destination: destinationPath,
Expand All @@ -680,10 +691,18 @@ describe('transform', () => {
force: false,
};

await transformFunc(templatePath, answers);
const transformModule = proxyquire('./transform', {
'../../../package.json': { version: '22.2.1-canary.33' },
});

mergeStub = sinon.stub(transformModule, 'merge').returns(mergedPkg);
diffAndWriteFilesStub = sinon.stub(transformModule, 'diffAndWriteFiles');

await transformModule.transform(templatePath, answers);

expect(ejsRenderFileStub).to.have.been.calledOnceWith(path.join(templatePath, file), {
...answers,
version: '22.2.1-canary.33',
helper: {
isDev: false,
getPascalCaseName: helpers.getPascalCaseName,
Expand Down Expand Up @@ -711,8 +730,13 @@ describe('transform', () => {
fsExistsSyncStub = sinon.stub(fs, 'existsSync').returns(true);
fsReadFileSunc = sinon.stub(fs, 'readFileSync').returns(currentDotEnv);
ejsRenderFileStub = sinon.stub(ejs, 'renderFile').returns(Promise.resolve(templateDotEnv));
mergeEnvStub = sinon.stub(transform, 'mergeEnv').returns(concatDotEnv);
diffAndWriteFilesStub = sinon.stub(transform, 'diffAndWriteFiles');

const transformModule = proxyquire('./transform', {
'../../../package.json': { version: '22.2.1-canary.33' },
});

mergeEnvStub = sinon.stub(transformModule, 'mergeEnv').returns(concatDotEnv);
diffAndWriteFilesStub = sinon.stub(transformModule, 'diffAndWriteFiles');

const answers = {
destination: destinationPath,
Expand All @@ -721,10 +745,11 @@ describe('transform', () => {
force: false,
};

await transformFunc(templatePath, answers);
await transformModule.transform(templatePath, answers);

expect(ejsRenderFileStub).to.have.been.calledOnceWith(path.join(templatePath, file), {
...answers,
version: '22.2.1-canary.33',
helper: {
isDev: false,
getPascalCaseName: helpers.getPascalCaseName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from '../utils/helpers';
import { diffLines, diffJson, Change } from 'diff';
import { BaseArgs } from '../args/base';
import { version } from '../../../package.json';

const FILE_FOR_COPY_REGEXP = /(index\.html)$|\.(gif|jpg|jpeg|tiff|png|svg|ashx|ico|pdf|jar|eot|woff|ttf|woff2)$/;

Expand Down Expand Up @@ -196,6 +197,7 @@ export const populateEjsData = (answers: BaseArgs, destination?: string) => {
// pass in helper to answers object
const ejsData: Data = {
...answers,
version,
helper: {
isDev: isDevEnvironment(destination || answers.destination),
getPascalCaseName: getPascalCaseName,
Expand Down
10 changes: 5 additions & 5 deletions packages/create-sitecore-jss/src/templates/angular/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "<%- appName %>",
"version": "22.2.0-canary",
"version": "<%- version %>",
"description": "Application utilizing Sitecore JavaScript Services and Angular (angular-cli).",
"config": {
"appName": "<%- appName %>",
Expand Down Expand Up @@ -57,7 +57,7 @@
"@apollo/client": "^3.3.12",
"@ngx-translate/core": "~15.0.0",
"@ngx-translate/http-loader": "~8.0.0",
"@sitecore-jss/sitecore-jss-angular": "~22.2.0-canary",
"@sitecore-jss/sitecore-jss-angular": "~<%- version %>",
"apollo-angular": "~6.0.0",
"bootstrap": "^5.3.3",
"core-js": "~3.37.1",
Expand All @@ -78,9 +78,9 @@
"@angular/cli": "~17.3.8",
"@angular/compiler-cli": "~17.3.11",
"@angular/language-service": "~17.3.11",
"@sitecore-jss/sitecore-jss-angular-schematics": "~22.2.0-canary",
"@sitecore-jss/sitecore-jss-cli": "~22.2.0-canary",
"@sitecore-jss/sitecore-jss-dev-tools": "~22.2.0-canary",
"@sitecore-jss/sitecore-jss-angular-schematics": "~<%- version %>",
"@sitecore-jss/sitecore-jss-cli": "~<%- version %>",
"@sitecore-jss/sitecore-jss-dev-tools": "~<%- version %>",
"@types/jasmine": "~3.6.7",
"@types/jasminewd2": "~2.0.8",
"@types/node": "~20.14.10",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"nprogress": "~0.2.0"
},
"devDependencies": {
"@sitecore-jss/sitecore-jss-dev-tools": "~22.2.0-canary",
"@sitecore-jss/sitecore-jss-dev-tools": "~<%- version %>",
"@types/nprogress": "^0.2.0"
},
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "<%- appName %>",
"description": "Application utilizing Sitecore JavaScript Services and Next.js",
"version": "22.2.0-canary",
"version": "<%- version %>",
"private": true,
"config": {
"appName": "<%- appName %>",
Expand All @@ -25,7 +25,7 @@
},
"license": "Apache-2.0",
"dependencies": {
"@sitecore-jss/sitecore-jss-nextjs": "~22.2.0-canary",
"@sitecore-jss/sitecore-jss-nextjs": "~<%- version %>",
"graphql": "~15.8.0",
"graphql-tag": "^2.12.6",
"next": "^14.2.7",
Expand All @@ -43,8 +43,8 @@
"@graphql-codegen/typescript-operations": "^4.0.1",
"@graphql-codegen/typescript-resolvers": "^4.0.1",
"@graphql-typed-document-node/core": "^3.2.0",
"@sitecore-jss/sitecore-jss-cli": "~22.2.0-canary",
"@sitecore-jss/sitecore-jss-dev-tools": "~22.2.0-canary",
"@sitecore-jss/sitecore-jss-cli": "~<%- version %>",
"@sitecore-jss/sitecore-jss-dev-tools": "~<%- version %>",
"@types/node": "^20.14.2",
"@types/react": "^18.2.22",
"@types/react-dom": "^18.0.5",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-headless-ssr-experience-edge-sample",
"version": "22.2.0-canary",
"version": "<%- version %>",
"description": "Node server-side-rendering sample for running JSS apps under Node hosting using Experience Edge",
"scripts": {
"start": "ts-node ./src/index.ts"
Expand All @@ -19,7 +19,7 @@
"homepage": "https://jss.sitecore.com",
"license": "Apache-2.0",
"dependencies": {
"@sitecore-jss/sitecore-jss": "~22.2.0-canary",
"@sitecore-jss/sitecore-jss": "~<%- version %>",
"compression": "^1.7.4",
"express": "^4.18.2",
"dotenv": "^16.0.3"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-headless-ssr-proxy-sample",
"version": "22.2.0-canary",
"version": "<%- version %>",
"description": "Node server-side-rendering proxy sample for running JSS apps under Node hosting",
"scripts": {
"start": "ts-node ./src/index.ts"
Expand All @@ -19,8 +19,8 @@
"homepage": "https://jss.sitecore.com",
"license": "Apache-2.0",
"dependencies": {
"@sitecore-jss/sitecore-jss": "~22.2.0-canary",
"@sitecore-jss/sitecore-jss-proxy": "~22.2.0-canary",
"@sitecore-jss/sitecore-jss": "~<%- version %>",
"@sitecore-jss/sitecore-jss-proxy": "~<%- version %>",
"agentkeepalive": "^4.2.1",
"compression": "~1.7.4",
"express": "~4.19.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-xmcloud-sample",
"version": "22.2.0-canary",
"version": "<%- version %>",
"description": "Node XM Cloud Proxy sample for running XM Cloud JSS SPA apps",
"author": {
"name": "Sitecore Corporation",
Expand All @@ -10,14 +10,14 @@
"start": "ts-node ./src/index.ts"
},
"dependencies": {
"@sitecore-jss/sitecore-jss-proxy": "~22.2.0-canary",
"@sitecore-jss/sitecore-jss-proxy": "~<%- version %>",
"compression": "^1.7.4",
"express": "^4.18.2",
"dotenv": "^16.0.3",
"http-proxy-middleware": "^3.0.0"
},
"devDependencies": {
"@sitecore-jss/sitecore-jss": "~22.2.0-canary",
"@sitecore-jss/sitecore-jss": "~<%- version %>",
"@types/compression": "^1.7.2",
"@types/express": "^4.17.17",
"ts-node": "^10.9.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "<%- appName %>",
"version": "22.2.0-canary",
"version": "<%- version %>",
"description": "A basic React Native app utilizing Sitecore JavaScript Services",
"config": {
"appName": "<%- appName %>",
Expand All @@ -23,7 +23,7 @@
},
"dependencies": {
"@react-native-community/masked-view": "^0.1.10",
"@sitecore-jss/sitecore-jss-react-native": "~22.2.0-canary",
"@sitecore-jss/sitecore-jss-react-native": "~<%- version %>",
"prop-types": "^15.6.0",
"react": "16.13.1",
"react-native": "^0.63.4",
Expand All @@ -37,8 +37,8 @@
},
"private": true,
"devDependencies": {
"@sitecore-jss/sitecore-jss-cli": "~22.2.0-canary",
"@sitecore-jss/sitecore-jss-dev-tools": "~22.2.0-canary",
"@sitecore-jss/sitecore-jss-cli": "~<%- version %>",
"@sitecore-jss/sitecore-jss-dev-tools": "~<%- version %>",
"babel-core": "^6.26.0",
"babel-eslint": "^8.2.1",
"babel-plugin-inline-replace-variables": "^1.3.1",
Expand Down
10 changes: 5 additions & 5 deletions packages/create-sitecore-jss/src/templates/react/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "<%- appName %>",
"description": "Application utilizing Sitecore JavaScript Services and React (create-react-app).",
"version": "22.2.0-canary",
"version": "<%- version %>",
"private": true,
"config": {
"appName": "<%- appName %>",
Expand All @@ -28,7 +28,7 @@
"license": "Apache-2.0",
"dependencies": {
"@apollo/client": "^3.7.1",
"@sitecore-jss/sitecore-jss-react": "~22.2.0-canary",
"@sitecore-jss/sitecore-jss-react": "~<%- version %>",
"axios": "^1.2.0",
"bootstrap": "^5.2.3",
"cross-fetch": "^3.1.5",
Expand All @@ -53,9 +53,9 @@
"@babel/preset-env": "^7.20.2",
"@babel/preset-react": "^7.18.6",
"@babel/register": "~7.18.9",
"@sitecore-jss/sitecore-jss-cli": "~22.2.0-canary",
"@sitecore-jss/sitecore-jss-dev-tools": "~22.2.0-canary",
"@sitecore-jss/sitecore-jss-rendering-host": "~22.2.0-canary",
"@sitecore-jss/sitecore-jss-cli": "~<%- version %>",
"@sitecore-jss/sitecore-jss-dev-tools": "~<%- version %>",
"@sitecore-jss/sitecore-jss-rendering-host": "~<%- version %>",
"babel-loader": "~9.1.0",
"babel-preset-react-app": "~10.0.1",
"chalk": "~4.1.2",
Expand Down
8 changes: 4 additions & 4 deletions packages/create-sitecore-jss/src/templates/vue/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "<%- appName %>",
"version": "22.2.0-canary",
"version": "<%- version %>",
"description": "Application utilizing Sitecore JavaScript Services and Vue (vue-cli).",
"private": true,
"config": {
Expand Down Expand Up @@ -45,7 +45,7 @@
"dependencies": {
"@apollo/client": "^3.7.4",
"@panter/vue-i18next": "~0.15.2",
"@sitecore-jss/sitecore-jss-vue": "~22.2.0-canary",
"@sitecore-jss/sitecore-jss-vue": "~<%- version %>",
"@vue/apollo-composable": "4.0.0-beta.2",
"@vue/apollo-option": "^4.0.0-alpha.20",
"@vue/apollo-ssr": "^4.0.0-alpha.18",
Expand All @@ -64,8 +64,8 @@
"devDependencies": {
"@babel/eslint-parser": "^7.19.1",
"@babel/register": "7.18.9",
"@sitecore-jss/sitecore-jss-cli": "~22.2.0-canary",
"@sitecore-jss/sitecore-jss-dev-tools": "~22.2.0-canary",
"@sitecore-jss/sitecore-jss-cli": "~<%- version %>",
"@sitecore-jss/sitecore-jss-dev-tools": "~<%- version %>",
"@vue/cli-plugin-babel": "~5.0.8",
"@vue/cli-plugin-eslint": "~5.0.8",
"@vue/cli-service": "~5.0.8",
Expand Down
Loading

0 comments on commit 8e4cc8f

Please sign in to comment.