Skip to content

Commit 0301cbe

Browse files
authored
Merge pull request #2349 from contentstack/feat/DX-3899
DX - 3899 - Migration Rewrite to TS
2 parents 31e3d9e + 09c6d62 commit 0301cbe

File tree

117 files changed

+7042
-1128
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+7042
-1128
lines changed

.github/workflows/release.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ jobs:
230230
if: ${{env.release_releaseAll == 'true' || env.release_plugins_migration == 'true'}}
231231
working-directory: ./packages/contentstack-migration
232232
run: npm install
233+
- name: Compiling Migration
234+
if: ${{ steps.migration-installation.conclusion == 'success' }}
235+
working-directory: ./packages/contentstack-migration
236+
run: npm run prepack
233237
- name: Publishing migration
234238
uses: JS-DevTools/npm-publish@v3
235239
if: ${{ steps.migration-installation.conclusion == 'success' }}

.talismanrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
fileignoreconfig:
22
- filename: package-lock.json
3-
checksum: 9bc80890e9aff310a9288fdc9fbaccb2652594b2e92f95f8b17f5d4a2be45f81
3+
checksum: 20001b2b16e2ab8cc8a3ccc30cebb5093c5c63f58e5b5fe64889d260a8d4cc56
44
- filename: pnpm-lock.yaml
5-
checksum: 70c84ad3ad7bcee1ed18cd49d921bce674c25fa4b20dfacd9dc3bd5a20ecee6b
5+
checksum: c2982bbd478bd9aabcc12bc162d2a76e2635d70023674a677dea996a8671e9ab
66
version: '1.0'

package-lock.json

Lines changed: 168 additions & 109 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/contentstack-migration/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@
55
/tmp
66
/yarn.lock
77
node_modules
8-
.nyc_output
8+
.nyc_output
9+
/lib
10+
tsconfig.tsbuildinfo
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"require": ["test/helpers/init.js", "ts-node/register", "source-map-support/register"],
3+
"watch-extensions": [
4+
"ts"
5+
],
6+
"recursive": true,
7+
"timeout": 5000
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"inlcude": [
3+
"lib/**/*.js"
4+
]
5+
}

