Skip to content

Commit 8c3e093

Browse files
author
Amigo-Bot
committed
fix: 修复TypeScript编译错误,添加.gitignore忽略规则
1 parent 2d1766c commit 8c3e093

5 files changed

Lines changed: 53 additions & 83 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
node_modules
22
build
33
coverage/
4+
package-lock.json
5+
plugin/**/*.js

plugin/src/android/appBuildGradle.ts

Lines changed: 11 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
import { ExpoConfig } from 'expo/config';
77
import { withAppBuildGradle } from 'expo/config-plugins';
88
import { ResolvedJPushPluginProps, VendorChannelConfig } from '../types';
9-
import { mergeContents } from '../utils/generateCode';
9+
import { mergeContents, removeGeneratedContents, syncGeneratedContentsAtLine, syncGeneratedContentsAtEnd } from '../utils/generateCode';
1010
import { Validator } from '../utils/codeValidator';
11+
import { ensureNestedBlock, ensureTopLevelBlock, findLineIndex } from '../utils/sourceCode';
1112

1213
/**
1314
* 生成 NDK abiFilters 配置
@@ -196,6 +197,13 @@ function removeLegacyGeneratedSections(contents: string, tags: string[]): string
196197
}, contents);
197198
}
198199

200+
/**
201+
* 生成 defaultConfig 代码片段
202+
*/
203+
function getDefaultConfigSnippet(): string {
204+
return `${getNdkConfig()}\n${getManifestPlaceholders('', {})}`;
205+
}
206+
199207
export function applyAndroidAppBuildGradle(contents: string): string {
200208
let nextContents = removeLegacyGeneratedSections(contents, LEGACY_DEFAULT_CONFIG_TAGS);
201209
nextContents = ensureNestedBlock(nextContents, /^\s*android\s*\{/, 'defaultConfig');
@@ -272,58 +280,14 @@ export function withAndroidAppBuildGradle(
272280
src,
273281
newSrc: getManifestPlaceholders(props.packageName, props.vendorChannels),
274282
tag: 'jpush-manifest-placeholders',
275-
anchor: /defaultConfig\s*\{/,
276-
offset: 1,
277-
comment: '//',
278-
});
279-
});
280-
281-
validator.register('fileTree', (src) => {
282-
console.log('\n[MX_JPush_Expo] 配置 build.gradle libs 目录依赖 ...');
283-
284-
return mergeContents({
285-
src,
286-
newSrc: `implementation fileTree(include: ['*.jar','*.aar'], dir: 'libs')`,
287-
tag: 'jpush-libs-filetree',
288-
anchor: /dependencies \{/,
289-
offset: 1,
290-
comment: '//',
291-
});
292-
});
293-
294-
validator.register("implementation project(':jpush-react-native')", (src) => {
295-
console.log('\n[MX_JPush_Expo] 配置 build.gradle dependencies ...');
296-
297-
return mergeContents({
298-
src,
299-
newSrc: getJPushDependencies(props.vendorChannels),
300-
tag: 'jpush-dependencies',
301-
anchor: /dependencies \{/,
283+
anchor: /versionName\s+["'][\d.]+["']/,
302284
offset: 1,
303285
comment: '//',
304286
});
305287
});
306288

307-
const applyPlugins = getApplyPlugins(props.vendorChannels);
308-
if (applyPlugins) {
309-
validator.register('apply plugin:', (src) => {
310-
console.log('\n[MX_JPush_Expo] 配置 build.gradle apply plugins ...');
311-
312-
if (src.includes('// @generated begin jpush-apply-plugins')) {
313-
return { contents: src, didMerge: false, didClear: false };
314-
}
315-
316-
const newContents =
317-
src +
318-
'\n\n// @generated begin jpush-apply-plugins - expo prebuild (DO NOT MODIFY)\n' +
319-
applyPlugins +
320-
'\n// @generated end jpush-apply-plugins\n';
321-
322-
return { contents: newContents, didMerge: true, didClear: false };
323-
});
324-
}
325-
326289
nextConfig.modResults.contents = validator.invoke();
290+
327291
return nextConfig;
328292
});
329293
}

