@pi-r/android 0.3.1 → 0.6.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.
@@ -142,27 +142,26 @@ function finalize(instance) {
142
142
  return;
143
143
  }
144
144
  const app = domutils.findOne(elem => elem.tagName === 'application', dom, true);
145
- if (!app) {
146
- return;
147
- }
148
- for (const { name, resource, value } of metaData) {
149
- if (name && (resource || value)) {
150
- let item = domutils.findOne(elem => elem.tagName === 'meta-data' && elem.attribs['android:name'] === name, app.childNodes);
151
- if (!item) {
152
- domutils.appendChild(app, item = new domhandler.Element('meta-data', { 'android:name': name }));
153
- domutils.append(item, new domhandler.Text('\n'));
154
- }
155
- else if (item.attribs['android:resource'] === resource || item.attribs['android:value'] === value) {
156
- continue;
157
- }
158
- if (resource) {
159
- item.attribs['android:resource'] = resource;
160
- }
161
- if (value) {
162
- item.attribs['android:value'] = value;
145
+ if (app) {
146
+ for (const { name, resource, value } of metaData) {
147
+ if (name && (resource || value)) {
148
+ let item = domutils.findOne(elem => elem.tagName === 'meta-data' && elem.attribs['android:name'] === name, app.childNodes);
149
+ if (!item) {
150
+ domutils.appendChild(app, item = new domhandler.Element('meta-data', { 'android:name': name }));
151
+ domutils.append(item, new domhandler.Text('\n'));
152
+ }
153
+ else if (item.attribs['android:resource'] === resource || item.attribs['android:value'] === value) {
154
+ continue;
155
+ }
156
+ if (resource) {
157
+ item.attribs['android:resource'] = resource;
158
+ }
159
+ if (value) {
160
+ item.attribs['android:value'] = value;
161
+ }
162
+ source = domserializer.default(dom, { xmlMode: true });
163
+ modified = true;
163
164
  }
164
- source = domserializer.default(dom, { xmlMode: true });
165
- modified = true;
166
165
  }
167
166
  }
168
167
  }), { xmlMode: true, decodeEntities: false }).end(source);
@@ -4,6 +4,30 @@ const path = require("path");
4
4
  const util_1 = require("@e-mc/document/util");
5
5
  const types_1 = require("@e-mc/types");
6
6
  const Document = require("@e-mc/document");
