Skip to content

Commit 9c09291

Browse files
author
Murat
committed
feat(script): support custom plugin modules
1 parent a6ac78b commit 9c09291

File tree

16 files changed

+433
-117
lines changed

16 files changed

+433
-117
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "react-native-integrate",
33
"version": "0.0.0-development",
44
"description": "Automate integration of additional code into React Native projects",
5+
"main": "lib/index.js",
56
"files": [
67
"!lib/__tests__/**/*",
78
"lib/**/*",
@@ -12,6 +13,7 @@
1213
"rni": "bin/index.js",
1314
"rnu": "bin/upgrade-cli.js"
1415
},
16+
1517
"scripts": {
1618
"build": "tsc",
1719
"clean": "rm -rf ./lib/",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = function plugin(ctx){
2+
ctx.set('script', 'working')
3+
}

src/__tests__/unit/tasks/scriptTask.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ describe('scriptTask', () => {
1010
actions: [
1111
{
1212
script: `
13+
const fs = require('fs');
1314
set('script', 'working')
1415
`,
1516
},
@@ -23,6 +24,25 @@ describe('scriptTask', () => {
2324
taskManager,
2425
});
2526

27+
expect(variables.get('script')).toEqual('working');
28+
});
29+
it('should require plugin', async () => {
30+
const task: ScriptTaskType = {
31+
task: 'script',
32+
actions: [
33+
{
34+
module: '../../src/__tests__/mocks/mockTestPlugin.js',
35+
},
36+
],
37+
};
38+
39+
await scriptTask({
40+
configPath: 'path/to/config',
41+
task: task,
42+
packageName: 'test-package',
43+
taskManager,
44+
});
45+
2646
expect(variables.get('script')).toEqual('working');
2747
});
2848
});

