@e-mc/document 0.0.1

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.
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const path = require("path");
4
+ const fs = require("fs");
5
+ const child_process = require("child_process");
6
+ const types_1 = require("../../../../types");
7
+ const module_1 = require("../../../../module");
8
+ async function finalize(instance) {
9
+ const commands = instance.config.commands;
10
+ if (!commands || this.archiving) {
11
+ return;
12
+ }
13
+ let taskArgs;
14
+ if (typeof commands === 'string') {
15
+ taskArgs = [[commands]];
16
+ }
17
+ else if ((0, types_1.isArray)(commands)) {
18
+ if (commands.every(value => typeof value === 'string')) {
19
+ taskArgs = [commands];
20
+ }
21
+ else {
22
+ taskArgs = commands.map(value => typeof value === 'string' ? [value] : value);
23
+ }
24
+ }
25
+ else {
26
+ return;
27
+ }
28
+ let { broadcastId, baseDirectory } = this, command = instance.settings.extensions?.task?.command, title, name, foundCwd;
29
+ if (command) {
30
+ if (command.indexOf('mvn') !== -1) {
31
+ title = 'maven';
32
+ }
33
+ else {
34
+ title = /([^\\/]+?)(?:\.[a-z]+)?$/i.exec(command)?.[1] || 'SPAWN';
35
+ }
36
+ command = path.normalize(command);
37
+ if (!command.includes(path.sep)) {
38
+ name = command;
39
+ }
40
+ command = module_1.default.sanitizeCmd(command);
41
+ }
42
+ else {
43
+ name = 'gradlew';
44
+ command = '.' + path.sep + name;
45
+ title = 'gradle';
46
+ }
47
+ if (name) {
48
+ try {
49
+ let appDir = baseDirectory;
50
+ while (!(foundCwd = fs.existsSync(path.join(appDir, name)))) {
51
+ const parent = path.dirname(appDir);
52
+ if (parent === appDir) {
53
+ break;
54
+ }
55
+ appDir = parent;
56
+ }
57
+ if (foundCwd) {
58
+ baseDirectory = appDir;
59
+ }
60
+ }
61
+ catch {
62
+ }
63
+ }
64
+ for (const args of taskArgs) {
65
+ if (instance.aborted) {
66
+ return Promise.reject((0, types_1.createAbortError)());
67
+ }
68
+ const startTime = process.hrtime();
69
+ const task = args.join(' ');
70
+ await new Promise((resolve, reject) => {
71
+ this.formatMessage(4 /* LOG_TYPE.PROCESS */, title, ['Executing task...', task], baseDirectory);
72
+ let out = '', message = '';
73
+ const { stdout, stderr } = child_process.spawn(command, module_1.default.sanitizeArgs(args), { cwd: baseDirectory, shell: true, stdio: module_1.default.hasLogType(32768 /* LOG_TYPE.STDOUT */) && !broadcastId ? 'inherit' : undefined, signal: instance.signal })
74
+ .on('exit', code => {
75
+ if (!code) {
76
+ instance.addLog(types_1.STATUS_TYPE.INFO, out);
77
+ this.writeTimeProcess(title, 'Success -> ' + task, startTime);
78
+ resolve();
79
+ }
80
+ else {
81
+ 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));
82
+ }
83
+ })
84
+ .on('error', err => reject(err));
85
+ if (stdout) {
86
+ stdout.setEncoding('utf-8').on('data', (value) => {
87
+ if (broadcastId) {
88
+ this.formatMessage(types_1.STATUS_TYPE.INFO, '', value, null, { sessionId: '' });
89
+ }
90
+ out += value;
91
+ });
92
+ }
93
+ if (stderr) {
94
+ stderr.setEncoding('utf-8').on('data', (value) => {
95
+ if (broadcastId) {
96
+ this.formatMessage(types_1.STATUS_TYPE.ERROR, '', value, null, { sessionId: '' });
97
+ }
98
+ message += value;
99
+ });
100
+ }
101
+ })
102
+ .catch(err => instance.writeFail(["Unable to perform task" /* ERR_MESSAGE.PERFORM_TASK */, command + ' ' + task], err, { type: 4 /* LOG_TYPE.PROCESS */, startTime }));
103
+ }
104
+ }
105
+ exports.default = finalize;
106
+
107
+ if (exports.default) {
108
+ module.exports = exports.default;
109
+ module.exports.default = exports.default;
110
+ }
@@ -0,0 +1,7 @@
1
+ import type { IFileManager } from '../../types/lib';
2
+
3
+ import type { AndroidDocumentConstructor, DocumentAsset } from './document';
4
+
5
+ declare const Android: AndroidDocumentConstructor<IFileManager<DocumentAsset>>;
6
+
7
+ export = Android;
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+ const types_1 = require("../../types");
6
+ const index_1 = require("../index");
7
+ class AndroidDocument extends index_1.default {
8
+ constructor() {
9
+ super(...arguments);
10
+ this.config = {
11
+ mainParentDir: 'app',
12
+ mainSrcDir: 'src/main',
13
+ mainActivityFile: '',
14
+ javaVersion: 0,
15
+ dataBinding: false,
16
+ projectName: undefined,
17
+ versionName: undefined,
18
+ versionCode: 0,
19
+ manifest: undefined,
20
+ namespace: undefined,
21
+ profileable: undefined,
22
+ dependencies: undefined,
23
+ commands: undefined
24
+ };
25
+ this.elements = [];
26
+ this.extensionData = {};
27
+ this._moduleName = 'android';
28
+ this._threadable = true;
29
+ }
30
+ static async finalize(instance) {
31
+ if (instance.aborted) {
32
+ return Promise.reject((0, types_1.createAbortError)());
33
+ }
34
+ if (instance.extensions.length) {
35
+ const config = instance.config;
36
+ const mainActivityFile = config.mainActivityFile;
37
+ if (mainActivityFile && !path.isAbsolute(mainActivityFile)) {
38
+ let pathname = /[\\/]/.test(mainActivityFile) && path.join(this.baseDirectory, mainActivityFile);
39
+ if (pathname && index_1.default.isPath(pathname)) {
40
+ config.mainActivityFile = pathname;
41
+ }
42
+ else {
43
+ const directories = [this.baseDirectory, config.mainParentDir, config.mainSrcDir];
44
+ do {
45
+ if (index_1.default.isPath(pathname = path.join(...directories.concat(mainActivityFile)))) {
46
+ config.mainActivityFile = pathname;
47
+ break;
48
+ }
49
+ directories.pop();
50
+ } while (directories.length);
51
+ }
52
+ }
53
+ }
54
+ return super.finalize.call(this, instance);
55
+ }
56
+ init(assets, config) {
57
+ if (config) {
58
+ const { targetAPI, mainParentDir, mainSrcDir, mainActivityFile, javaVersion, projectName, versionName, versionCode = 0, manifest, namespace, profileable, dependencies, dataBinding, commands, directories, elements, extensionData } = config;
59
+ const target = this.config;
60
+ if (projectName) {
61
+ target.projectName = projectName;
62
+ }
63
+ if (namespace) {
64
+ target.namespace = namespace;
65
+ }
66
+ if (mainParentDir) {
67
+ target.mainParentDir = mainParentDir;
68
+ }
69
+ if (mainSrcDir) {
70
+ target.mainSrcDir = mainSrcDir;
71
+ }
72
+ if (mainActivityFile) {
73
+ target.mainActivityFile = mainActivityFile;
74
+ }
75
+ if (versionName) {
76
+ target.versionName = versionName;
77
+ }
78
+ if (manifest) {
79
+ target.manifest = manifest;
80
+ }
81
+ if (profileable !== undefined) {
82
+ target.profileable = profileable;
83
+ }
84
+ if (versionCode >= 1) {
85
+ target.versionCode = Math.min(Math.ceil(versionCode), 2100000000);
86
+ }
87
+ if (commands) {
88
+ target.commands = commands;
89
+ }
90
+ if (javaVersion) {
91
+ target.javaVersion = +(typeof javaVersion === 'string' ? javaVersion.toString().replace(/_/g, '.') : javaVersion);
92
+ }
93
+ if (dataBinding) {
94
+ target.dataBinding = true;
95
+ }
96
+ if ((0, types_1.isArray)(dependencies)) {
97
+ target.dependencies = dependencies;
98
+ }
99
+ if (targetAPI) {
100
+ this.targetAPI = targetAPI;
101
+ }
102
+ if ((0, types_1.isPlainObject)(directories)) {
103
+ this.directories = directories;
104
+ }
105
+ if ((0, types_1.isArray)(elements)) {
106
+ this.elements = elements;
107
+ }
108
+ if ((0, types_1.isPlainObject)(extensionData)) {
109
+ this.extensionData = extensionData;
110
+ }
111
+ }
112
+ return super.init(assets, config);
113
+ }
114
+ findVersion(name, fallback) {
115
+ const targetAPI = this.targetAPI;
116
+ if (targetAPI) {
117
+ if (!Array.isArray(name)) {
118
+ name = [name];
119
+ }
120
+ for (let i = 0; i < name.length; i += 2) {
121
+ name.splice(i, 0, name[i] + '-' + targetAPI);
122
+ }
123
+ }
124
+ return super.findVersion(name, fallback);
125
+ }
126
+ async using(data) {
127
+ if (this.aborted) {
128
+ return Promise.reject((0, types_1.createAbortError)());
129
+ }
130
+ const { host, file } = data;
131
+ const localUri = file.localUri;
132
+ switch (file.mimeType) {
133
+ case 'font/unknown':
134
+ switch (await host.findMime(file, true)) {
135
+ case 'font/ttf':
136
+ case 'font/otf':
137
+ return;
138
+ case 'font/woff':
139
+ case 'font/woff2':
140
+ break;
141
+ default:
142
+ host.deleteFile(localUri);
143
+ return;
144
+ }
145
+ case 'font/woff':
146
+ case 'font/woff2': {
147
+ const instance = host.loadModule('compress');
148
+ const buffer = host.getBuffer(file);
149
+ if (instance && buffer) {
150
+ await instance.tryFile(buffer, localUri, { format: 'ttf', etag: file.etag }, (err, result) => {
151
+ if (err) {
152
+ host.deleteFile(localUri);
153
+ host.writeFail("Unable to compress file" /* ERR_MESSAGE.COMPRESS_FILE */, err, 8 /* LOG_TYPE.COMPRESS */);
154
+ }
155
+ else if ((0, types_1.isString)(result)) {
156
+ host.replace(file, result);
157
+ }
158
+ });
159
+ }
160
+ break;
161
+ }
162
+ }
163
+ }
164
+ findTemplate(baseDir, filename, options) {
165
+ let detect, languageOf;
166
+ if (options) {
167
+ ({ detect, languageOf } = options);
168
+ }
169
+ let kotlin, language;
170
+ if (languageOf) {
171
+ kotlin = (language = this.settings.language?.[languageOf]) === 'kotlin';
172
+ const isKts = this.detectKts(baseDir, filename);
173
+ detect = isKts !== null && (kotlin && isKts || !kotlin && !isKts);
174
+ if (kotlin) {
175
+ filename += '.kts';
176
+ }
177
+ }
178
+ const localUri = path.join(baseDir, filename);
179
+ try {
180
+ const existing = detect && fs.existsSync(localUri);
181
+ const paths = language ? [language, filename] : [filename];
182
+ let uri;
183
+ if (!existing && !(uri = this.resolveDir('template', ...paths)) && !fs.existsSync(uri = path.join(__dirname, 'template', ...paths))) {
184
+ throw (0, types_1.errorValue)("File not found" /* ERR_MESSAGE.NOTFOUND_FILE */, uri);
185
+ }
186
+ return { localUri, source: fs.readFileSync(uri || localUri, 'utf-8'), existing, kotlin, language };
187
+ }
188
+ catch (err) {
189
+ this.writeFail(["Unable to read file" /* ERR_MESSAGE.READ_FILE */, path.basename(localUri)], err, 32 /* LOG_TYPE.FILE */);
190
+ }
191
+ return { kotlin, language };
192
+ }
193
+ detectKts(...paths) {
194
+ try {
195
+ const file = path.join(...paths);
196
+ if (fs.existsSync(file)) {
197
+ return false;
198
+ }
199
+ if (fs.existsSync(file + '.kts')) {
200
+ return true;
201
+ }
202
+ }
203
+ catch {
204
+ }
205
+ return null;
206
+ }
207
+ get settings() {
208
+ var _a;
209
+ return (_a = this.module).settings || (_a.settings = {});
210
+ }
211
+ }
212
+ exports.default = AndroidDocument;
213
+
214
+ if (exports.default) {
215
+ module.exports = exports.default;
216
+ module.exports.default = exports.default;
217
+ }
@@ -0,0 +1,23 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="{{package}}">
3
+
4
+ <application
5
+ android:icon="@mipmap/ic_launcher"
6
+ android:label="{{label}}"
7
+ android:supportsRtl="{{supportsRtl}}"
8
+ android:theme="{{theme}}">
9
+ <activity
10
+ android:name="{{activityName}}"
11
+ android:exported="true"
12
+ android:label="{{label}}"
13
+ android:theme="{{theme}}">
14
+ <intent-filter>
15
+ <action android:name="android.intent.action.MAIN" />
16
+
17
+ <category android:name="android.intent.category.LAUNCHER" />
18
+ </intent-filter>
19
+ </activity>
20
+ <profileable android:shell="true" android:enabled="{{profileable}}" />
21
+ </application>
22
+
23
+ </manifest>
@@ -0,0 +1,39 @@
1
+ plugins {
2
+ id 'com.android.application'
3
+ }
4
+
5
+ android {
6
+ namespace ''
7
+ compileSdk 33
8
+
9
+ defaultConfig {
10
+ applicationId ''
11
+ minSdk 19
12
+ targetSdk 33
13
+ versionCode 1
14
+ versionName '1.0'
15
+
16
+ testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
17
+ }
18
+ buildTypes {
19
+ release {
20
+ debuggable false
21
+ minifyEnabled true
22
+ shrinkResources false
23
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
24
+ }
25
+ }
26
+ compileOptions {
27
+ sourceCompatibility JavaVersion.VERSION_1_8
28
+ targetCompatibility JavaVersion.VERSION_1_8
29
+ }
30
+ buildFeatures {
31
+ viewBinding false
32
+ }
33
+ }
34
+
35
+ dependencies {
36
+ testImplementation 'junit:junit:4.13.2'
37
+ androidTestImplementation 'androidx.test.ext:junit:1.1.5'
38
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
39
+ }
@@ -0,0 +1,18 @@
1
+ pluginManagement {
2
+ repositories {
3
+ gradlePluginPortal()
4
+ google()
5
+ mavenCentral()
6
+ }
7
+ }
8
+
9
+ dependencyResolutionManagement {
10
+ repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
11
+ repositories {
12
+ google()
13
+ mavenCentral()
14
+ }
15
+ }
16
+
17
+ rootProject.name = '{{projectName}}'
18
+ include '{{name}}'
@@ -0,0 +1,44 @@
1
+ plugins {
2
+ id 'com.android.application'
3
+ id 'org.jetbrains.kotlin.android'
4
+ }
5
+
6
+ android {
7
+ namespace ''
8
+ compileSdk 33
9
+
10
+ defaultConfig {
11
+ applicationId ''
12
+ minSdk 19
13
+ targetSdk 33
14
+ versionCode 1
15
+ versionName '1.0'
16
+
17
+ testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
18
+ }
19
+ buildTypes {
20
+ release {
21
+ debuggable false
22
+ minifyEnabled true
23
+ shrinkResources false
24
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
25
+ }
26
+ }
27
+ compileOptions {
28
+ sourceCompatibility JavaVersion.VERSION_1_8
29
+ targetCompatibility JavaVersion.VERSION_1_8
30
+ }
31
+ kotlinOptions {
32
+ jvmTarget = '1.8'
33
+ }
34
+ buildFeatures {
35
+ viewBinding false
36
+ }
37
+ }
38
+
39
+ dependencies {
40
+ implementation 'androidx.core:core-ktx:1.9.0'
41
+ testImplementation 'junit:junit:4.13.2'
42
+ androidTestImplementation 'androidx.test.ext:junit:1.1.5'
43
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
44
+ }
@@ -0,0 +1,18 @@
1
+ pluginManagement {
2
+ repositories {
3
+ gradlePluginPortal()
4
+ google()
5
+ mavenCentral()
6
+ }
7
+ }
8
+
9
+ dependencyResolutionManagement {
10
+ repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
11
+ repositories {
12
+ google()
13
+ mavenCentral()
14
+ }
15
+ }
16
+
17
+ rootProject.name = '{{projectName}}'
18
+ include '{{name}}'
@@ -0,0 +1,46 @@
1
+ plugins {
2
+ id("com.android.application")
3
+ kotlin("android")
4
+ }
5
+
6
+ android {
7
+ namespace = ""
8
+ compileSdk(33)
9
+
10
+ defaultConfig {
11
+ applicationId = ""
12
+ minSdk(19)
13
+ targetSdk(33)
14
+ versionCode = 1
15
+ versionName = "1.0"
16
+
17
+ testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
18
+ }
19
+ buildTypes {
20
+ getByName("release") {
21
+ isDebuggable = false
22
+ isMinifyEnabled = true
23
+ isShrinkResources = false
24
+ proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
25
+ }
26
+ }
27
+ kotlinOptions {
28
+ jvmTarget = "1.8"
29
+ }
30
+ buildFeatures {
31
+ viewBinding = true
32
+ }
33
+ }
34
+
35
+ java {
36
+ sourceCompatibility = JavaVersion.VERSION_1_8
37
+ targetCompatibility = JavaVersion.VERSION_1_8
38
+ }
39
+
40
+ dependencies {
41
+ implementation("org.jetbrains.kotlin:kotlin-stdlib:1.8.0")
42
+ implementation("androidx.core:core-ktx:1.9.0")
43
+ testImplementation("junit:junit:4.13.2")
44
+ androidTestImplementation("androidx.test.ext:junit:1.1.5")
45
+ androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
46
+ }
@@ -0,0 +1,18 @@
1
+ pluginManagement {
2
+ repositories {
3
+ gradlePluginPortal()
4
+ google()
5
+ mavenCentral()
6
+ }
7
+ }
8
+
9
+ dependencyResolutionManagement {
10
+ repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
11
+ repositories {
12
+ google()
13
+ mavenCentral()
14
+ }
15
+ }
16
+
17
+ rootProject.name = "${{projectName}}"
18
+ include("{{name}}")
package/asset.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import type { ExternalAsset } from '../types/lib/asset';
2
+
3
+ declare namespace asset {
4
+ function isEqual(item: ExternalAsset, other: ExternalAsset): boolean;
5
+ function setInitialValue(file: ExternalAsset, cacheable?: boolean): void;
6
+ }
7
+
8
+ export = asset;
package/asset.js ADDED
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.setInitialValue = exports.isEqual = void 0;
4
+ function isEqual(item, other) {
5
+ return !!(item.id && item.id === other.id || item.uri === other.uri && item.pathname === other.pathname && item.filename === other.filename && item.pathname && item.filename);
6
+ }
7
+ exports.isEqual = isEqual;
8
+ function setInitialValue(file, cacheable = true) {
9
+ file.initialValue || (file.initialValue = { pathname: file.pathname, filename: file.filename, mimeType: file.mimeType, localUri: file.localUri, inlineFilename: file.inlineFilename, cacheable });
10
+ }
11
+ exports.setInitialValue = setInitialValue;