Skip to content

Commit 9a2265b

Browse files
Merge pull request #189 from contentstack/fix/v1-build-issues
Fix/v1 build issues
2 parents 60d5412 + 85d3ec7 commit 9a2265b

30 files changed

Lines changed: 2162 additions & 4341 deletions

File tree

.github/workflows/unit-test.yml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,26 +66,22 @@ jobs:
6666
working-directory: ./packages/contentstack-query-export
6767
run: npm run test:unit
6868

69-
- name: Run tests for Contentstack Apps CLI
70-
working-directory: ./packages/contentstack-apps-cli
71-
run: npm run test:unit:report:json
72-
7369
- name: Run tests for Contentstack Content Type plugin
7470
working-directory: ./packages/contentstack-content-type
7571
run: npm run test:unit
7672

7773
- name: Run tests for Contentstack Regex Validate plugin
7874
working-directory: ./packages/contentstack-cli-cm-regex-validate
79-
run: npm run test:unit
80-
81-
- name: Run tests for Contentstack Tsgen plugin
82-
working-directory: ./packages/contentstack-cli-tsgen
8375
run: npm run test
8476

8577
- name: Run tests for Contentstack Migrate RTE
8678
working-directory: ./packages/contentstack-migrate-rte
87-
run: npm test
79+
run: npm run test
8880

8981
- name: Run tests for Contentstack Bulk Operations
9082
working-directory: ./packages/contentstack-bulk-operations
91-
run: npm test
83+
run: npm run test
84+
85+
- name: Run tests for Contentstack Apps CLI
86+
working-directory: ./packages/contentstack-apps-cli
87+
run: npm run test:unit:report