src/__tests__/unit/variables.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,12 @@ describe('variables', () => {
9191
});
9292
it('should process script', () => {
9393
const replaced = getText(`this is $[
94-
set("test", false);
95-
test = true;
94+
var result = true;
95+
set("test2", result);
96+
result;
9697
]`);
9798
expect(replaced).toEqual('this is true');
98-
expect(variables.get('test')).toEqual(true);
99+
expect(variables.get('test2')).toEqual(true);
99100
});
100101
});
101102
describe('transformTextInObject', () => {

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './types/mod.types';

src/schema/integrate.schema.json

Lines changed: 92 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,31 @@
10041004
}
10051005
]
10061006
},
1007+
"ModuleScriptActionType": {
1008+
"additionalProperties": false,
1009+
"properties": {
1010+
"module": {
1011+
"type": "string"
1012+
},
1013+
"name": {
1014+
"type": "string"
1015+
},
1016+
"when": {
1017+
"anyOf": [
1018+
{
1019+
"$ref": "#/definitions/AnyObject"
1020+
},
1021+
{
1022+
"type": "string"
1023+
}
1024+
]
1025+
}
1026+
},
1027+
"required": [
1028+
"module"
1029+
],
1030+
"type": "object"
1031+
},
10071032
"NotificationServiceTaskType": {
10081033
"additionalProperties": false,
10091034
"properties": {
@@ -1635,29 +1660,14 @@
16351660
"type": "object"
16361661
},
16371662
"ScriptActionType": {
1638-
"additionalProperties": false,
1639-
"properties": {
1640-
"name": {
1641-
"type": "string"
1642-
},
1643-
"script": {
1644-
"type": "string"
1663+
"anyOf": [
1664+
{
1665+
"$ref": "#/definitions/TextScriptActionType"
16451666
},
1646-
"when": {
1647-
"anyOf": [
1648-
{
1649-
"$ref": "#/definitions/AnyObject"
1650-
},
1651-
{
1652-
"type": "string"
1653-
}
1654-
]
1667+
{
1668+
"$ref": "#/definitions/ModuleScriptActionType"
16551669
}
1656-
},
1657-
"required": [
1658-
"script"
1659-
],
1660-
"type": "object"
1670+
]
16611671
},
16621672
"ScriptTaskType": {
16631673
"additionalProperties": false,
@@ -2011,6 +2021,31 @@
20112021
}
20122022
]
20132023
},
2024+
"TextScriptActionType": {
2025+
"additionalProperties": false,
2026+
"properties": {
2027+
"name": {
2028+
"type": "string"
2029+
},
2030+
"script": {
2031+
"type": "string"
2032+
},
2033+
"when": {
2034+
"anyOf": [
2035+
{
2036+
"$ref": "#/definitions/AnyObject"
2037+
},
2038+
{
2039+
"type": "string"
2040+
}
2041+
]
2042+
}
2043+
},
2044+
"required": [
2045+
"script"
2046+
],
2047+
"type": "object"
2048+
},
20142049
"XcodeAddBMCapability": {
20152050
"additionalProperties": false,
20162051
"properties": {
@@ -2474,9 +2509,45 @@
24742509
},
24752510
{
24762511
"$ref": "#/definitions/XcodeAddPreBuildRunScriptAction"
2512+
},
2513+
{
2514+
"$ref": "#/definitions/XcodeScriptAction"
24772515
}
24782516
]
24792517
},
2518+
"XcodeScriptAction": {
2519+
"additionalProperties": false,
2520+
"properties": {
2521+
"name": {
2522+
"type": "string"
2523+
},
2524+
"script": {
2525+
"anyOf": [
2526+
{
2527+
"additionalProperties": false,
2528+
"type": "object"
2529+
},
2530+
{
2531+
"type": "string"
2532+
}
2533+
]
2534+
},
2535+
"when": {
2536+
"anyOf": [
2537+
{
2538+
"$ref": "#/definitions/AnyObject"
2539+
},
2540+
{
2541+
"type": "string"
2542+
}
2543+
]
2544+
}
2545+
},
2546+
"required": [
2547+
"script"
2548+
],
2549+
"type": "object"
2550+
},
24802551
"XcodeSetDeploymentVersion": {
24812552
"additionalProperties": false,
24822553
"properties": {

src/schema/upgrade.schema.json

Lines changed: 92 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,31 @@
10041004
}
10051005
]
10061006
},
1007+
"ModuleScriptActionType": {
1008+
"additionalProperties": false,
1009+
"properties": {
1010+
"module": {
1011+
"type": "string"
1012+
},
1013+
"name": {
1014+
"type": "string"
1015+
},
1016+
"when": {
1017+
"anyOf": [
1018+
{
1019+
"$ref": "#/definitions/AnyObject"
1020+
},
1021+
{
1022+
"type": "string"
1023+
}
1024+
]
1025+
}
1026+
},
1027+
"required": [
1028+
"module"
1029+
],
1030+
"type": "object"
1031+
},
10071032
"NotificationServiceTaskType": {
10081033
"additionalProperties": false,
10091034
"properties": {
@@ -1635,29 +1660,14 @@
16351660
"type": "object"
16361661
},
16371662
"ScriptActionType": {
1638-
"additionalProperties": false,
1639-
"properties": {
1640-
"name": {
1641-
"type": "string"
1642-
},
1643-
"script": {
1644-
"type": "string"
1663+
"anyOf": [
1664+
{
1665+
"$ref": "#/definitions/TextScriptActionType"
16451666
},
1646-
"when": {
1647-
"anyOf": [
1648-
{
1649-
"$ref": "#/definitions/AnyObject"
1650-
},
1651-
{
1652-
"type": "string"
1653-
}
1654-
]
1667+
{
1668+
"$ref": "#/definitions/ModuleScriptActionType"
16551669
}
1656-
},
1657-
"required": [
1658-
"script"
1659-
],
1660-
"type": "object"
1670+
]
16611671
},
16621672
"ScriptTaskType": {
16631673
"additionalProperties": false,
@@ -2011,6 +2021,31 @@
20112021
}
20122022
]
20132023
},
2024+
"TextScriptActionType": {
2025+
"additionalProperties": false,
2026+
"properties": {
2027+
"name": {
2028+
"type": "string"
2029+
},
2030+
"script": {
2031+
"type": "string"
2032+
},
2033+
"when": {
2034+
"anyOf": [
2035+
{
2036+
"$ref": "#/definitions/AnyObject"
2037+
},
2038+
{
2039+
"type": "string"
2040+
}
2041+
]
2042+
}
2043+
},
2044+
"required": [
2045+
"script"
2046+
],
2047+
"type": "object"
2048+
},
20142049
"XcodeAddBMCapability": {
20152050
"additionalProperties": false,
20162051
"properties": {
@@ -2474,9 +2509,45 @@
24742509
},
24752510
{
24762511
"$ref": "#/definitions/XcodeAddPreBuildRunScriptAction"
2512+
},
2513+
{
2514+
"$ref": "#/definitions/XcodeScriptAction"
24772515
}
24782516
]
24792517
},
2518+
"XcodeScriptAction": {
2519+
"additionalProperties": false,
2520+
"properties": {
2521+
"name": {
2522+
"type": "string"
2523+
},
2524+
"script": {
2525+
"anyOf": [
2526+
{
2527+
"additionalProperties": false,
2528+
"type": "object"
2529+
},
2530+
{
2531+
"type": "string"
2532+
}
2533+
]
2534+
},
2535+
"when": {
2536+
"anyOf": [
2537+
{
2538+
"$ref": "#/definitions/AnyObject"
2539+
},
2540+
{
2541+
"type": "string"
2542+
}
2543+
]
2544+
}
2545+
},
2546+
"required": [
2547+
"script"
2548+
],
2549+
"type": "object"
2550+
},
24802551
"XcodeSetDeploymentVersion": {
24812552
"additionalProperties": false,
24822553
"properties": {

0 commit comments

Comments
 (0)