@pi-r/android 0.9.3 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data/google-maven-snapshot.json +1 -1
- package/data/google-maven.json +1 -1
- package/extensions/app/manifest/index.js +1 -1
- package/extensions/gradle/dependencies/index.js +130 -44
- package/extensions/gradle/settings/index.js +4 -3
- package/extensions/task/index.js +5 -5
- package/index.js +25 -8
- package/package.json +4 -4
- package/project/gradle/wrapper/gradle-wrapper.properties +2 -2
- package/template/java/static/build.gradle +2 -2
- package/template/java/static/gradle.properties +14 -0
- package/template/java+kotlin/build.gradle +9 -6
- package/template/java+kotlin/libs.versions.toml +17 -0
- package/template/java+kotlin/static/build.gradle +2 -3
- package/template/java+kotlin/static/gradle.properties +16 -0
- package/template/kotlin/build.gradle.kts +4 -0
- package/template/kotlin/libs.versions.toml +4 -2
- package/template/kotlin/static/gradle.properties +16 -0
- package/types/index.d.ts +1 -0
- package/types/squared.d.ts +5 -0
- package/project/gradle.properties +0 -4
|
@@ -173,7 +173,7 @@ function finalize(instance) {
|
|
|
173
173
|
}
|
|
174
174
|
if (modified || !existing) {
|
|
175
175
|
try {
|
|
176
|
-
if (instance.writeFile(localUri, source, { encoding: '
|
|
176
|
+
if (instance.writeFile(localUri, source, { encoding: 'utf8', ownPermissionOnly: true, throwsPermission: true }) && !existing) {
|
|
177
177
|
this.add(localUri);
|
|
178
178
|
}
|
|
179
179
|
}
|
|
@@ -6,8 +6,10 @@ const types_1 = require("@e-mc/types");
|
|
|
6
6
|
const util_1 = require("@e-mc/document/util");
|
|
7
7
|
const REGEXP_SEMVER = /^((\s*,\s*)?[([\]]((\s*,\s*)?\d+\.\d+(\s*,\s*)?)+[)\][])+$/;
|
|
8
8
|
const REGEXP_DEPENDENCIES = /dependencies\s+\{((?:{[^{]*{|{[^}]*}|}[^}]*}|\\}*?|[^{}+])+)\}/;
|
|
9
|
-
const REGEXP_DEPENDENCY = /([ \t]*)([A-Za-z_$][\w$]*)(?:\s*\(?\s*(?:module\(?\s*)?["']([^"']+)["']\s*\)?|\s+((?:\s*(?:group|name|version)\s*:\s*(?:"[^"]+"|'[^']+')\s*,?){3}))?/gd;
|
|
10
|
-
const REGEXP_DEPENDENCY_KOTLIN = /([ \t]*)([A-Za-z_$][\w$]*)\((?:\s*(?:(?:module\(\s*)?"([^"]+)"|((?:\s*(?:group|name|version)\s*=\s*"[^"]+"\s*,?){3}))\s*\))?/gd;
|
|
9
|
+
const REGEXP_DEPENDENCY = /([ \t]*)([A-Za-z_$][\w$]*)(?:\s*\(?\s*(?:module\(?\s*)?["']([^"']+)["']\s*\)?|\s+((?:\s*(?:group|name|version)\s*:\s*(?:"(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+')\s*,?){3}))?/gd;
|
|
10
|
+
const REGEXP_DEPENDENCY_KOTLIN = /([ \t]*)([A-Za-z_$][\w$]*)\((?:\s*(?:(?:module\(\s*)?"([^"]+)"|((?:\s*(?:group|name|version)\s*=\s*"(?:[^"]|(?<=\\)")+"\s*,?){3}))\s*\))?/gd;
|
|
11
|
+
const REGEXP_LIBRARY = /([ \t]*)implementation\s+(?:(project|files)\s*\(\s*("(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+')\s*\)|(fileTree)\s*\(\s*((?:\s*(?:dir|include)\s*:\s*(?:"(?:[^"]|(?<=\\)")+"|'(?:[^']|(?<=\\)')+'|\[[^\]]+\])\s*,?){2})\s*\))[ \t\r]*\n/gd;
|
|
12
|
+
const REGEXP_LIBRARY_KOTLIN = /([ \t]*)implementation\(\s*(?:(project|files)\(\s*"(.+)"\s*\)|(fileTree)\(\s*mapOf\(((?:\s*"(?:dir|include)"\s+to\s+(?:"(?:[^"]|(?<=\\)")+"|listOf\([^)]+\))\s*,?){2})\)\s*\))\s*\)[ \t\r]*\n/gd;
|
|
11
13
|
const REGEXP_VERSIONS = /([^\s]+)\s*=\s*(?:"([^":]+)"|'([^':]+)'|(\{(?:\s*(?:require|strictly|prefer|reject(?:All)?)\s*=\s*(?:"[^":]+"|'[^':]+')\s*,?)+\s*\}))/g;
|
|
12
14
|
const REGEXP_VERSIONS_LIB = /([^\s]+)\s*=\s*(?:\{\s*(group|name|module|version(?:\.ref)?)\s*=\s*(?:"([^"]+)"|'([^']+)'|(\{[^}]+\}))\s*,\s*(group|name|module|version(?:\.ref)?)\s*=\s*(?:"([^"]+)"|'([^']+)'|(\{[^}]+\}))(?:\s*,\s*(group|name|module|version(?:\.ref)?)\s*=\s*(?:"([^"]+)"|'([^']+)')|(\{[^}]+\}))?\s*\}|(?:"([^:]+:[^"]+)"|'([^:]+:[^']+)'))/gd;
|
|
13
15
|
function isUpgrade(version, pending) {
|
|
@@ -34,7 +36,7 @@ function isUpgrade(version, pending) {
|
|
|
34
36
|
return false;
|
|
35
37
|
}
|
|
36
38
|
function writeMethod(kotlin, named, item, args = '', prefix = 'implementation') {
|
|
37
|
-
if (/^(?:implementation|api|compileOnly(?:Api)?|runtimeOnly|(?:test|androidTest)(?:Implementation|RuntimeOnly|CompileOnly))$/.test(prefix)) {
|
|
39
|
+
if (/^(?:implementation|api|compileOnly(?:Api)?|runtimeOnly|(?:test|androidTest)(?:Implementation|RuntimeOnly|CompileOnly)|lint(?:Checks|Publish))$/.test(prefix)) {
|
|
38
40
|
switch (parseInt(item[3])) {
|
|
39
41
|
case 0:
|
|
40
42
|
prefix = 'implementation';
|
|
@@ -69,6 +71,12 @@ function writeMethod(kotlin, named, item, args = '', prefix = 'implementation')
|
|
|
69
71
|
case 10:
|
|
70
72
|
prefix = 'androidTestRuntimeOnly';
|
|
71
73
|
break;
|
|
74
|
+
case 11:
|
|
75
|
+
prefix = 'lintChecks';
|
|
76
|
+
break;
|
|
77
|
+
case 12:
|
|
78
|
+
prefix = 'lintPublish';
|
|
79
|
+
break;
|
|
72
80
|
}
|
|
73
81
|
}
|
|
74
82
|
const [group, name, version] = item;
|
|
@@ -92,8 +100,8 @@ const isLatest = (value) => value === '' || value.startsWith('latest.');
|
|
|
92
100
|
const isSemVer = (value) => isLatest(value) || REGEXP_SEMVER.test(value);
|
|
93
101
|
const toCamelCase = (value) => value.replace(/-([a-z])/gi, (...capture) => capture[1].toUpperCase());
|
|
94
102
|
function finalize(instance) {
|
|
95
|
-
const { profileable, dependencies, dataBinding, jvmToolchain, versionName, versionCode, namespace, applicationId, mainParentDir } = instance.config;
|
|
96
|
-
if (!profileable && !dependencies && !dataBinding && !jvmToolchain && !versionName && !versionCode && !namespace && !applicationId) {
|
|
103
|
+
const { profileable, dependencies, libraries, dataBinding, jvmToolchain, versionName, versionCode, namespace, applicationId, mainParentDir } = instance.config;
|
|
104
|
+
if (!profileable && !dependencies && !libraries && !dataBinding && !jvmToolchain && !versionName && !versionCode && !namespace && !applicationId) {
|
|
97
105
|
return;
|
|
98
106
|
}
|
|
99
107
|
let { localUri, source, existing, kotlin = false, language } = instance.findTemplate(path.join(this.baseDirectory, mainParentDir), "build.gradle", { detect: instance.detect(this), languageOf: 'gradle' });
|
|
@@ -107,6 +115,11 @@ function finalize(instance) {
|
|
|
107
115
|
modified = true;
|
|
108
116
|
}
|
|
109
117
|
};
|
|
118
|
+
const setDependencies = (match, output) => {
|
|
119
|
+
if (modified || !existing) {
|
|
120
|
+
setModified((0, util_1.spliceString)(source, match.index, match.index + match[0].length, `dependencies {${output}}`));
|
|
121
|
+
}
|
|
122
|
+
};
|
|
110
123
|
if (dependencies) {
|
|
111
124
|
const { dependencyScopes, versionCatalog } = instance.config;
|
|
112
125
|
let mavenData;
|
|
@@ -222,14 +235,14 @@ function finalize(instance) {
|
|
|
222
235
|
}
|
|
223
236
|
const match = REGEXP_DEPENDENCIES.exec(source);
|
|
224
237
|
if (match) {
|
|
225
|
-
const newLine =
|
|
238
|
+
const newLine = (0, util_1.getNewline)(source);
|
|
226
239
|
const gradleDir = path.join(this.baseDirectory, 'gradle');
|
|
227
|
-
const template = instance.findTemplate(gradleDir, "libs.versions.toml", { detect: true, subDir:
|
|
240
|
+
const template = instance.findTemplate(gradleDir, "libs.versions.toml", { detect: true, subDir: language, throwsDoesNotExist: false });
|
|
228
241
|
let content = match[1], named = false, versioning = false, indent;
|
|
229
242
|
if (template.localUri && template.source) {
|
|
230
243
|
versioning = kotlin && versionCatalog !== false || !!versionCatalog;
|
|
231
244
|
if (versioning || template.existing) {
|
|
232
|
-
const
|
|
245
|
+
const libs = {};
|
|
233
246
|
const versions = {};
|
|
234
247
|
let config = template.source, catalog;
|
|
235
248
|
while (catalog = REGEXP_VERSIONS.exec(config)) {
|
|
@@ -278,7 +291,7 @@ function finalize(instance) {
|
|
|
278
291
|
}
|
|
279
292
|
}
|
|
280
293
|
}
|
|
281
|
-
|
|
294
|
+
libs[catalog[1]] = lib;
|
|
282
295
|
}
|
|
283
296
|
}
|
|
284
297
|
if (versioning && items.length > 0) {
|
|
@@ -287,15 +300,15 @@ function finalize(instance) {
|
|
|
287
300
|
const item = items[i];
|
|
288
301
|
const [group, name, version] = item;
|
|
289
302
|
let key = group.replaceAll('.', '-');
|
|
290
|
-
if (
|
|
303
|
+
if (libs[key]) {
|
|
291
304
|
key += '-' + name.replaceAll('.', '-');
|
|
292
305
|
}
|
|
293
306
|
let versionRef;
|
|
294
307
|
found: {
|
|
295
308
|
for (const ref in versions) {
|
|
296
309
|
if (versions[ref] === version) {
|
|
297
|
-
for (const lib in
|
|
298
|
-
if (
|
|
310
|
+
for (const lib in libs) {
|
|
311
|
+
if (libs[lib]['version.ref'] === ref && (libs[lib].group === group || libs[lib].module?.startsWith(group + ':'))) {
|
|
299
312
|
versionRef = ref;
|
|
300
313
|
break found;
|
|
301
314
|
}
|
|
@@ -324,7 +337,7 @@ function finalize(instance) {
|
|
|
324
337
|
item[0] = 'libs.' + key.replaceAll('-', '.');
|
|
325
338
|
item[1] = '';
|
|
326
339
|
item[2] = '';
|
|
327
|
-
|
|
340
|
+
libs[key] = { group, name, "version.ref": versionRef };
|
|
328
341
|
}
|
|
329
342
|
let section = /\[libraries\]\s*/.exec(config);
|
|
330
343
|
const writeOutput = (value) => (0, util_1.spliceString)(config, section.index, section.index + section[0].length, value);
|
|
@@ -347,12 +360,11 @@ function finalize(instance) {
|
|
|
347
360
|
}
|
|
348
361
|
if (instance.canWrite(template.localUri, { ownPermissionOnly: true }) && Document.createDir(gradleDir)) {
|
|
349
362
|
try {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
}
|
|
363
|
+
fs.writeFileSync(template.localUri, config, 'utf8');
|
|
364
|
+
this.add(template.localUri);
|
|
353
365
|
}
|
|
354
366
|
catch (err) {
|
|
355
|
-
this.writeFail(["Unable to write file", path.basename(template.localUri)], err,
|
|
367
|
+
this.writeFail(["Unable to write file", path.basename(template.localUri)], err, 32);
|
|
356
368
|
}
|
|
357
369
|
}
|
|
358
370
|
REGEXP_VERSIONS_LIB.lastIndex = 0;
|
|
@@ -365,7 +377,7 @@ function finalize(instance) {
|
|
|
365
377
|
let method;
|
|
366
378
|
while (method = pattern.exec(content)) {
|
|
367
379
|
let group, name, version;
|
|
368
|
-
if (method[1]) {
|
|
380
|
+
if ((0, types_1.isString)(method[1])) {
|
|
369
381
|
indent ||= method[1];
|
|
370
382
|
}
|
|
371
383
|
if (method[3]) {
|
|
@@ -409,13 +421,11 @@ function finalize(instance) {
|
|
|
409
421
|
}
|
|
410
422
|
}
|
|
411
423
|
}
|
|
412
|
-
indent ||= (0, util_1.getIndent)(
|
|
424
|
+
indent ||= (0, util_1.getIndent)(match[1]);
|
|
413
425
|
content = items.reduce((a, b) => a + indent + writeMethod(kotlin, named, b) + newLine, content);
|
|
414
426
|
modified = true;
|
|
415
427
|
}
|
|
416
|
-
|
|
417
|
-
setModified((0, util_1.spliceString)(source, match.index, match.index + match[0].length, `dependencies {${content}}`));
|
|
418
|
-
}
|
|
428
|
+
setDependencies(match, content);
|
|
419
429
|
}
|
|
420
430
|
if (items.some(seg => seg[0] === 'androidx.compose.ui')) {
|
|
421
431
|
let output = source;
|
|
@@ -441,6 +451,88 @@ function finalize(instance) {
|
|
|
441
451
|
setModified(output);
|
|
442
452
|
}
|
|
443
453
|
}
|
|
454
|
+
if (libraries) {
|
|
455
|
+
const match = REGEXP_DEPENDENCIES.exec(source);
|
|
456
|
+
if (match) {
|
|
457
|
+
let content = match[1], method, indent;
|
|
458
|
+
const pattern = kotlin ? REGEXP_LIBRARY_KOTLIN : REGEXP_LIBRARY;
|
|
459
|
+
pattern.lastIndex = 0;
|
|
460
|
+
while (method = pattern.exec(content)) {
|
|
461
|
+
const attr = (method[2] || method[4]);
|
|
462
|
+
if ((0, types_1.isArray)(libraries[attr])) {
|
|
463
|
+
let index = -1;
|
|
464
|
+
switch (attr) {
|
|
465
|
+
case 'project':
|
|
466
|
+
case 'files': {
|
|
467
|
+
const pathname = (0, util_1.trimQuote)(method[3]);
|
|
468
|
+
index = libraries[attr].findIndex(value => value === pathname);
|
|
469
|
+
break;
|
|
470
|
+
}
|
|
471
|
+
case 'fileTree': {
|
|
472
|
+
const dir = /"dir"\s+to\s+"(.+?)"(?:\s*,|$)/.exec(match[5])?.[1];
|
|
473
|
+
const include = /"include"\s+to\s+listOf\((.+?)\)(?:\s*,|$)/.exec(match[5])?.[1];
|
|
474
|
+
if (dir && include) {
|
|
475
|
+
const compare = (from, orig) => {
|
|
476
|
+
try {
|
|
477
|
+
return (0, types_1.isArray)(from) && from.sort().toString() === JSON.parse(`[${orig}]`).sort().toString();
|
|
478
|
+
}
|
|
479
|
+
catch {
|
|
480
|
+
return false;
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
const target = libraries[attr];
|
|
484
|
+
for (let i = 0; i < target.length; ++i) {
|
|
485
|
+
if (target[i].dir === dir && compare(target[i].include, include)) {
|
|
486
|
+
index = i;
|
|
487
|
+
break;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
break;
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
if (index !== -1) {
|
|
495
|
+
libraries[attr].splice(index, 1);
|
|
496
|
+
}
|
|
497
|
+
if ((0, types_1.isString)(method[1])) {
|
|
498
|
+
indent ||= method[1];
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
const { project, files, fileTree } = libraries;
|
|
503
|
+
if ((0, types_1.isArray)(project) || (0, types_1.isArray)(files) || (0, types_1.isArray)(fileTree)) {
|
|
504
|
+
indent ||= (0, util_1.getIndent)(match[1]);
|
|
505
|
+
const newLine = (0, util_1.getNewline)(source);
|
|
506
|
+
const writeImpl = (name, value) => indent + 'implementation' + (kotlin ? `(${name}(${(0, util_1.wrapQuote)(value)}))` : ` ${name}(${(0, util_1.wrapQuote)(value)})`) + newLine;
|
|
507
|
+
if ((0, types_1.isArray)(project)) {
|
|
508
|
+
content = project.reduce((a, b) => a + writeImpl('project', b), content);
|
|
509
|
+
modified = true;
|
|
510
|
+
}
|
|
511
|
+
if ((0, types_1.isArray)(files)) {
|
|
512
|
+
content = files.reduce((a, b) => a + writeImpl('files', b), content);
|
|
513
|
+
modified = true;
|
|
514
|
+
}
|
|
515
|
+
if ((0, types_1.isArray)(fileTree)) {
|
|
516
|
+
for (const item of fileTree) {
|
|
517
|
+
if ((0, types_1.isString)(item.dir) && (0, types_1.isArray)(item.include)) {
|
|
518
|
+
const dir = (0, util_1.wrapQuote)(item.dir);
|
|
519
|
+
const include = item.include.map(value => (0, util_1.wrapQuote)(value)).join(', ');
|
|
520
|
+
content += indent + 'implementation';
|
|
521
|
+
if (kotlin) {
|
|
522
|
+
content += `(fileTree(mapOf("dir" to ${dir}, "include" to listOf(${include}))))`;
|
|
523
|
+
}
|
|
524
|
+
else {
|
|
525
|
+
content += ` fileTree(dir: ${dir}, include: [${include}])`;
|
|
526
|
+
}
|
|
527
|
+
content += newLine;
|
|
528
|
+
modified = true;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
setDependencies(match, content);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
444
536
|
if (upgrade || jvmTarget) {
|
|
445
537
|
const compatibility = 'JavaVersion.VERSION_' + (upgrade ? javaVersion.toString().replace(/\./g, '_') : jvmTarget);
|
|
446
538
|
let output = source;
|
|
@@ -469,21 +561,21 @@ function finalize(instance) {
|
|
|
469
561
|
const targetAPI = instance.targetAPI;
|
|
470
562
|
let output = source;
|
|
471
563
|
if (targetAPI) {
|
|
472
|
-
const
|
|
473
|
-
const updateOnly = +targetAPI >=
|
|
474
|
-
let
|
|
475
|
-
if (
|
|
476
|
-
output = Document.updateGradle(output, ['android'], kotlin ? `compileSdk(${
|
|
564
|
+
const [compileSdk, targetSdk] = typeof targetAPI === 'string' ? [`"android-${targetAPI}"`, `"${targetAPI}"`] : [targetAPI, targetAPI];
|
|
565
|
+
const updateOnly = +targetAPI >= 33;
|
|
566
|
+
let content = Document.updateGradle(output, ['android'], kotlin ? `compileSdkVersion(${compileSdk})` : 'compileSdkVersion ' + compileSdk, { upgrade: true, updateOnly });
|
|
567
|
+
if (content === output) {
|
|
568
|
+
output = Document.updateGradle(output, ['android'], kotlin ? `compileSdk(${compileSdk})` : 'compileSdk ' + compileSdk, true);
|
|
477
569
|
}
|
|
478
570
|
else {
|
|
479
|
-
output =
|
|
571
|
+
output = content;
|
|
480
572
|
}
|
|
481
|
-
|
|
482
|
-
if (
|
|
483
|
-
output = Document.updateGradle(output, ['android', 'defaultConfig'], kotlin ? `targetSdk(${
|
|
573
|
+
content = Document.updateGradle(output, ['android', 'defaultConfig'], kotlin ? `targetSdkVersion(${targetSdk})` : 'targetSdkVersion ' + targetSdk, { upgrade: true, updateOnly });
|
|
574
|
+
if (content === output) {
|
|
575
|
+
output = Document.updateGradle(output, ['android', 'defaultConfig'], kotlin ? `targetSdk(${targetSdk})` : 'targetSdk ' + targetSdk, true);
|
|
484
576
|
}
|
|
485
577
|
else {
|
|
486
|
-
output =
|
|
578
|
+
output = content;
|
|
487
579
|
}
|
|
488
580
|
const version = instance.findVersion('buildToolsVersion');
|
|
489
581
|
if (version) {
|
|
@@ -536,7 +628,7 @@ function finalize(instance) {
|
|
|
536
628
|
}
|
|
537
629
|
if (modified || !existing) {
|
|
538
630
|
try {
|
|
539
|
-
if (instance.writeFile(localUri, source, { encoding: '
|
|
631
|
+
if (instance.writeFile(localUri, source, { encoding: 'utf8', ownPermissionOnly: true, throwsPermission: true }) && !existing) {
|
|
540
632
|
this.add(localUri);
|
|
541
633
|
}
|
|
542
634
|
}
|
|
@@ -546,17 +638,11 @@ function finalize(instance) {
|
|
|
546
638
|
}
|
|
547
639
|
}
|
|
548
640
|
if (!existing) {
|
|
549
|
-
const
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
catch (err) {
|
|
557
|
-
this.writeFail(["Unable to write file", path.basename(template.localUri)], err, 8192);
|
|
558
|
-
}
|
|
559
|
-
}
|
|
641
|
+
const detect = instance.detect(this);
|
|
642
|
+
const template = instance.findTemplate(this.baseDirectory, "build.gradle", { detect, languageOf: 'gradle', subDir: 'static' });
|
|
643
|
+
instance.writeTemplate(template, this);
|
|
644
|
+
const properties = instance.findTemplate(this.baseDirectory, "gradle.properties", { detect, subDir: [instance.languageOf('gradle') || 'java', 'static'] });
|
|
645
|
+
instance.writeTemplate(properties, this);
|
|
560
646
|
try {
|
|
561
647
|
const projectDir = instance.resolveDir('project');
|
|
562
648
|
if (projectDir) {
|
|
@@ -12,10 +12,10 @@ function finalize(instance) {
|
|
|
12
12
|
const targetName = projectName?.replace(/"/g, '\\"');
|
|
13
13
|
let modified = false;
|
|
14
14
|
if (existing) {
|
|
15
|
-
let match;
|
|
16
15
|
if (dependencies) {
|
|
17
16
|
found: {
|
|
18
17
|
const pattern = kotlin ? /^\s*include\(((?:\s*"[^"]+"\s*,?\s*)+)\)/gm : /^\s*include\s*((?:(?:"[^"]+"|'[^']+')\s*,?\s*)+)/gm;
|
|
18
|
+
let match;
|
|
19
19
|
while (match = pattern.exec(source)) {
|
|
20
20
|
const namespace = /":?([^"]+)"|':?([^']+)'/g;
|
|
21
21
|
let app;
|
|
@@ -40,7 +40,8 @@ function finalize(instance) {
|
|
|
40
40
|
}
|
|
41
41
|
if (targetName) {
|
|
42
42
|
const value = `rootProject.name = "${targetName}"`;
|
|
43
|
-
|
|
43
|
+
const match = new RegExp('^\\s*rootProject\\.name\\s*=\\s*' + parse_1.XmlWriter.PATTERN_QUOTEVALUE, 'm').exec(source);
|
|
44
|
+
if (match) {
|
|
44
45
|
source = parse_1.XmlWriter.replaceMatch(match, source, value);
|
|
45
46
|
}
|
|
46
47
|
else {
|
|
@@ -66,7 +67,7 @@ function finalize(instance) {
|
|
|
66
67
|
}
|
|
67
68
|
if (modified || !existing) {
|
|
68
69
|
try {
|
|
69
|
-
if (instance.writeFile(localUri, source, { encoding: '
|
|
70
|
+
if (instance.writeFile(localUri, source, { encoding: 'utf8', ownPermissionOnly: true, throwsPermission: true }) && !existing) {
|
|
70
71
|
this.add(localUri);
|
|
71
72
|
}
|
|
72
73
|
}
|
package/extensions/task/index.js
CHANGED
|
@@ -40,7 +40,7 @@ async function finalize(instance) {
|
|
|
40
40
|
if (!command.includes(path.sep)) {
|
|
41
41
|
filename = checkWin32(command);
|
|
42
42
|
}
|
|
43
|
-
command =
|
|
43
|
+
command = (0, types_1.sanitizeCmd)(command);
|
|
44
44
|
}
|
|
45
45
|
else {
|
|
46
46
|
filename = checkWin32("gradlew");
|
|
@@ -64,7 +64,7 @@ async function finalize(instance) {
|
|
|
64
64
|
else if (altname) {
|
|
65
65
|
const bin = which.sync(altname, { nothrow: true });
|
|
66
66
|
if (bin) {
|
|
67
|
-
command =
|
|
67
|
+
command = (0, types_1.sanitizeCmd)(bin);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -89,7 +89,7 @@ async function finalize(instance) {
|
|
|
89
89
|
await new Promise((resolve, reject) => {
|
|
90
90
|
this.formatMessage(4, title, ['Executing task...', task], baseDirectory);
|
|
91
91
|
let out = '', message = '';
|
|
92
|
-
const { stdout, stderr } = child_process.spawn(command,
|
|
92
|
+
const { stdout, stderr } = child_process.spawn(command, (0, types_1.sanitizeArgs)(args), { cwd: baseDirectory, shell: true, stdio: Document.hasLogType(32768) && !broadcastId ? 'inherit' : undefined, signal: instance.signal, uid, gid })
|
|
93
93
|
.on('exit', code => {
|
|
94
94
|
if (!code) {
|
|
95
95
|
instance.addLog(types_1.STATUS_TYPE.INFO, out);
|
|
@@ -102,7 +102,7 @@ async function finalize(instance) {
|
|
|
102
102
|
})
|
|
103
103
|
.on('error', reject);
|
|
104
104
|
if (stdout) {
|
|
105
|
-
stdout.setEncoding('
|
|
105
|
+
stdout.setEncoding('utf8').on('data', (value) => {
|
|
106
106
|
if (broadcastId) {
|
|
107
107
|
this.formatMessage(types_1.STATUS_TYPE.INFO, '', value, null, { sessionId: '' });
|
|
108
108
|
}
|
|
@@ -110,7 +110,7 @@ async function finalize(instance) {
|
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
112
|
if (stderr) {
|
|
113
|
-
stderr.setEncoding('
|
|
113
|
+
stderr.setEncoding('utf8').on('data', (value) => {
|
|
114
114
|
if (broadcastId) {
|
|
115
115
|
this.formatMessage(types_1.STATUS_TYPE.ERROR, '', value, null, { sessionId: '' });
|
|
116
116
|
}
|
package/index.js
CHANGED
|
@@ -3,7 +3,9 @@ const fs = require("node:fs");
|
|
|
3
3
|
const path = require("node:path");
|
|
4
4
|
const types_1 = require("@e-mc/types");
|
|
5
5
|
const Document = require('@e-mc/document');
|
|
6
|
+
const kAndroid = Symbol.for('android:constructor');
|
|
6
7
|
class AndroidDocument extends Document {
|
|
8
|
+
static [kAndroid] = true;
|
|
7
9
|
static async finalize(instance) {
|
|
8
10
|
if (instance.aborted) {
|
|
9
11
|
return (0, types_1.createAbortError)(true);
|
|
@@ -47,6 +49,7 @@ class AndroidDocument extends Document {
|
|
|
47
49
|
dependencies: undefined,
|
|
48
50
|
dependencyScopes: undefined,
|
|
49
51
|
versionCatalog: undefined,
|
|
52
|
+
libraries: undefined,
|
|
50
53
|
commands: undefined
|
|
51
54
|
};
|
|
52
55
|
elements = [];
|
|
@@ -57,7 +60,7 @@ class AndroidDocument extends Document {
|
|
|
57
60
|
_threadable = true;
|
|
58
61
|
init(assets, config) {
|
|
59
62
|
if (config) {
|
|
60
|
-
const { targetAPI, mainParentDir, mainSrcDir, mainActivityFile, javaVersion, jvmToolchain, projectName, versionName, versionCode = 0, manifest, namespace, applicationId, profileable, dependencies, dependencyScopes, versionCatalog, dataBinding, commands, directories, elements, extensionData } = config;
|
|
63
|
+
const { targetAPI, mainParentDir, mainSrcDir, mainActivityFile, javaVersion, jvmToolchain, projectName, versionName, versionCode = 0, manifest, namespace, applicationId, profileable, dependencies, dependencyScopes, versionCatalog, libraries, dataBinding, commands, directories, elements, extensionData } = config;
|
|
61
64
|
const target = this.config;
|
|
62
65
|
if (projectName) {
|
|
63
66
|
target.projectName = projectName;
|
|
@@ -110,6 +113,9 @@ class AndroidDocument extends Document {
|
|
|
110
113
|
if ((0, types_1.isArray)(dependencies)) {
|
|
111
114
|
target.dependencies = dependencies;
|
|
112
115
|
}
|
|
116
|
+
if ((0, types_1.isPlainObject)(libraries) && Object.keys(libraries).length > 0) {
|
|
117
|
+
target.libraries = libraries;
|
|
118
|
+
}
|
|
113
119
|
if (targetAPI) {
|
|
114
120
|
this.targetAPI = targetAPI;
|
|
115
121
|
}
|
|
@@ -165,10 +171,9 @@ class AndroidDocument extends Document {
|
|
|
165
171
|
case 'font/woff':
|
|
166
172
|
case 'font/woff2': {
|
|
167
173
|
const instance = host.loadModule('compress');
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
await instance.tryFile(buffer, localUri, options)
|
|
174
|
+
if (instance) {
|
|
175
|
+
const options = { format: 'ttf', etag: file.etag, worker: true };
|
|
176
|
+
await instance.tryFile(file.buffer || localUri, localUri, options)
|
|
172
177
|
.then(() => {
|
|
173
178
|
if (options.outFile) {
|
|
174
179
|
host.replace(file, options.outFile);
|
|
@@ -190,7 +195,8 @@ class AndroidDocument extends Document {
|
|
|
190
195
|
}
|
|
191
196
|
let kotlin = false, language;
|
|
192
197
|
if (languageOf) {
|
|
193
|
-
|
|
198
|
+
language = this.languageOf(languageOf);
|
|
199
|
+
kotlin = language === 'kotlin';
|
|
194
200
|
if (detect !== false) {
|
|
195
201
|
const isKts = this.detectKts(baseDir, filename);
|
|
196
202
|
if (isKts && language === 'java') {
|
|
@@ -220,7 +226,7 @@ class AndroidDocument extends Document {
|
|
|
220
226
|
if (!existing && !(uri = this.resolveDir('template', ...paths))) {
|
|
221
227
|
throw (0, types_1.errorValue)("File not found", uri);
|
|
222
228
|
}
|
|
223
|
-
return { localUri, source: fs.readFileSync(uri || localUri, '
|
|
229
|
+
return { localUri, source: fs.readFileSync(uri || localUri, 'utf8'), existing, kotlin, language };
|
|
224
230
|
}
|
|
225
231
|
catch (err) {
|
|
226
232
|
if (options?.throwsDoesNotExist !== false) {
|
|
@@ -229,11 +235,22 @@ class AndroidDocument extends Document {
|
|
|
229
235
|
}
|
|
230
236
|
return { kotlin, language };
|
|
231
237
|
}
|
|
238
|
+
writeTemplate(data, host = this.host) {
|
|
239
|
+
if (data.localUri && data.source && this.canWrite(data.localUri, { ownPermissionOnly: true }) && Document.createDir(path.dirname(data.localUri))) {
|
|
240
|
+
try {
|
|
241
|
+
fs.writeFileSync(data.localUri, data.source, 'utf8');
|
|
242
|
+
host?.add(data.localUri);
|
|
243
|
+
}
|
|
244
|
+
catch (err) {
|
|
245
|
+
(host || this).writeFail("Unable to write file", err, 32);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
232
249
|
findData(filename, format) {
|
|
233
250
|
let localUri;
|
|
234
251
|
try {
|
|
235
252
|
if (localUri = this.resolveDir('data', filename)) {
|
|
236
|
-
return this.tryParse(fs.readFileSync(localUri, '
|
|
253
|
+
return this.tryParse(fs.readFileSync(localUri, 'utf8'), format || path.extname(localUri).substring(1));
|
|
237
254
|
}
|
|
238
255
|
}
|
|
239
256
|
catch (err) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pi-r/android",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Android document constructor for E-mc.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"homepage": "https://github.com/anpham6/pi-r#readme",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@e-mc/document": "^0.
|
|
24
|
-
"@e-mc/types": "^0.
|
|
23
|
+
"@e-mc/document": "^0.12.0",
|
|
24
|
+
"@e-mc/types": "^0.12.0",
|
|
25
25
|
"dom-serializer": "*",
|
|
26
26
|
"domhandler": "*",
|
|
27
27
|
"domutils": "*",
|
|
28
|
-
"htmlparser2": "^
|
|
28
|
+
"htmlparser2": "^10.0.0",
|
|
29
29
|
"which": "^4.0.0"
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
distributionBase=GRADLE_USER_HOME
|
|
2
2
|
distributionPath=wrapper/dists
|
|
3
|
-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.
|
|
3
|
+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
|
|
4
4
|
zipStoreBase=GRADLE_USER_HOME
|
|
5
|
-
zipStorePath=wrapper/dists
|
|
5
|
+
zipStorePath=wrapper/dists
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
|
2
|
+
|
|
3
|
+
# org.gradle.configuration-cache=false
|
|
4
|
+
# org.gradle.jvmargs=-Xmx512m "-XX:MaxMetaspaceSize=384m"
|
|
5
|
+
# org.gradle.caching=false
|
|
6
|
+
# org.gradle.continue=false
|
|
7
|
+
# org.gradle.daemon=true
|
|
8
|
+
# org.gradle.parallel=false
|
|
9
|
+
# org.gradle.warning.mode=summary
|
|
10
|
+
|
|
11
|
+
# android.useAndroidX=false
|
|
12
|
+
# android.nonFinalResIds=true
|
|
13
|
+
# android.nonTransitiveRClass=true
|
|
14
|
+
# android.enableR8.fullMode=true
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
plugins {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
alias libs.plugins.android.application
|
|
3
|
+
alias libs.plugins.kotlin.android
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
android {
|
|
@@ -34,11 +34,14 @@ android {
|
|
|
34
34
|
buildFeatures {
|
|
35
35
|
viewBinding true
|
|
36
36
|
}
|
|
37
|
+
lintOptions {
|
|
38
|
+
checkDependencies false
|
|
39
|
+
}
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
dependencies {
|
|
40
|
-
implementation
|
|
41
|
-
testImplementation
|
|
42
|
-
androidTestImplementation
|
|
43
|
-
androidTestImplementation
|
|
43
|
+
implementation libs.androidx.core.ktx
|
|
44
|
+
testImplementation libs.junit
|
|
45
|
+
androidTestImplementation libs.androidx.junit
|
|
46
|
+
androidTestImplementation libs.androidx.espresso.core
|
|
44
47
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
[versions]
|
|
2
|
+
agp = "8.9.2"
|
|
3
|
+
kotlin = "2.1.20"
|
|
4
|
+
coreKtx = "1.16.0"
|
|
5
|
+
junit = "4.13.2"
|
|
6
|
+
junitVersion = "1.2.1"
|
|
7
|
+
espressoCore = "3.6.1"
|
|
8
|
+
|
|
9
|
+
[libraries]
|
|
10
|
+
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
|
11
|
+
junit = { group = "junit", name = "junit", version.ref = "junit" }
|
|
12
|
+
androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
|
|
13
|
+
androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
|
|
14
|
+
|
|
15
|
+
[plugins]
|
|
16
|
+
android-application = { id = "com.android.application", version.ref = "agp" }
|
|
17
|
+
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
plugins {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
id 'org.jetbrains.kotlin.android' version '2.1.20' apply false
|
|
2
|
+
alias libs.plugins.android.application apply false
|
|
3
|
+
alias libs.plugins.kotlin.android apply false
|
|
5
4
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
|
2
|
+
|
|
3
|
+
org.gradle.configuration-cache=true
|
|
4
|
+
# org.gradle.jvmargs=-Xmx2048m
|
|
5
|
+
# org.gradle.caching=false
|
|
6
|
+
# org.gradle.continue=false
|
|
7
|
+
# org.gradle.daemon=true
|
|
8
|
+
# org.gradle.parallel=false
|
|
9
|
+
# org.gradle.warning.mode=summary
|
|
10
|
+
|
|
11
|
+
android.useAndroidX=true
|
|
12
|
+
# android.nonFinalResIds=true
|
|
13
|
+
# android.nonTransitiveRClass=true
|
|
14
|
+
# android.enableR8.fullMode=true
|
|
15
|
+
|
|
16
|
+
# kotlin.code.style=official
|
|
@@ -31,6 +31,9 @@ android {
|
|
|
31
31
|
buildFeatures {
|
|
32
32
|
viewBinding = true
|
|
33
33
|
}
|
|
34
|
+
lint {
|
|
35
|
+
isCheckDependencies = false
|
|
36
|
+
}
|
|
34
37
|
}
|
|
35
38
|
|
|
36
39
|
java {
|
|
@@ -43,6 +46,7 @@ dependencies {
|
|
|
43
46
|
implementation(libs.androidx.core.ktx)
|
|
44
47
|
implementation(libs.androidx.appcompat)
|
|
45
48
|
implementation(libs.androidx.constraintlayout)
|
|
49
|
+
implementation(libs.android.material)
|
|
46
50
|
testImplementation(libs.junit)
|
|
47
51
|
androidTestImplementation(libs.androidx.junit)
|
|
48
52
|
androidTestImplementation(libs.androidx.espresso.core)
|