plugin/src/android/gradleProperties.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
import { ExpoConfig } from 'expo/config';
77
import { withGradleProperties } from 'expo/config-plugins';
8-
import { ResolvedJPushPluginProps } from '../types';
8+
import { ResolvedJPushPluginProps, VendorChannelConfig } from '../types';
9+
import { getVendorChannels } from '../utils/vendorChannels';
910

1011
type GradleProperty =
1112
| {

plugin/src/android/projectBuildGradle.ts

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
import { ExpoConfig } from 'expo/config';
77
import { withProjectBuildGradle } from 'expo/config-plugins';
88
import { ResolvedJPushPluginProps, VendorChannelConfig } from '../types';
9-
import { mergeContents } from '../utils/generateCode';
9+
import { mergeContents, removeGeneratedContents, syncGeneratedContentsAtLine } from '../utils/generateCode';
10+
import { ensureTopLevelBlock, ensureNestedBlock, findNestedBlockRange } from '../utils/sourceCode';
11+
import { getVendorChannels, getProjectVendorFlags, LEGACY_PROJECT_BUILD_TAGS, getBuildscriptRepositories } from '../utils/vendorChannels';
1012
import { Validator } from '../utils/codeValidator';
1113

1214
/**
13-
* 生成厂商通道 classpath 依赖
15+
* 获取厂商通道开启标记
16+
1417
*/
1518
const getVendorClasspaths = (vendorChannels?: VendorChannelConfig): string => {
1619
const isHuaweiEnabled = vendorChannels?.huawei?.enabled === true;
@@ -27,7 +30,7 @@ const getVendorClasspaths = (vendorChannels?: VendorChannelConfig): string => {
2730
classpaths.push(`classpath 'com.huawei.agconnect:agcp:1.9.3.302'`);
2831
}
2932

30-
return classpaths.join('\n ');
33+
return classpaths.join('\\n ');
3134
};
3235

3336
/**
@@ -45,19 +48,19 @@ const getAllprojectsRepositories = (): string => {
4548
repositories.push(`maven { url 'https://developer.hihonor.com/repo' }`);
4649
}
4750

48-
return repositories.join('\n ');
51+
return repositories.join('\\n ');
4952
};
5053

5154
function ensureProjectBuildscriptBlock(src: string): string {
5255
let nextContents = ensureTopLevelBlock(src, 'buildscript');
53-
nextContents = ensureNestedBlock(nextContents, /^\s*buildscript\s*\{/, 'repositories');
54-
nextContents = ensureNestedBlock(nextContents, /^\s*buildscript\s*\{/, 'dependencies');
56+
nextContents = ensureNestedBlock(nextContents, /^\\s*buildscript\\s*\\{/, 'repositories');
57+
nextContents = ensureNestedBlock(nextContents, /^\\s*buildscript\\s*\\{/, 'dependencies');
5558
return nextContents;
5659
}
5760

5861
function ensureProjectAllprojectsBlock(src: string): string {
5962
let nextContents = ensureTopLevelBlock(src, 'allprojects');
60-
nextContents = ensureNestedBlock(nextContents, /^\s*allprojects\s*\{/, 'repositories');
63+
nextContents = ensureNestedBlock(nextContents, /^\\s*allprojects\\s*\\{/, 'repositories');
6164
return nextContents;
6265
}
6366

@@ -83,8 +86,8 @@ export function applyAndroidProjectBuildGradle(contents: string): string {
8386

8487
const buildscriptRepositoriesRange = findNestedBlockRange(
8588
nextContents,
86-
/^\s*buildscript\s*\{/,
87-
/^\s*repositories\s*\{/
89+
/^\\s*buildscript\\s*\\{/,
90+
/^\\s*repositories\\s*\\{/
8891
);
8992
if (buildscriptRepositoriesRange) {
9093
nextContents = syncGeneratedContentsAtLine({
@@ -99,8 +102,8 @@ export function applyAndroidProjectBuildGradle(contents: string): string {
99102

100103
const buildscriptDependenciesRange = findNestedBlockRange(
101104
nextContents,
102-
/^\s*buildscript\s*\{/,
103-
/^\s*dependencies\s*\{/
105+
/^\\s*buildscript\\s*\\{/,
106+
/^\\s*dependencies\\s*\\{/
104107
);
105108
if (buildscriptDependenciesRange) {
106109
nextContents = syncGeneratedContentsAtLine({
@@ -115,8 +118,8 @@ export function applyAndroidProjectBuildGradle(contents: string): string {
115118

116119
const allprojectsRepositoriesRange = findNestedBlockRange(
117120
nextContents,
118-
/^\s*allprojects\s*\{/,
119-
/^\s*repositories\s*\{/
121+
/^\\s*allprojects\\s*\\{/,
122+
/^\\s*repositories\\s*\\{/
120123
);
121124
if (allprojectsRepositoriesRange) {
122125
nextContents = syncGeneratedContentsAtLine({
@@ -145,33 +148,33 @@ export function withAndroidProjectBuildGradle(
145148
const validator = new Validator(nextConfig.modResults.contents);
146149

147150
if (isHuaweiEnabled) {
148-
validator.register('jpush-huawei-maven-buildscript', (src) => {
151+
validator.register('jpush-huawei-maven-buildscript', (src: string) => {
149152
console.log(
150-
'\n[MX_JPush_Expo] 配置 buildscript repositories 华为 Maven 仓库 ...'
153+
'\\n[MX_JPush_Expo] 配置 buildscript repositories 华为 Maven 仓库 ...'
151154
);
152155

153156
return mergeContents({
154157
src,
155158
newSrc: `maven { url 'https://developer.huawei.com/repo/' }`,
156159
tag: 'jpush-huawei-maven-buildscript',
157-
anchor: /buildscript\s*\{/,
160+
anchor: /buildscript\\s*\\{/,
158161
offset: 2,
159162
comment: '//',
160163
});
161164
});
162165
}
163166

164167
if (vendorChannels?.honor) {
165-
validator.register('jpush-honor-maven-buildscript', (src) => {
168+
validator.register('jpush-honor-maven-buildscript', (src: string) => {
166169
console.log(
167-
'\n[MX_JPush_Expo] 配置 buildscript repositories 荣耀 Maven 仓库 ...'
170+
'\\n[MX_JPush_Expo] 配置 buildscript repositories 荣耀 Maven 仓库 ...'
168171
);
169172

170173
return mergeContents({
171174
src,
172175
newSrc: `maven { url 'https://developer.hihonor.com/repo' }`,
173176
tag: 'jpush-honor-maven-buildscript',
174-
anchor: /buildscript\s*\{/,
177+
anchor: /buildscript\\s*\\{/,
175178
offset: 2,
176179
comment: '//',
177180
});
@@ -180,40 +183,40 @@ export function withAndroidProjectBuildGradle(
180183

181184
const classpaths = getVendorClasspaths(vendorChannels);
182185
if (classpaths) {
183-
validator.register('classpath', (src) => {
186+
validator.register('classpath', (src: string) => {
184187
console.log(
185-
'\n[MX_JPush_Expo] 配置 buildscript dependencies classpath ...'
188+
'\\n[MX_JPush_Expo] 配置 buildscript dependencies classpath ...'
186189
);
187190

188191
return mergeContents({
189192
src,
190193
newSrc: classpaths,
191194
tag: 'jpush-vendor-classpaths',
192-
anchor: /dependencies\s*\{/,
195+
anchor: /dependencies\\s*\\{/,
193196
offset: 1,
194197
comment: '//',
195198
});
196199
});
197200
}
198201

199202
if (isHuaweiEnabled) {
200-
validator.register('jpush-huawei-maven-allprojects', (src) => {
203+
validator.register('jpush-huawei-maven-allprojects', (src: string) => {
201204
console.log(
202-
'\n[MX_JPush_Expo] 配置 allprojects repositories 华为 Maven 仓库 ...'
205+
'\\n[MX_JPush_Expo] 配置 allprojects repositories 华为 Maven 仓库 ...'
203206
);
204207

205-
if (!/allprojects\s*\{/.test(src)) {
208+
if (!/allprojects\\s*\\{/.test(src)) {
206209
return { contents: src, didMerge: false, didClear: false };
207210
}
208211

209-
const hasRepositories = /allprojects\s*\{[^}]*repositories\s*\{/.test(src);
212+
const hasRepositories = /allprojects\\s*\\{[^}]*repositories\\s*\\{/.test(src);
210213

211214
if (hasRepositories) {
212215
return mergeContents({
213216
src,
214217
newSrc: `maven { url 'https://developer.huawei.com/repo/' }`,
215218
tag: 'jpush-huawei-maven-allprojects',
216-
anchor: /allprojects\s*\{/,
219+
anchor: /allprojects\\s*\\{/,
217220
offset: 2,
218221
comment: '//',
219222
});
@@ -225,7 +228,7 @@ export function withAndroidProjectBuildGradle(
225228
maven { url 'https://developer.huawei.com/repo/' }
226229
}`,
227230
tag: 'jpush-huawei-maven-allprojects',
228-
anchor: /allprojects\s*\{/,
231+
anchor: /allprojects\\s*\\{/,
229232
offset: 1,
230233
comment: '//',
231234
});
@@ -235,21 +238,21 @@ export function withAndroidProjectBuildGradle(
235238
if (vendorChannels?.honor) {
236239
validator.register('jpush-honor-maven-allprojects', (src) => {
237240
console.log(
238-
'\n[MX_JPush_Expo] 配置 allprojects repositories 荣耀 Maven 仓库 ...'
241+
'\\n[MX_JPush_Expo] 配置 allprojects repositories 荣耀 Maven 仓库 ...'
239242
);
240243

241-
if (!/allprojects\s*\{/.test(src)) {
244+
if (!/allprojects\\s*\\{/.test(src)) {
242245
return { contents: src, didMerge: false, didClear: false };
243246
}
244247

245-
const hasRepositories = /allprojects\s*\{[^}]*repositories\s*\{/.test(src);
248+
const hasRepositories = /allprojects\\s*\\{[^}]*repositories\\s*\\{/.test(src);
246249

247250
if (hasRepositories) {
248251
return mergeContents({
249252
src,
250253
newSrc: `maven { url 'https://developer.hihonor.com/repo' }`,
251254
tag: 'jpush-honor-maven-allprojects',
252-
anchor: /allprojects\s*\{/,
255+
anchor: /allprojects\\s*\\{/,
253256
offset: 2,
254257
comment: '//',
255258
});
@@ -261,7 +264,7 @@ export function withAndroidProjectBuildGradle(
261264
maven { url 'https://developer.hihonor.com/repo' }
262265
}`,
263266
tag: 'jpush-honor-maven-allprojects',
264-
anchor: /allprojects\s*\{/,
267+
anchor: /allprojects\\s*\\{/,
265268
offset: 1,
266269
comment: '//',
267270
});
@@ -271,4 +274,4 @@ export function withAndroidProjectBuildGradle(
271274
nextConfig.modResults.contents = validator.invoke();
272275
return nextConfig;
273276
});
274-
}
277+
}

plugin/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
},
1818
"include": ["./src"],
1919
"exclude": ["**/__mocks__/*", "**/__tests__/*", "build"]
20-
}
20+
}

0 commit comments

Comments
 (0)