7
+ const REGEXP_SEMVER = /^((\s*,\s*)?[([\]]((\s*,\s*)?\d+\.\d+(\s*,\s*)?)+[)\][])+$/;
8
+ function isUpgrade(version, pending) {
9
+ if (REGEXP_SEMVER.test(pending)) {
10
+ return true;
11
+ }
12
+ if (!REGEXP_SEMVER.test(version)) {
13
+ const previous = version.split(/[.-]/);
14
+ const current = pending.split(/[.-]/);
15
+ for (let i = 0; i < previous.length; ++i) {
16
+ const a = parseInt(previous[i]);
17
+ const b = parseInt(current[i]);
18
+ if (isNaN(a) && isNaN(b)) {
19
+ continue;
20
+ }
21
+ if (isNaN(a) || b > a) {
22
+ return true;
23
+ }
24
+ if (isNaN(b) || b < a) {
25
+ break;
26
+ }
27
+ }
28
+ }
29
+ return false;
30
+ }
7
31
  function finalize(instance) {
8
32
  const config = instance.config;
9
33
  const { profileable, dependencies, dataBinding, versionName, versionCode } = config;
@@ -13,7 +37,7 @@ function finalize(instance) {
13
37
  const detect = this.incremental !== 'staging';
14
38
  let { localUri, source, existing, kotlin } = instance.findTemplate(path.join(this.baseDirectory, config.mainParentDir), "build.gradle" /* GRADLE.FILENAME */, { detect, languageOf: 'gradle' });
15
39
  if (localUri && source && instance.canWrite(localUri, { ownPermissionOnly: true })) {
16
- let { namespace, javaVersion } = config, jvmTarget, modified;
40
+ let { namespace, javaVersion, dependencyScopes } = config, jvmTarget, modified;
17
41
  const upgrade = javaVersion > 0;
18
42
  const setModified = (output) => {
19
43
  if (output !== source) {
@@ -22,24 +46,175 @@ function finalize(instance) {
22
46
  }
23
47
  };
24
48
  if (dependencies) {
25
- const items = dependencies.map(item => item.split(':'));
26
- if (!kotlin && items.some(value => value[1].endsWith('-ktx'))) {
49
+ let data;
50
+ const hasScope = (value) => (0, types_1.isArray)(dependencyScopes) && dependencyScopes.includes(value) || dependencyScopes === value;
51
+ const snapshot = hasScope('snapshot');
52
+ const getData = () => data || (data = instance.findData('google-maven' + (snapshot ? '-snapshot' : '') + '.json', 'json'));
53
+ const items = dependencies.map(item => {
54
+ let [groupId, artifactId, version, type] = item.split(':');
55
+ if (!version || version === 'maven') {
56
+ const maven = getData();
57
+ let artifact;
58
+ if (maven && (artifact = maven[groupId]?.find(child => child.artifactId === artifactId))) {
59
+ version = artifact.version;
60
+ }
61
+ else {
62
+ version = '';
63
+ }
64
+ }
65
+ return [groupId, artifactId, version || (snapshot ? 'latest.integration' : 'latest.release'), type];
66
+ });
67
+ if (dependencyScopes && (data = getData())) {
68
+ const supplement = [];
69
+ for (const item of items) {
70
+ const [gId, id] = item;
71
+ const target = data[gId]?.find(group => id === group.artifactId);
72
+ if (!target) {
73
+ continue;
74
+ }
75
+ if (target.dependencies) {
76
+ let found;
77
+ for (const { groupId, artifactId, version, scope } of target.dependencies) {
78
+ if (scope && (dependencyScopes === true || hasScope(scope))) {
79
+ let type = -1;
80
+ switch (scope) {
81
+ case 'compile':
82
+ type = 0 /* DEPENDENCY_TYPE.IMPLEMENTATION */;
83
+ break;
84
+ case 'provided':
85
+ type = 2 /* DEPENDENCY_TYPE.COMPILE_ONLY */;
86
+ break;
87
+ case 'runtime':
88
+ type = 4 /* DEPENDENCY_TYPE.RUNTIME_ONLY */;
89
+ break;
90
+ case 'test':
91
+ type = 5 /* DEPENDENCY_TYPE.TEST_IMPLEMENTATION */;
92
+ break;
93
+ }
94
+ if (type !== -1) {
95
+ const current = supplement.find(seg => seg[0] === groupId && seg[1] === artifactId);
96
+ if (current) {
97
+ const t = parseInt(current[3]);
98
+ if (t !== type) {
99
+ const rangeVer = REGEXP_SEMVER.test(version);
100
+ if (!REGEXP_SEMVER.test(current[2])) {
101
+ if (rangeVer || type < t) {
102
+ current[2] = version;
103
+ found = true;
104
+ }
105
+ }
106
+ else if (rangeVer && type < t) {
107
+ current[2] = version;
108
+ found = true;
109
+ }
110
+ current[3] = '0';
111
+ }
112
+ else if (isUpgrade(current[2], version)) {
113
+ current[2] = version;
114
+ found = true;
115
+ }
116
+ }
117
+ else {
118
+ supplement.push([groupId, artifactId, version, type.toString()]);
119
+ found = true;
120
+ }
121
+ }
122
+ }
123
+ }
124
+ if (found && (snapshot || isUpgrade(item[2], target.version))) {
125
+ item[2] = target.version;
126
+ }
127
+ }
128
+ break;
129
+ }
130
+ for (const item of supplement) {
131
+ const [groupId, artifactId] = item;
132
+ const index = items.findIndex(seg => seg[0] === groupId && seg[1] === artifactId);
133
+ if (index === -1) {
134
+ items.push(item);
135
+ }
136
+ else if (snapshot) {
137
+ item[3] = items[index][3];
138
+ items[index] = item;
139
+ }
140
+ }
141
+ }
142
+ items.sort((a, b) => {
143
+ const tA = parseInt(a[3]) || 0;
144
+ const tB = parseInt(b[3]) || 0;
145
+ if (tA !== tB) {
146
+ return tA - tB;
147
+ }
148
+ const gA = a[0];
149
+ const gB = b[0];
150
+ if (gA !== gB) {
151
+ return gA < gB ? -1 : 1;
152
+ }
153
+ return a[1] < b[1] ? -1 : 1;
154
+ });
155
+ if (!kotlin && items.some(seg => seg[1].endsWith('-ktx'))) {
27
156
  setModified(Document.updateGradle(source, ['plugins'], "id 'kotlin-android'", { multiple: true }));
28
157
  }
29
- const match = /dependencies\s+\{((?:{[^}]*}|(?![{}])[\S\s])+)\}/.exec(source);
158
+ const match = /dependencies\s+\{((?:{[^{]*{|{[^}]*}|}[^}]*}|\\}*?|[^{}+])+)\}/.exec(source);
30
159
  if (match) {
31
- const writeImpl = (item) => 'implementation' + (kotlin ? `("${item.join(':')}")` : ` '${item.join(':')}'`);
32
- const pattern = kotlin ? /([ \t]*)implementation\((?:\s*"([^"]+)"\s*\))?/g : /([ \t]*)implementation(?:\s*\(?\s*["']([^"']+)["']\s*\)?|\s+((?:\s*(?:group|name|version)\s*:\s*["'][^"']+["']\s*,?){3}))?/g;
33
- let content = match[1], indent, impl;
34
- while (impl = pattern.exec(match[1])) {
160
+ const pattern = kotlin ? /([ \t]*)(implementation|api|compileOnly(?:Api)?|runtimeOnly|(?:test|androidTest)(?:Implementation|RuntimeOnly|CompileOnly))\((?:\s*(?:"([^"]+)"|((?:\s*(?:group|name|version)\s*=\s*"[^"]+"\s*,?){3}))\s*\))?/g : /([ \t]*)(implementation|api|compileOnly(?:Api)?|runtimeOnly|(?:test|androidTest)(?:Implementation|RuntimeOnly|CompileOnly))(?:\s*\(?\s*["']([^"']+)["']\s*\)?|\s+((?:\s*(?:group|name|version)\s*:\s*["'][^"']+["']\s*,?){3}))?/g;
161
+ let content = match[1], named = false, indent, method;
162
+ const writeMethod = (item, args, prefix = 'implementation') => {
163
+ switch (parseInt(item[3])) {
164
+ case 0 /* DEPENDENCY_TYPE.IMPLEMENTATION */:
165
+ prefix = 'implementation';
166
+ break;
167
+ case 1 /* DEPENDENCY_TYPE.API */:
168
+ prefix = 'api';
169
+ break;
170
+ case 2 /* DEPENDENCY_TYPE.COMPILE_ONLY */:
171
+ prefix = 'compileOnly';
172
+ break;
173
+ case 3 /* DEPENDENCY_TYPE.COMPILE_ONLY_API */:
174
+ prefix = 'compileOnlyApi';
175
+ break;
176
+ case 4 /* DEPENDENCY_TYPE.RUNTIME_ONLY */:
177
+ prefix = 'runtimeOnly';
178
+ break;
179
+ case 5 /* DEPENDENCY_TYPE.TEST_IMPLEMENTATION */:
180
+ prefix = 'testImplementation';
181
+ break;
182
+ case 6 /* DEPENDENCY_TYPE.TEST_COMPILE_ONLY */:
183
+ prefix = 'testCompileOnly';
184
+ break;
185
+ case 7 /* DEPENDENCY_TYPE.TEST_RUNTIME_ONLY */:
186
+ prefix = 'testRuntimeOnly';
187
+ break;
188
+ case 8 /* DEPENDENCY_TYPE.ANDROID_TEST_IMPLEMENTATION */:
189
+ prefix = 'androidTestImplementation';
190
+ break;
191
+ case 9 /* DEPENDENCY_TYPE.ANDROID_TEST_COMPILE_ONLY */:
192
+ prefix = 'androidTestCompileOnly';
193
+ break;
194
+ case 10 /* DEPENDENCY_TYPE.ANDROID_TEST_RUNTIME_ONLY */:
195
+ prefix = 'androidTestRuntimeOnly';
196
+ break;
197
+ }
198
+ let dependency;
199
+ if (args || named) {
200
+ const [group, name, version] = item;
201
+ dependency = kotlin ? `(group = "${group}", name = "${name}", version = "${version}")` : ` group: '${group}', name: '${name}', version: '${version}'` + (args?.endsWith(',') ? ',' : '');
202
+ }
203
+ else {
204
+ dependency = item.slice(0, 3).join(':');
205
+ dependency = kotlin ? `("${dependency}")` : ` '${dependency}'`;
206
+ }
207
+ return prefix + dependency;
208
+ };
209
+ while (method = pattern.exec(match[1])) {
35
210
  let group, name, version;
36
- if (impl[2]) {
37
- [group, name, version] = impl[2].trim().split(/\s*:\s*/);
211
+ if (method[3]) {
212
+ [group, name, version] = method[3].trim().split(/\s*:\s*/);
38
213
  }
39
- else if (impl[3]) {
40
- const method = /(group|name|version)\s*:\s*["']([^"']+)["']/g;
214
+ else if (method[4]) {
215
+ const params = /(group|name|version)\s*[=:]\s*["']([^"']+)["']/g;
41
216
  let param;
42
- while (param = method.exec(impl[3])) {
217
+ while (param = params.exec(method[4])) {
43
218
  const value = param[2].trim();
44
219
  switch (param[1]) {
45
220
  case 'group':
@@ -53,66 +228,45 @@ function finalize(instance) {
53
228
  break;
54
229
  }
55
230
  }
231
+ named = true;
56
232
  }
57
233
  if (group && name) {
58
234
  let found = 0, index = -1;
59
235
  if (version && (index = items.findIndex(seg => seg[0] === group && seg[1] === name)) !== -1) {
60
- found = 1;
61
- if (version[0] !== '$' || !kotlin && impl[0].indexOf("'") !== -1) {
62
- const semver = /^((\s*,\s*)?[([\]]((\s*,\s*)?\d+\.\d+(\s*,\s*)?)+[)\][])+$/;
63
- const pending = items[index][2];
64
- if (semver.test(pending)) {
65
- found = 2;
66
- }
67
- else if (!semver.test(version)) {
68
- const getArray = (value) => value.split(/[.-]/).map(seg => +seg);
69
- const current = getArray(pending);
70
- const previous = getArray(version);
71
- for (let i = 0; i < previous.length; ++i) {
72
- const a = previous[i];
73
- const b = current[i];
74
- if (isNaN(a) || b > a) {
75
- found = 2;
76
- break;
77
- }
78
- if (isNaN(b) || b < a) {
79
- break;
80
- }
81
- }
82
- }
83
- }
236
+ found = (!version.startsWith('$') || !kotlin && method[0].includes("'")) && isUpgrade(version, items[index][2]) ? 2 : 1;
84
237
  }
85
238
  if (found) {
86
239
  if (found === 2) {
87
- content = content.replace(impl[0].trim(), writeImpl(items[index]));
240
+ content = content.replace(method[0].trim(), writeMethod(items[index], method[4], method[2]));
88
241
  modified = true;
89
242
  }
90
243
  items.splice(index, 1);
91
244
  }
92
245
  }
93
- if (impl[1]) {
94
- indent = impl[1];
246
+ if (method[1]) {
247
+ indent = method[1];
95
248
  }
96
249
  }
97
250
  if (items.length) {
251
+ const newline = process.platform === 'win32' ? '\r\n' : '\n';
98
252
  indent || (indent = (0, util_1.getIndent)(source));
99
- content = items.reduce((a, b) => a + indent + writeImpl(b) + '\n', content);
253
+ content = items.reduce((a, b) => a + indent + writeMethod(b) + newline, content);
100
254
  modified = true;
101
255
  }
102
256
  if (modified || !existing) {
103
257
  setModified(source.substring(0, match.index) + `dependencies {${content}}` + source.substring(match.index + match[0].length));
104
258
  }
105
259
  }
106
- if (items.some(value => value[0] === 'androidx.compose.ui')) {
260
+ if (items.some(seg => seg[0] === 'androidx.compose.ui')) {
107
261
  let output = source;
108
262
  if (kotlin) {
109
263
  output = Document.updateGradle(output, ['plugins'], 'kotlin("android")');
110
264
  output = Document.updateGradle(output, ['android', 'buildFeatures'], 'compose = true');
111
265
  }
112
266
  else {
113
- output = Document.updateGradle(output, ['plugins'], "id 'org.jetbrains.kotlin.android'", { upgrade: true, multiple: true, addendum: `version '${instance.findVersion('org.jetbrains.kotlin:kotlin-stdlib', "1.9.10" /* VERSIONS.KOTLIN_STDLIB */)}'` });
267
+ output = Document.updateGradle(output, ['plugins'], "id 'org.jetbrains.kotlin.android'", { upgrade: true, multiple: true, addendum: `version '${instance.findVersion('org.jetbrains.kotlin:kotlin-stdlib', "1.9.21" /* VERSIONS.KOTLIN_STDLIB */)}'` });
114
268
  output = Document.updateGradle(output, ['android', 'buildFeatures'], "compose true");
115
- output = Document.updateGradle(output, ['android', 'composeOptions'], `kotlinCompilerExtensionVersion '${instance.findVersion('kotlinCompilerExtensionVersion', "1.5.5" /* VERSIONS.KOTLIN_COMPILER */)}'`, true);
269
+ output = Document.updateGradle(output, ['android', 'composeOptions'], `kotlinCompilerExtensionVersion '${instance.findVersion('kotlinCompilerExtensionVersion', "1.5.7" /* VERSIONS.KOTLIN_COMPILER */)}'`, true);
116
270
  if (upgrade) {
117
271
  output = Document.updateGradle(output, ['android', 'kotlinOptions'], `jvmTarget = '${javaVersion}'`, true);
118
272
  }
@@ -8,7 +8,7 @@ function finalize(instance) {
8
8
  if (!dependencies && !projectName) {
9
9
  return;
10
10
  }
11
- let { localUri, source, existing, kotlin } = instance.findTemplate(this.baseDirectory, 'settings.gradle', { detect: this.incremental !== 'staging', languageOf: 'gradle' });
11
+ let { localUri, source, existing, kotlin } = instance.findTemplate(this.baseDirectory, "settings.gradle" /* GRADLE.FILENAME */, { detect: this.incremental !== 'staging', languageOf: 'gradle' });
12
12
  if (localUri && source && instance.canWrite(localUri, { ownPermissionOnly: true })) {
13
13
  let targetName = projectName?.replace(/"/g, '\\"'), modified;
14
14
  if (existing) {
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const path = require("path");
4
4
  const fs = require("fs");
5
5
  const child_process = require("child_process");
6
+ const which = require("which");
6
7
  const types_1 = require("@e-mc/types");
7
8
  const Document = require("@e-mc/document");
8
9
  const checkWin32 = (value) => value === "gradlew" /* STRINGS.GRADLEW */ && process.platform === 'win32' ? value + '.bat' : value;
@@ -28,15 +29,14 @@ async function finalize(instance) {
28
29
  }
29
30
  const settings = instance.settings.extensions?.task || {};
30
31
  const exec = settings.exec;
31
- let { broadcastId, baseDirectory } = this, command = settings.command, uid, gid, title, filename, foundCwd;
32
+ let { broadcastId, baseDirectory } = this, command = settings.command, uid, gid, title, filename, altname, foundDir;
32
33
  if (command) {
33
- if (command.indexOf('mvn') !== -1) {
34
- title = 'maven';
34
+ if (command.includes('mvn')) {
35
+ title = "maven" /* STRINGS.MAVEN */;
35
36
  }
36
37
  else {
37
- title = /([^\\/]+?)(?:\.[a-z]+)?$/i.exec(command)?.[1] || 'SPAWN';
38
+ title = /([^\\/]+?)(?:\.[a-z]+)?$/i.exec(command)?.[1] || 'spawn';
38
39
  }
39
- command = path.normalize(command);
40
40
  if (!/[\\/]/.test(command = path.normalize(command))) {
41
41
  filename = checkWin32(command);
42
42
  }
@@ -45,21 +45,28 @@ async function finalize(instance) {
45
45
  else {
46
46
  filename = checkWin32("gradlew" /* STRINGS.GRADLEW */);
47
47
  command = '.' + path.sep + filename;
48
- title = 'gradle';
48
+ title = "gradle" /* STRINGS.GRADLE */;
49
+ altname = "gradle" /* STRINGS.GRADLE */;
49
50
  }
50
51
  if (filename) {
51
52
  try {
52
53
  let appDir = baseDirectory;
53
- while (!(foundCwd = fs.existsSync(path.join(appDir, filename)))) {
54
+ while (!(foundDir = fs.existsSync(path.join(appDir, filename)))) {
54
55
  const parent = path.dirname(appDir);
55
56
  if (parent === appDir) {
56
57
  break;
57
58
  }
58
59
  appDir = parent;
59
60
  }
60
- if (foundCwd) {
61
+ if (foundDir) {
61
62
  baseDirectory = appDir;
62
63
  }
64
+ else if (altname) {
65
+ const bin = which.sync(altname, { nothrow: true });
66
+ if (bin) {
67
+ command = Document.sanitizeCmd(bin);
68
+ }
69
+ }
63
70
  }
64
71
  catch {
65
72
  }
@@ -90,7 +97,7 @@ async function finalize(instance) {
90
97
  resolve();
91
98
  }
92
99
  else {
93
- reject((0, types_1.errorValue)(message || (!foundCwd && code === 1 ? "Unable to execute file" /* ERR_MESSAGE.EXECUTE_FILE */ : "Unknown" /* ERR_MESSAGE.UNKNOWN */), "Error code" /* ERR_MESSAGE.ERROR_CODE */ + ': ' + code));
100
+ reject((0, types_1.errorValue)(message || (!foundDir && code === 1 ? "Unable to execute file" /* ERR_MESSAGE.EXECUTE_FILE */ : "Unknown" /* ERR_MESSAGE.UNKNOWN */), "Error code" /* ERR_MESSAGE.ERROR_CODE */ + ': ' + code));
94
101
  }
95
102
  })
96
103
  .on('error', err => reject(err));
package/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import type { IFileManager } from '@e-mc/types/types/lib';
2
-
3
- import type { AndroidDocumentConstructor, DocumentAsset } from './types';
4
-
5
- declare const Android: AndroidDocumentConstructor<IFileManager<DocumentAsset>>;
6
-
1
+ import type { IFileManager } from '@e-mc/types/types/lib';
2
+
3
+ import type { AndroidDocumentConstructor, DocumentAsset } from './types';
4
+
5
+ declare const Android: AndroidDocumentConstructor<IFileManager<DocumentAsset>>;
6
+
7
7
  export = Android;
package/index.js CHANGED
@@ -21,6 +21,7 @@ class AndroidDocument extends Document {
21
21
  namespace: undefined,
22
22
  profileable: undefined,
23
23
  dependencies: undefined,
24
+ dependencyScopes: undefined,
24
25
  commands: undefined
25
26
  };
26
27
  this.elements = [];
@@ -56,7 +57,7 @@ class AndroidDocument extends Document {
56
57
  }
57
58
  init(assets, config) {
58
59
  if (config) {
59
- const { targetAPI, mainParentDir, mainSrcDir, mainActivityFile, javaVersion, projectName, versionName, versionCode = 0, manifest, namespace, profileable, dependencies, dataBinding, commands, directories, elements, extensionData } = config;
60
+ const { targetAPI, mainParentDir, mainSrcDir, mainActivityFile, javaVersion, projectName, versionName, versionCode = 0, manifest, namespace, profileable, dependencies, dependencyScopes, dataBinding, commands, directories, elements, extensionData } = config;
60
61
  const target = this.config;
61
62
  if (projectName) {
62
63
  target.projectName = projectName;
@@ -76,7 +77,7 @@ class AndroidDocument extends Document {
76
77
  if (versionName) {
77
78
  target.versionName = versionName;
78
79
  }
79
- if (manifest) {
80
+ if ((0, types_1.isPlainObject)(manifest)) {
80
81
  target.manifest = manifest;
81
82
  }
82
83
  if (profileable !== undefined) {
@@ -89,7 +90,7 @@ class AndroidDocument extends Document {
89
90
  target.commands = commands;
90
91
  }
91
92
  if (javaVersion) {
92
- target.javaVersion = +(typeof javaVersion === 'string' ? javaVersion.toString().replace(/_/g, '.') : javaVersion);
93
+ target.javaVersion = typeof javaVersion === 'string' ? +javaVersion.replace(/_/g, '.') : javaVersion;
93
94
  }
94
95
  if (dataBinding) {
95
96
  target.dataBinding = true;
@@ -97,6 +98,9 @@ class AndroidDocument extends Document {
97
98
  if ((0, types_1.isArray)(dependencies)) {
98
99
  target.dependencies = dependencies;
99
100
  }
101
+ if (dependencyScopes) {
102
+ target.dependencyScopes = dependencyScopes;
103
+ }
100
104
  if (targetAPI) {
101
105
  this.targetAPI = targetAPI;
102
106
  }
@@ -198,6 +202,18 @@ class AndroidDocument extends Document {
198
202
  }
199
203
  return { kotlin, language };
200
204
  }
205
+ findData(filename, format) {
206
+ let localUri;
207
+ if ((localUri = this.resolveDir('data', filename)) || Document.isPath(localUri = path.join(__dirname, 'data', filename))) {
208
+ try {
209
+ return this.tryParse(fs.readFileSync(localUri, 'utf-8'), format || path.extname(localUri).substring(1));
210
+ }
211
+ catch (err) {
212
+ this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, path.basename(localUri)], err, 32 /* LOG_TYPE.FILE */);
213
+ }
214
+ }
215
+ return null;
216
+ }
201
217
  detectKts(...paths) {
202
218
  try {
203
219
  const file = path.join(...paths);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pi-r/android",
3
- "version": "0.3.1",
3
+ "version": "0.6.0",
4
4
  "description": "Android document constructor for E-mc.",
5
5
  "main": "index.js",
6
6
  "publishConfig": {
@@ -20,8 +20,9 @@
20
20
  "license": "MIT",
21
21
  "homepage": "https://github.com/anpham6/pi-r#readme",
22
22
  "dependencies": {
23
- "@e-mc/document": "^0.6.0",
24
- "@e-mc/types": "^0.6.0",
25
- "htmlparser2": "^9.0.0"
23
+ "@e-mc/document": "^0.8.0",
24
+ "@e-mc/types": "^0.8.0",
25
+ "htmlparser2": "^9.0.0",
26
+ "which": "^2.0.2"
26
27
  }
27
28
  }
@@ -1,5 +1,5 @@
1
1
  plugins {
2
2
  id 'com.android.application' version '8.2.0' apply false
3
3
  id 'com.android.library' version '8.2.0' apply false
4
- id 'org.jetbrains.kotlin.android' version '1.9.10' apply false
4
+ id 'org.jetbrains.kotlin.android' version '1.9.21' apply false
5
5
  }
@@ -38,7 +38,7 @@ java {
38
38
  }
39
39
 
40
40
  dependencies {
41
- implementation("org.jetbrains.kotlin:kotlin-stdlib:1.9.10")
41
+ implementation("org.jetbrains.kotlin:kotlin-stdlib:1.9.21")
42
42
  implementation("androidx.core:core-ktx:1.12.0")
43
43
  testImplementation("junit:junit:4.13.2")
44
44
  androidTestImplementation("androidx.test.ext:junit:1.1.5")
@@ -1,5 +1,5 @@
1
1
  plugins {
2
2
  id("com.android.application") version "8.2.0" apply false
3
3
  id("com.android.library") version "8.2.0" apply false
4
- id("org.jetbrains.kotlin.android") version "1.9.10" apply false
4
+ id("org.jetbrains.kotlin.android") version "1.9.21" apply false
5
5
  }
package/types/index.d.ts CHANGED
@@ -2,15 +2,15 @@ import type { FinalizedElement } from '@e-mc/types/lib/squared';
2
2
 
3
3
  import type { DocumentConstructor, IDocument, IFileManager } from '@e-mc/types/lib';
4
4
  import type { ExternalAsset } from '@e-mc/types/lib/asset';
5
- import type { DocumentDirectory as IDocumentDirectory, DocumentModule as IDocumentModule, ExecAction } from '@e-mc/types/lib/settings';
5
+ import type { DocumentModule as IDocumentModule, DocumentSettings as IDocumentSettings, ExecAction } from '@e-mc/types/lib/settings';
6
6
 
7
- import type { DocumentOutput } from './squared';
7
+ import type { DocumentOutput, MavenScopes } from './squared';
8
8
 
9
9
  interface DocumentDirectory extends IDocumentDirectory {
10
10
  template?: string;
11
11
  }
12
12
 
13
- interface AndroidDocumentSettings extends PlainObject {
13
+ interface AndroidDocumentSettings extends Pick<IDocumentSettings, "users" | "directory">, PlainObject {
14
14
  extensions?: {
15
15
  task?: {
16
16
  exec?: ExecAction;
@@ -20,7 +20,6 @@ interface AndroidDocumentSettings extends PlainObject {
20
20
  language?: {
21
21
  gradle?: "java" | "kotlin" | "java+kotlin";
22
22
  };
23
- directory?: DocumentDirectory;
24
23
  }
25
24
 
26
25
  type LanguageType = "gradle";
@@ -52,11 +51,20 @@ export interface FindTemplateOptions {
52
51
  subDir?: ArrayOf<string>;
53
52
  }
54
53
 
54
+ export interface MavenArtifact {
55
+ groupId: string;
56
+ artifactId: string;
57
+ version: string;
58
+ scope?: MavenScopes;
59
+ dependencies?: MavenArtifact[];
60
+ }
61
+
55
62
  export interface IAndroidDocument<T extends IFileManager<U>, U extends DocumentAsset = DocumentAsset> extends IDocument<T, U>, Pick<DocumentOutput, DocumentProperties> {
56
63
  config: UserConfig;
57
64
  elements: FinalizedElement[];
58
65
  extensionData: PlainObject;
59
66
  findTemplate(baseDir: string, filename: string, options?: FindTemplateOptions): TemplateData;
67
+ findData<V = AnyObject>(filename: string, format?: string): Null<V>;
60
68
  detectKts(...paths: string[]): Null<boolean>;
61
69
  get settings(): AndroidDocumentSettings;
62
70
  }
@@ -9,6 +9,7 @@ export interface DocumentOutput {
9
9
  namespace?: string;
10
10
  profileable?: boolean | StringOfArray;
11
11
  dependencies?: string[];
12
+ dependencyScopes?: boolean | ArrayOf<DependencyScopes | "snapshot">;
12
13
  directories?: ControllerSettingsDirectoryUI;
13
14
  elements?: FinalizedElement[];
14
15
  projectName?: string;
@@ -50,4 +51,6 @@ export interface ControllerSettingsDirectoryUI extends IControllerSettingsDirect
50
51
  main: string;
51
52
  animation: string;
52
53
  theme: string;
53
- }
54
+ }
55
+
56
+ export type DependencyScopes = "compile" | "provided" | "runtime" | "test";