packages/contentstack-apps-cli/package.json

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"chalk": "^4.1.2",
3030
"lodash": "^4.18.1",
3131
"shelljs": "^0.10.0",
32-
"tmp": "^0.2.5",
32+
"tmp": "^0.2.7",
3333
"winston": "^3.19.0"
3434
},
3535
"devDependencies": {
@@ -49,10 +49,9 @@
4949
"eslint": "^8.57.1",
5050
"eslint-config-oclif": "^6.0.157",
5151
"eslint-config-oclif-typescript": "^3.1.14",
52-
"fancy-test": "3.0.16",
5352
"mocha": "^10.8.2",
5453
"nyc": "^15.1.0",
55-
"oclif": "^4.23.0",
54+
"oclif": "^4.23.8",
5655
"shx": "^0.4.0",
5756
"ts-node": "^10.9.2",
5857
"tslib": "^2.8.1",
@@ -62,9 +61,6 @@
6261
"bin": "csdx",
6362
"dirname": "apps-cli",
6463
"commands": "./lib/commands",
65-
"hooks": {
66-
"init": "./lib/hooks/init/load-chalk.js"
67-
},
6864
"plugins": [],
6965
"topicSeparator": ":",
7066
"additionalHelpFlags": [
@@ -80,11 +76,11 @@
8076
}
8177
},
8278
"scripts": {
83-
"build": "npm run clean && shx rm -rf lib && tsc -b",
79+
"build": "pnpm clean && tsc -b",
8480
"lint": "eslint . --ext .ts --config .eslintrc",
8581
"postpack": "shx rm -f oclif.manifest.json",
86-
"posttest": "npm run lint",
87-
"prepack": "npm run build && oclif manifest && oclif readme",
82+
"posttest": "pnpm lint",
83+
"prepack": "pnpm build && oclif manifest && oclif readme",
8884
"test": "mocha --forbid-only \"test/**/*.test.ts\"",
8985
"version": "oclif readme && git add README.md",
9086
"clean": "rm -rf ./lib tsconfig.tsbuildinfo oclif.manifest.json",

packages/contentstack-apps-cli/test/helpers/init.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,13 @@ process.env.NODE_ENV = 'development'
44

55
global.oclif = global.oclif || {}
66
global.oclif.columns = 80
7-
global.commonMock = require(path.join(__dirname, '../unit/mock/common.mock.json'))
7+
global.commonMock = require(path.join(__dirname, '../unit/mock/common.mock.json'))
8+
9+
const { configHandler } = require('@contentstack/cli-utilities')
10+
if (!configHandler.get('region')) {
11+
configHandler.set('region', {
12+
name: 'NA',
13+
cma: 'https://api.contentstack.io',
14+
cda: 'https://cdn.contentstack.io',
15+
})
16+
}

packages/contentstack-apps-cli/test/unit/commands/app/deploy.test.ts

Lines changed: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,15 @@ import { runCommand } from "@oclif/test";
44
import { cliux, configHandler } from "@contentstack/cli-utilities";
55
import messages, { $t } from "../../../../src/messages";
66
const mock = (global as any).commonMock;
7-
import { getDeveloperHubUrl } from "../../../../src/util/inquirer";
87
import sinon from "sinon";
98
import { stubAuthentication } from "../../helpers/auth-stub-helper";
109
import Deploy from "../../../../src/commands/app/deploy";
1110
import { BaseCommand } from "../../../../src/base-command";
12-
import { join } from "path";
13-
14-
const region = configHandler.get("region");
15-
// Commands run from lib/ (oclif.commands); stub the same classes/modules the running command uses
16-
let BaseCommandToStub: typeof BaseCommand;
17-
let LibDeploy: typeof Deploy;
18-
let libCommonUtils: any;
19-
let libInquirer: any;
20-
try {
21-
BaseCommandToStub = require(join(process.cwd(), "lib", "base-command")).BaseCommand;
22-
} catch {
23-
BaseCommandToStub = BaseCommand;
24-
}
25-
try {
26-
LibDeploy = require(join(process.cwd(), "lib", "commands", "app", "deploy")).default;
27-
} catch {
28-
LibDeploy = Deploy;
29-
}
30-
try {
31-
libCommonUtils = require(join(process.cwd(), "lib", "util", "common-utils"));
32-
} catch {
33-
libCommonUtils = require("../../../../src/util/common-utils");
34-
}
35-
try {
36-
libInquirer = require(join(process.cwd(), "lib", "util", "inquirer"));
37-
} catch {
38-
libInquirer = require("../../../../src/util/inquirer");
39-
}
40-
const developerHubBaseUrl = getDeveloperHubUrl();
11+
import * as libCommonUtils from "../../../../src/util/common-utils";
12+
import * as libInquirer from "../../../../src/util/inquirer";
13+
14+
let region!: { cma: string; name: string; cda: string };
15+
let developerHubBaseUrl!: string;
4116

4217
describe("app:deploy", () => {
4318
let sandbox: sinon.SinonSandbox;
@@ -52,6 +27,8 @@ describe("app:deploy", () => {
5227

5328
// Stub authentication using shared helper
5429
stubAuthentication(sandbox);
30+
region = configHandler.get("region");
31+
developerHubBaseUrl = libInquirer.getDeveloperHubUrl();
5532

5633
sandbox.stub(cliux, "loader").callsFake(() => {});
5734
sandbox.stub(cliux, "inquire").callsFake((prompt: any) => {
@@ -64,7 +41,7 @@ describe("app:deploy", () => {
6441
return Promise.resolve(cases[prompt.name]);
6542
});
6643

67-
// Stub utilities used by the running command (lib/util); stub same module it requires
44+
// Stub utilities used by the running command (src/util); same module instances oclif loads via tsPath
6845
sandbox.stub(libCommonUtils, "getProjects").resolves([]);
6946
sandbox.stub(libCommonUtils, "updateApp").resolves();
7047
sandbox.stub(libCommonUtils, "disconnectApp").resolves();
@@ -76,14 +53,14 @@ describe("app:deploy", () => {
7653
sandbox.stub(libInquirer, "getAppUrl").resolves("https://example.com");
7754
sandbox.stub(libInquirer, "askProjectType").resolves("existing");
7855
sandbox.stub(libInquirer, "askConfirmation").resolves(false);
79-
sandbox.stub(libInquirer, "selectProject").resolves(null);
56+
sandbox.stub(libInquirer, "selectProject").resolves(undefined);
8057
sandbox.stub(libInquirer, "askProjectName").resolves("test-project");
8158

8259
// Stub Launch.run
8360
sandbox.stub(require("@contentstack/cli-launch").Launch, "run").resolves();
8461

85-
// Stub getApolloClient on the class that actually runs (lib Deploy) so no real GraphQL runs
86-
sandbox.stub(LibDeploy.prototype, "getApolloClient").resolves({
62+
// Stub getApolloClient so no real GraphQL runs
63+
sandbox.stub(Deploy.prototype, "getApolloClient").resolves({
8764
query: () =>
8865
Promise.resolve({
8966
data: {
@@ -94,7 +71,7 @@ describe("app:deploy", () => {
9471
}),
9572
} as any);
9673

97-
// Stub SDK init so no real HTTP is made (cli-utilities exports use getters so we can't stub those).
74+
// Stub SDK init so no real HTTP is made
9875
const mockManagementSdk = {
9976
organization: () => ({
10077
fetchAll: () =>
@@ -116,15 +93,15 @@ describe("app:deploy", () => {
11693
}),
11794
}),
11895
};
119-
sandbox.stub(BaseCommandToStub.prototype, "initCmaSDK").callsFake(async function (this: any) {
96+
sandbox.stub(BaseCommand.prototype, "initCmaSDK").callsFake(async function (this: any) {
12097
this.managementSdk = mockManagementSdk;
12198
this.managementAppSdk = mockManagementSdk;
12299
});
123-
sandbox.stub(BaseCommandToStub.prototype, "initMarketplaceSDK").callsFake(async function (this: any) {
100+
sandbox.stub(BaseCommand.prototype, "initMarketplaceSDK").callsFake(async function (this: any) {
124101
this.marketplaceAppSdk = mockMarketplaceSdk;
125102
});
126103

127-
// Nock CMA and developer hub (SDK may use :443 or different param order)
104+
// Nock CMA and developer hub
128105
const cmaOrigin = region.cma.replace(/\/$/, "");
129106
const orgReply = {
130107
organizations: mock.organizations,
@@ -213,7 +190,7 @@ describe("app:deploy", () => {
213190
sandbox.stub(process, "exit").callsFake(((code?: number) => {
214191
throw new Error(`process.exit(${code})`);
215192
}) as any);
216-
sandbox.stub(LibDeploy.prototype, "getApolloClient").resolves({
193+
sandbox.stub(Deploy.prototype, "getApolloClient").resolves({
217194
query: () =>
218195
Promise.resolve({
219196
data: { projects: { edges: [] } },
@@ -240,11 +217,11 @@ describe("app:deploy", () => {
240217
}),
241218
}),
242219
};
243-
sandbox.stub(BaseCommandToStub.prototype, "initCmaSDK").callsFake(async function (this: any) {
220+
sandbox.stub(BaseCommand.prototype, "initCmaSDK").callsFake(async function (this: any) {
244221
this.managementSdk = mockMgmt;
245222
this.managementAppSdk = mockMgmt;
246223
});
247-
sandbox.stub(BaseCommandToStub.prototype, "initMarketplaceSDK").callsFake(async function (this: any) {
224+
sandbox.stub(BaseCommand.prototype, "initMarketplaceSDK").callsFake(async function (this: any) {
248225
this.marketplaceAppSdk = mockMkt;
249226
});
250227
stubAuthentication(sandbox);
@@ -287,7 +264,7 @@ describe("app:deploy", () => {
287264
sandbox.stub(process, "exit").callsFake(((code?: number) => {
288265
throw new Error(`process.exit(${code})`);
289266
}) as any);
290-
sandbox.stub(LibDeploy.prototype, "getApolloClient").resolves({
267+
sandbox.stub(Deploy.prototype, "getApolloClient").resolves({
291268
query: () =>
292269
Promise.resolve({
293270
data: {
@@ -330,11 +307,11 @@ describe("app:deploy", () => {
330307
}),
331308
}),
332309
};
333-
sandbox.stub(BaseCommandToStub.prototype, "initCmaSDK").callsFake(async function (this: any) {
310+
sandbox.stub(BaseCommand.prototype, "initCmaSDK").callsFake(async function (this: any) {
334311
this.managementSdk = mockMgmt;
335312
this.managementAppSdk = mockMgmt;
336313
});
337-
sandbox.stub(BaseCommandToStub.prototype, "initMarketplaceSDK").callsFake(async function (this: any) {
314+
sandbox.stub(BaseCommand.prototype, "initMarketplaceSDK").callsFake(async function (this: any) {
338315
this.marketplaceAppSdk = mockMkt;
339316
});
340317
stubAuthentication(sandbox);
@@ -355,14 +332,15 @@ describe("app:deploy", () => {
355332
sandbox.stub(libInquirer, "askProjectType").resolves("new");
356333
sandbox.stub(libInquirer, "askProjectName").resolves("new-project");
357334
sandbox.stub(libInquirer, "askConfirmation").resolves(false);
358-
sandbox.stub(libInquirer, "selectProject").resolves(null);
335+
sandbox.stub(libInquirer, "selectProject").resolves(undefined);
359336

360337
sandbox.stub(libCommonUtils, "getProjects").resolves([
361338
{
362339
name: "new-project",
363340
uid: "project-2",
364341
url: "https://new-project.com",
365342
environmentUid: "env-2",
343+
developerHubAppUid: null,
366344
},
367345
]);
368346
sandbox.stub(libCommonUtils, "setupConfig").returns({

packages/contentstack-apps-cli/test/unit/commands/app/update.test.ts

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,6 @@ import { BaseCommand } from "../../../../src/base-command";
1414

1515
const region = configHandler.get("region");
1616

17-
// Commands run from lib/ (oclif); stub the same class the running command uses
18-
let BaseCommandToStub: typeof BaseCommand;
19-
let LibUpdate: typeof Update;
20-
try {
21-
BaseCommandToStub = require(join(process.cwd(), "lib", "base-command")).BaseCommand;
22-
} catch {
23-
BaseCommandToStub = BaseCommand;
24-
}
25-
try {
26-
LibUpdate = require(join(process.cwd(), "lib", "commands", "app", "update")).default;
27-
} catch {
28-
LibUpdate = Update;
29-
}
30-
3117
/** Optional override: return a custom marketplace SDK mock for this test. */
3218
let marketplaceMockOverride: any = null;
3319

@@ -55,11 +41,11 @@ function stubUpdateInit(sandbox: sinon.SinonSandbox) {
5541
}),
5642
}),
5743
};
58-
sandbox.stub(BaseCommandToStub.prototype, "initCmaSDK").callsFake(async function (this: any) {
44+
sandbox.stub(BaseCommand.prototype, "initCmaSDK").callsFake(async function (this: any) {
5945
this.managementSdk = mockManagementSdk;
6046
this.managementAppSdk = mockManagementSdk;
6147
});
62-
sandbox.stub(BaseCommandToStub.prototype, "initMarketplaceSDK").callsFake(async function (this: any) {
48+
sandbox.stub(BaseCommand.prototype, "initMarketplaceSDK").callsFake(async function (this: any) {
6349
this.marketplaceAppSdk = marketplaceMockOverride ?? defaultMarketplaceSdk;
6450
});
6551
}
@@ -95,7 +81,7 @@ describe("app:update", () => {
9581
sandbox.stub(fs, "writeFileSync").callsFake(() => {});
9682

9783
sandbox
98-
.stub(LibUpdate.prototype, "updateAppOnDeveloperHub")
84+
.stub(Update.prototype, "updateAppOnDeveloperHub")
9985
.callsFake(async function (this: any) {
10086
this.log(this.messages.APP_UPDATE_SUCCESS, "info");
10187
});
@@ -193,7 +179,7 @@ describe("app:update", () => {
193179
describe("Update app with wrong app-uid API failure", () => {
194180
beforeEach(() => {
195181
sandbox
196-
.stub(LibUpdate.prototype, "updateAppOnDeveloperHub")
182+
.stub(Update.prototype, "updateAppOnDeveloperHub")
197183
.callsFake(async function (this: any) {
198184
this.log(this.messages.INVALID_APP_ID, "error");
199185
throw { status: 400 };
@@ -214,7 +200,7 @@ describe("app:update", () => {
214200
describe("Update app API failure", () => {
215201
beforeEach(() => {
216202
sandbox
217-
.stub(LibUpdate.prototype, "updateAppOnDeveloperHub")
203+
.stub(Update.prototype, "updateAppOnDeveloperHub")
218204
.callsFake(async function (this: any) {
219205
this.log(this.messages.APP_INVALID_ORG, "error");
220206
throw { status: 403 };
@@ -234,7 +220,7 @@ describe("app:update", () => {
234220
describe("Update app with duplicate app name (409 status)", () => {
235221
beforeEach(() => {
236222
sandbox
237-
.stub(LibUpdate.prototype, "updateAppOnDeveloperHub")
223+
.stub(Update.prototype, "updateAppOnDeveloperHub")
238224
.callsFake(async function (this: any) {
239225
this.log(
240226
this.$t(this.messages.DUPLICATE_APP_NAME, {

packages/contentstack-audit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"dependencies": {
2121
"@contentstack/cli-command": "~1.8.2",
2222
"@contentstack/cli-utilities": "~1.18.3",
23-
"@oclif/core": "^4.10.5",
23+
"@oclif/core": "^4.11.4",
2424
"chalk": "^4.1.2",
2525
"fast-csv": "^4.3.6",
2626
"fs-extra": "^11.3.0",

packages/contentstack-bootstrap/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"@contentstack/cli-command": "~1.8.2",
2121
"@contentstack/cli-config": "~1.20.3",
2222
"@contentstack/cli-utilities": "~1.18.3",
23-
"@oclif/core": "^4.10.5",
23+
"@oclif/core": "^4.11.4",
2424
"inquirer": "8.2.7",
2525
"mkdirp": "^2.1.6",
2626
"tar": "^7.5.11"

packages/contentstack-branches/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"bugs": "https://github.com/contentstack/cli/issues",
77
"dependencies": {
88
"@contentstack/cli-command": "~1.8.2",
9-
"@oclif/core": "^4.10.5",
9+
"@oclif/core": "^4.11.4",
1010
"@contentstack/cli-utilities": "~1.18.3",
1111
"chalk": "^4.1.2",
1212
"just-diff": "^6.0.2",

0 commit comments

Comments
 (0)