packages/contentstack-migration/examples/change-master-locale/02-change-master-locale-new-file-structure.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module.exports = async ({ migration, config }) => {
3434
if (masterLocale) {
3535
masterLocale = JSON.parse(masterLocale);
3636
masterLocale = Object.values(masterLocale);
37-
masterLocale = masterLocale[0]?.code;
37+
masterLocale = masterLocale[0]
3838

3939
// Validate that we have a valid master locale code
4040
if (!masterLocale) {

packages/contentstack-migration/package.json

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@contentstack/cli-migration",
3-
"version": "1.10.3",
3+
"version": "1.11.0",
44
"author": "@contentstack",
55
"bugs": "https://github.com/contentstack/cli/issues",
66
"dependencies": {
@@ -18,39 +18,49 @@
1818
},
1919
"devDependencies": {
2020
"@oclif/test": "^4.1.13",
21+
"@types/mocha": "^8.2.3",
22+
"@types/node": "^14.18.63",
2123
"chai": "^4.5.0",
2224
"eslint": "^8.57.1",
2325
"eslint-config-oclif": "^6.0.62",
2426
"jsdoc-to-markdown": "^8.0.3",
27+
"mocha": "^10.8.2",
2528
"nock": "^13.5.6",
2629
"nyc": "^15.1.0",
27-
"oclif": "^4.17.46"
30+
"oclif": "^4.17.46",
31+
"sinon": "^19.0.5",
32+
"source-map-support": "^0.5.21",
33+
"ts-node": "^10.9.2",
34+
"typescript": "^4.9.5"
2835
},
2936
"engines": {
3037
"node": ">=8.3.0"
3138
},
3239
"files": [
40+
"/lib",
3341
"/npm-shrinkwrap.json",
34-
"/oclif.manifest.json",
35-
"/src",
36-
"/yarn.lock"
42+
"/oclif.manifest.json"
3743
],
3844
"homepage": "https://github.com/contentstack/cli",
3945
"keywords": [
4046
"oclif-plugin"
4147
],
4248
"license": "MIT",
4349
"oclif": {
44-
"commands": "./src/commands",
50+
"commands": "./lib/commands",
4551
"bin": "csdx",
4652
"repositoryPrefix": "<%- repo %>/blob/main/packages/contentstack-migration/<%- commandPath %>"
4753
},
4854
"repository": "contentstack/cli",
4955
"scripts": {
5056
"postpack": "rm -f oclif.manifest.json",
51-
"generate-api-ref-md-doc": "nyc jsdoc2md ./src/modules/* > ./docs/api-reference.md",
52-
"prepack": "oclif manifest && oclif readme && pnpm generate-api-ref-md-doc",
53-
"test": "nyc mocha --timeout 3000 \"test/**/*.test.js\"",
57+
"generate-api-ref-md-doc": "nyc jsdoc2md ./src/modules/*.ts > ./docs/api-reference.md || true",
58+
"compile": "tsc -b tsconfig.json",
59+
"prepack": "pnpm compile && oclif manifest && oclif readme",
60+
"pretest": "tsc -p test",
61+
"test": "mocha --forbid-only \"test/unit/**/*.test.ts\"",
62+
"test:unit": "mocha --timeout 10000 --forbid-only \"test/unit/**/*.test.ts\"",
63+
"test:unit:report": "nyc --extension .ts mocha --forbid-only \"test/unit/**/*.test.ts\"",
5464
"version": "oclif readme && git add README.md",
5565
"clean": "rm -rf ./node_modules tsconfig.build.tsbuildinfo"
5666
},

packages/contentstack-migration/src/actions/action-list.js renamed to packages/contentstack-migration/src/actions/action-list.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
/* eslint-disable no-unused-expressions */
2-
'use strict';
2+
export default class ActionList {
3+
typeErrors?: any;
4+
actionList?: any[];
5+
validators: any[];
36

4-
class ActionList {
5-
constructor(actionList, typeErrors) {
7+
constructor(actionList?: any[], typeErrors?: any) {
68
typeErrors && (this.typeErrors = typeErrors);
79
actionList && (this.actionList = actionList);
810
this.validators = [];
911
}
1012

11-
addValidators(validator) {
13+
addValidators(validator: any): void {
1214
this.validators.push(validator);
1315
}
1416

15-
validate() {
17+
validate(): any[] {
1618
const { validators, actionList } = this;
1719

18-
let errors = [];
20+
if (!actionList) {
21+
return [];
22+
}
23+
24+
let errors: any[] = [];
1925
for (const action of actionList) {
2026
for (const validator of validators) {
2127
if (validator.isApplicable(action)) {
@@ -28,5 +34,3 @@ class ActionList {
2834
return errors;
2935
}
3036
}
31-
32-
module.exports = ActionList;

packages/contentstack-migration/src/actions/index.js renamed to packages/contentstack-migration/src/actions/index.ts

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
'use strict';
2-
31
// Utils
4-
const { constants } = require('../utils');
2+
import { constants } from '../utils';
53
// Properties
64
const { actions, validationAction } = constants;
75
const {
@@ -18,8 +16,8 @@ const {
1816
field,
1917
} = validationAction;
2018

21-
const actionCreators = {
22-
customTasks: (callsite, opts) => {
19+
export const actionCreators = {
20+
customTasks: (callsite: any, opts: any) => {
2321
const { CUSTOM_TASK } = actions;
2422
return {
2523
type: customTask,
@@ -36,7 +34,7 @@ const actionCreators = {
3634
};
3735
},
3836
contentType: {
39-
create: (callsite, id, opts) => {
37+
create: (callsite: any, id: string, opts: any) => {
4038
const { CREATE_CT } = actions;
4139
return {
4240
type: create,
@@ -53,7 +51,7 @@ const actionCreators = {
5351
},
5452
};
5553
},
56-
edit: (callsite, id, opts) => {
54+
edit: (callsite: any, id: string, opts: any) => {
5755
const { EDIT_CT } = actions;
5856

5957
return {
@@ -72,7 +70,7 @@ const actionCreators = {
7270
};
7371
},
7472
// delete: () => { },
75-
transformEntries: (callsite, id, opts) => {
73+
transformEntries: (callsite: any, id: string, opts: any) => {
7674
return {
7775
type: transformEntries,
7876
meta: {
@@ -86,7 +84,7 @@ const actionCreators = {
8684
},
8785
};
8886
},
89-
deriveLinkedEntries: (callsite, id, opts) => {
87+
deriveLinkedEntries: (callsite: any, id: string, opts: any) => {
9088
return {
9189
type: deriveLinkedEntries,
9290
meta: {
@@ -100,7 +98,7 @@ const actionCreators = {
10098
},
10199
};
102100
},
103-
transformEntriesToType: (callsite, id, opts) => {
101+
transformEntriesToType: (callsite: any, id: string, opts: any) => {
104102
return {
105103
type: transformEntriesToType,
106104
meta: {
@@ -114,7 +112,7 @@ const actionCreators = {
114112
},
115113
};
116114
},
117-
typeError: (callsite, id, { typeErrors }) => {
115+
typeError: (callsite: any, id: string, { typeErrors }: { typeErrors: any }) => {
118116
return {
119117
type: typeError,
120118
meta: {
@@ -126,7 +124,7 @@ const actionCreators = {
126124
payload: { typeErrors },
127125
};
128126
},
129-
apiError: (callsite, id, opts) => {
127+
apiError: (callsite: any, id: string, opts: any) => {
130128
return {
131129
type: apiError,
132130
meta: {
@@ -138,7 +136,7 @@ const actionCreators = {
138136
payload: { apiError: opts },
139137
};
140138
},
141-
fromFields: (callsite, id, opts) => {
139+
fromFields: (callsite: any, id: string, opts: any) => {
142140
return {
143141
type: schema,
144142
meta: {
@@ -150,7 +148,7 @@ const actionCreators = {
150148
payload: { fromField: opts.fromField },
151149
};
152150
},
153-
toFields: (callsite, id, opts) => {
151+
toFields: (callsite: any, id: string, opts: any) => {
154152
return {
155153
type: schema,
156154
meta: {
@@ -162,7 +160,7 @@ const actionCreators = {
162160
payload: { toField: opts.toField },
163161
};
164162
},
165-
toReferenceFields: (callsite, id, opts) => {
163+
toReferenceFields: (callsite: any, id: string, opts: any) => {
166164
return {
167165
type: schema,
168166
meta: {
@@ -174,7 +172,7 @@ const actionCreators = {
174172
payload: { toField: opts.toReferenceField },
175173
};
176174
},
177-
deriveFields: (callsite, id, opts) => {
175+
deriveFields: (callsite: any, id: string, opts: any) => {
178176
return {
179177
type: schema,
180178
meta: {
@@ -186,7 +184,7 @@ const actionCreators = {
186184
payload: { deriveField: opts.deriveField },
187185
};
188186
},
189-
migrationError: (callsite, id, opts) => {
187+
migrationError: (callsite: any, id: string, opts: any) => {
190188
return {
191189
type: __migrationError,
192190
meta: {
@@ -198,7 +196,7 @@ const actionCreators = {
198196
payload: { migrationError: opts },
199197
};
200198
},
201-
field: (callsite, id, opts) => {
199+
field: (callsite: any, id: string, opts: any) => {
202200
return {
203201
type: field,
204202
meta: {
@@ -213,5 +211,4 @@ const actionCreators = {
213211
},
214212
};
215213

216-
exports.actionCreators = actionCreators;
217-
exports.ActionList = require('./action-list');
214+
export { default as ActionList } from './action-list';

0 commit comments

Comments
 (0)