├── .gitignore
├── dist
├── test.d.ts
├── test.js.map
├── test.js
├── index.d.ts
├── index.js.map
└── index.js
├── README.md
├── src
├── test.ts
└── index.ts
├── CHANGELOG.md
├── package.json
├── LICENSE
└── tsconfig.json
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/*
2 |
--------------------------------------------------------------------------------
/dist/test.d.ts:
--------------------------------------------------------------------------------
1 | export {};
2 |
--------------------------------------------------------------------------------
/dist/test.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"test.js","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,MAAM,YAAY,CAAC;AAE5C,MAAM,KAAK,GAAG;IACV,qBAAqB;IACrB,oCAAoC;IACpC,sDAAsD;IACtD,wEAAwE;CAC3E,CAAC;AAEF,MAAM,IAAI,GAAG,4BAA4B,CAAC;AAC1C,MAAM,MAAM,GAAG,6BAA6B,CAAC;AAC7C,MAAM,kBAAkB,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC"}
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # unitypackage
2 |
3 | This package is for creating unitypackage in Node.js environment.
4 |
5 | # Install
6 |
7 | ```
8 | npm install unitypackage
9 | ```
10 |
11 | # How to use
12 |
13 | ```
14 | import create from 'unitypackage';
15 | ```
16 |
17 | ## License
18 |
19 | The scripts and documentation in this project are released under the [MIT License](LICENSE)
--------------------------------------------------------------------------------
/src/test.ts:
--------------------------------------------------------------------------------
1 | import createUnityPackage from './index.js';
2 |
3 | const files = [
4 | 'Assets/Voiceer.meta',
5 | 'Assets/Voiceer/VoiceResources.meta',
6 | 'Assets/Voiceer/VoiceResources/MusubimeYuiVoices.meta',
7 | 'Assets/Voiceer/VoiceResources/MusubimeYuiVoices/MusubimeYui.asset.meta',
8 | ];
9 |
10 | const path = "D:\\Saved Games\\Voiceer\\";
11 | const output = 'Voiceer+sample.unitypackage';
12 | await createUnityPackage(files, path, output, console.log);
--------------------------------------------------------------------------------
/dist/test.js:
--------------------------------------------------------------------------------
1 | import createUnityPackage from './index.js';
2 | const files = [
3 | 'Assets/Voiceer.meta',
4 | 'Assets/Voiceer/VoiceResources.meta',
5 | 'Assets/Voiceer/VoiceResources/MusubimeYuiVoices.meta',
6 | 'Assets/Voiceer/VoiceResources/MusubimeYuiVoices/MusubimeYui.asset.meta',
7 | ];
8 | const path = "D:\\Saved Games\\Voiceer\\";
9 | const output = 'Voiceer+sample.unitypackage';
10 | await createUnityPackage(files, path, output, console.log);
11 | //# sourceMappingURL=test.js.map
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## [1.0.1](https://github.com/pCYSl5EDgo/unitypackage/compare/v1.0.0...v1.0.1) (2020-01-30)
2 |
3 |
4 | ### Bug Fixes
5 |
6 | * add npm package "git-snapshot" ([312ed3c](https://github.com/pCYSl5EDgo/unitypackage/commit/312ed3c4632e26eea65d90903484aa129dae6217))
7 |
8 | # 1.0.0 (2020-01-30)
9 |
10 |
11 | ### Bug Fixes
12 |
13 | * add npm repositories ([ab384f6](https://github.com/pCYSl5EDgo/unitypackage/commit/ab384f6e48daa9559fb2b3a85586aa05fffb274f))
14 | * npm ci ([809a263](https://github.com/pCYSl5EDgo/unitypackage/commit/809a26329fa3d253a9b492f5b05aaa79e70f1a9b))
15 |
16 |
17 | ### Features
18 |
19 | * Initial Commit ([c0527db](https://github.com/pCYSl5EDgo/unitypackage/commit/c0527dbc0d119c9510b8d21a6f2c9a071b729078))
20 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "unitypackage",
3 | "version": "1.0.8",
4 | "type": "module",
5 | "description": "create unitypackage utility",
6 | "exports": "./dist/index.js",
7 | "pkg": "unitypackage",
8 | "scripts": {
9 | "test": "exit 0",
10 | "build": "tsc"
11 | },
12 | "files": [
13 | "dist/index.js",
14 | "dist/index.d.ts",
15 | "package.json",
16 | "package-lock.json"
17 | ],
18 | "repository": {
19 | "type": "git",
20 | "url": "git+https://github.com/pCYSl5EDgo/unitypackage.git"
21 | },
22 | "engines": {
23 | "node": ">=20.0.0"
24 | },
25 | "author": "pCYSl5EDgo",
26 | "license": "MIT",
27 | "bugs": {
28 | "url": "https://github.com/pCYSl5EDgo/unitypackage/issues"
29 | },
30 | "homepage": "https://github.com/pCYSl5EDgo/unitypackage#readme",
31 | "dependencies": {
32 | "yaml": "^2.3.4"
33 | },
34 | "devDependencies": {
35 | "@types/node": "^20.10.6",
36 | "typescript": "^5.3.3"
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020-2022 pCYSl5EDgo
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
--------------------------------------------------------------------------------
/dist/index.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 | export type NoParamAsyncCallback = (err: NodeJS.ErrnoException | null) => Promise;
3 | export interface AssetMetaData {
4 | guid: string;
5 | folderAsset: 'yes' | 'no' | undefined;
6 | }
7 | export declare namespace InternalImplementation {
8 | const loadAssetMetaData: (data: string) => AssetMetaData;
9 | function createUnityPackageFromFolder(folderContainsMetaFolders: string, output: string, callback?: NoParamAsyncCallback, logger?: (logText: string) => void, removeDirs?: string[]): Promise;
10 | function createMetaFolderUnderFolder(metaFileRelativePathWithExtension: string, projectRoot: string, folderContainsMetaFolders: string, callback?: NoParamAsyncCallback, logger?: (logText: string) => void): Promise;
11 | function createUnityPackageFromMetaFilePathsWithTempFolder(metaFiles: string[], projectRoot: string, output: string, folderContainsMetaFolders: string, logger?: (logText: string) => void, removeDirs?: string[]): Promise;
12 | }
13 | export default function createUnityPackage(metaFiles: string[], projectRoot: string, output: string, logger?: (logText: string) => void): Promise;
14 |
--------------------------------------------------------------------------------
/dist/index.js.map:
--------------------------------------------------------------------------------
1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAa,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAC3F,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AASjC,MAAM,KAAQ,sBAAsB,CA4HnC;AA5HD,WAAc,sBAAsB;IACnB,wCAAiB,GAAG,CAAC,IAAY,EAAiB,EAAE,CAAC,KAAK,CAAC,IAAI,CAAkB,CAAC;IAC/F,KAAK,UAAU,WAAW,CAAC,GAAiC,IAAmB,IAAI,GAAG,EAAE,CAAC;QAAC,MAAM,GAAG,CAAC;IAAC,C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C;YAC3B,MAAM,YAAY,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC;YAC7C,MAAM,QAAQ,GAAG,KAAK,EAAE,GAAiC,EAAiB,EAAE;gBACxE,IAAI,GAAG,EAAE,CAAC;oBACN,MAAM,GAAG,CAAC;gBACd,CAAC;gBAED,cAAc,CAAC,YAAY,CAAC,GAAG,IAAI,CAAC;gBACpC,IAAI,cAAc,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;oBACvC,MAAM,4BAA4B,CAAC,yBAAyB,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;gBAC3G,CAAC;YACL,CAAC,CAAC;YAEF,MAAM,2BAA2B,CAAC,YAAY,EAAE,WAAW,EAAE,yBAAyB,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;QAC9G,CAAC;IACL,CAAC;IA1BqB,wEAAiD,oDA0BtE,CAAA;IAAA,CAAC;AACN,CAAC,EA5Ha,sBAAsB,KAAtB,sBAAsB,QA4HnC;AAED,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,kBAAkB,CAAC,SAAmB,EAAE,WAAmB,EAAE,MAAc,EAAE,MAAkC;IACzI,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,YAAY,CAAC,CAAC;IAC3C,MAAM,yBAAyB,GAAG,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAC3D,MAAM,KAAK,CAAC,yBAAyB,CAAC,CAAC;IACvC,MAAM,sBAAsB,CAAC,iDAAiD,CAAC,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,yBAAyB,EAAE,MAAM,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;AAChK,CAAC;AAAA,CAAC"}
--------------------------------------------------------------------------------
/dist/index.js:
--------------------------------------------------------------------------------
1 | import { exec } from 'node:child_process';
2 | import { existsSync } from 'node:fs';
3 | import { copyFile, mkdir, mkdtemp, readFile, rm, writeFile, stat } from 'node:fs/promises';
4 | import { parse } from 'yaml';
5 | import { tmpdir } from 'node:os';
6 | import { join } from 'node:path';
7 | export var InternalImplementation;
8 | (function (InternalImplementation) {
9 | InternalImplementation.loadAssetMetaData = (data) => parse(data);
10 | async function NoOperation(err) { if (err) {
11 | throw err;
12 | } }
13 | ;
14 | const recursiveDelete = { recursive: true, force: true };
15 | async function createUnityPackageFromFolder(folderContainsMetaFolders, output, callback, logger, removeDirs) {
16 | const tmpDirectory = join(tmpdir(), "tmp");
17 | const archtemp = join(tmpDirectory, "archtemp.tar");
18 | await rm(tmpDirectory, recursiveDelete);
19 | await mkdir(tmpDirectory);
20 | async function totalEnd() {
21 | const archtemp_gzip = archtemp + '.gz';
22 | await copyFile(archtemp_gzip, output);
23 | if (removeDirs) {
24 | for (const removeDir of removeDirs) {
25 | await rm(removeDir, recursiveDelete);
26 | }
27 | }
28 | try {
29 | await rm(tmpDirectory, recursiveDelete);
30 | }
31 | catch (error) {
32 | if (callback) {
33 | callback(error);
34 | }
35 | return;
36 | }
37 | if (callback) {
38 | callback(null);
39 | }
40 | }
41 | ;
42 | exec('tar -cf "' + archtemp + '" -C "' + folderContainsMetaFolders + '" .', (err, stdout, stderr) => {
43 | if (err) {
44 | if (logger) {
45 | logger('stdout : ' + stdout);
46 | logger('stderr : ' + stderr);
47 | }
48 | throw err;
49 | }
50 | const sevenZipPath = '"C:\\Program Files\\7-Zip\\7z.exe"';
51 | if (existsSync(sevenZipPath)) {
52 | exec(sevenZipPath + ' a -tgzip "' + archtemp + '.gz" "' + archtemp + '"', totalEnd);
53 | }
54 | else {
55 | exec('gzip -f "' + archtemp + '"', totalEnd);
56 | }
57 | });
58 | }
59 | InternalImplementation.createUnityPackageFromFolder = createUnityPackageFromFolder;
60 | ;
61 | async function createMetaFolderUnderFolder(metaFileRelativePathWithExtension, projectRoot, folderContainsMetaFolders, callback, logger) {
62 | const metaFileAbsolutePath = join(projectRoot, metaFileRelativePathWithExtension);
63 | const data = await readFile(metaFileAbsolutePath, { encoding: "utf-8" });
64 | const metaDatum = InternalImplementation.loadAssetMetaData(data);
65 | const guid = metaDatum.guid;
66 | const dir = join(folderContainsMetaFolders, guid);
67 | if (logger) {
68 | logger('create-directory : ' + dir);
69 | }
70 | await mkdir(dir);
71 | await copyFile(metaFileAbsolutePath, join(dir, "asset.meta"));
72 | if (metaDatum.folderAsset !== "yes") {
73 | const assetFileAbsolutePath = metaFileAbsolutePath.slice(0, metaFileAbsolutePath.length - 5);
74 | const stats = await stat(assetFileAbsolutePath);
75 | if (stats.isFile()) {
76 | await copyFile(assetFileAbsolutePath, join(dir, "asset"));
77 | }
78 | }
79 | const assetFileRelativePath = metaFileRelativePathWithExtension.slice(0, metaFileRelativePathWithExtension.length - 5);
80 | try {
81 | await writeFile(join(dir, "pathname"), assetFileRelativePath);
82 | }
83 | catch (error) {
84 | if (callback) {
85 | callback(error);
86 | }
87 | return;
88 | }
89 | if (callback) {
90 | callback(null);
91 | }
92 | }
93 | InternalImplementation.createMetaFolderUnderFolder = createMetaFolderUnderFolder;
94 | ;
95 | async function createUnityPackageFromMetaFilePathsWithTempFolder(metaFiles, projectRoot, output, folderContainsMetaFolders, logger, removeDirs) {
96 | const processHasDone = new Array(metaFiles.length);
97 | processHasDone.fill(false);
98 | for (let index = 0; index < metaFiles.length; index++) {
99 | const currentIndex = index;
100 | const metaFilePath = metaFiles[currentIndex];
101 | const callback = async (err) => {
102 | if (err) {
103 | throw err;
104 | }
105 | processHasDone[currentIndex] = true;
106 | if (processHasDone.indexOf(false) === -1) {
107 | await createUnityPackageFromFolder(folderContainsMetaFolders, output, NoOperation, logger, removeDirs);
108 | }
109 | };
110 | await createMetaFolderUnderFolder(metaFilePath, projectRoot, folderContainsMetaFolders, callback, logger);
111 | }
112 | }
113 | InternalImplementation.createUnityPackageFromMetaFilePathsWithTempFolder = createUnityPackageFromMetaFilePathsWithTempFolder;
114 | ;
115 | })(InternalImplementation || (InternalImplementation = {}));
116 | export default async function createUnityPackage(metaFiles, projectRoot, output, logger) {
117 | const folder = await mkdtemp("tempFolder");
118 | const folderContainsMetaFolders = join(folder, 'archtemp');
119 | await mkdir(folderContainsMetaFolders);
120 | await InternalImplementation.createUnityPackageFromMetaFilePathsWithTempFolder(metaFiles, projectRoot, output, folderContainsMetaFolders, logger, [folder]);
121 | }
122 | ;
123 | //# sourceMappingURL=index.js.map
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | /* Basic Options */
4 | // "incremental": true, /* Enable incremental compilation */
5 | "target": "ES2022", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
6 | "module": "NodeNext", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
7 | // "lib": [], /* Specify library files to be included in the compilation. */
8 | // "allowJs": true, /* Allow javascript files to be compiled. */
9 | // "checkJs": true, /* Report errors in .js files. */
10 | // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
11 | "declaration": true, /* Generates corresponding '.d.ts' file. */
12 | // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
13 | "sourceMap": true, /* Generates corresponding '.map' file. */
14 | // "outFile": "./", /* Concatenate and emit output to single file. */
15 | "outDir": "./dist/", /* Redirect output structure to the directory. */
16 | "rootDir": "./src/", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
17 | // "composite": true, /* Enable project compilation */
18 | // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
19 | // "removeComments": true, /* Do not emit comments to output. */
20 | // "noEmit": true, /* Do not emit outputs. */
21 | // "importHelpers": true, /* Import emit helpers from 'tslib'. */
22 | // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
23 | // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
24 |
25 | /* Strict Type-Checking Options */
26 | // "strict": true, /* Enable all strict type-checking options. */
27 | // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
28 | // "strictNullChecks": true, /* Enable strict null checks. */
29 | // "strictFunctionTypes": true, /* Enable strict checking of function types. */
30 | // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
31 | // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
32 | // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
33 | // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
34 |
35 | /* Additional Checks */
36 | // "noUnusedLocals": true, /* Report errors on unused locals. */
37 | // "noUnusedParameters": true, /* Report errors on unused parameters. */
38 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
39 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
40 |
41 | /* Module Resolution Options */
42 | "moduleResolution": "NodeNext", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
43 | // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
44 | // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
45 | // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
46 | // "typeRoots": [], /* List of folders to include type definitions from. */
47 | // "types": [], /* Type declaration files to be included in compilation. */
48 | // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
49 | // "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
50 | // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
51 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
52 |
53 | /* Source Map Options */
54 | // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
55 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
56 | // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
57 | // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
58 |
59 | /* Experimental Options */
60 | // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
61 | // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
62 |
63 | /* Advanced Options */
64 | "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/src/index.ts:
--------------------------------------------------------------------------------
1 | import { exec } from 'node:child_process';
2 | import { existsSync, RmOptions } from 'node:fs';
3 | import { copyFile, mkdir, mkdtemp, readFile, rm, writeFile, stat } from 'node:fs/promises';
4 | import { parse } from 'yaml';
5 | import { tmpdir } from 'node:os';
6 | import { join } from 'node:path';
7 |
8 | export type NoParamAsyncCallback = (err: NodeJS.ErrnoException | null) => Promise;
9 |
10 | export interface AssetMetaData {
11 | guid: string;
12 | folderAsset: 'yes' | 'no' | undefined
13 | }
14 |
15 | export module InternalImplementation {
16 | export const loadAssetMetaData = (data: string): AssetMetaData => parse(data) as AssetMetaData;
17 | async function NoOperation(err: NodeJS.ErrnoException | null): Promise { if (err) { throw err; } };
18 | const recursiveDelete: RmOptions = { recursive: true, force: true };
19 | export async function createUnityPackageFromFolder(
20 | folderContainsMetaFolders: string,
21 | output: string,
22 | callback?: NoParamAsyncCallback,
23 | logger?: (logText: string) => void,
24 | removeDirs?: string[],
25 | ): Promise {
26 | const tmpDirectory = join(tmpdir(), "tmp");
27 | const archtemp = join(tmpDirectory, "archtemp.tar");
28 | await rm(tmpDirectory, recursiveDelete);
29 | await mkdir(tmpDirectory);
30 | async function totalEnd(): Promise {
31 | const archtemp_gzip = archtemp + '.gz';
32 | await copyFile(archtemp_gzip, output);
33 | if (removeDirs) {
34 | for (const removeDir of removeDirs) {
35 | await rm(removeDir, recursiveDelete);
36 | }
37 | }
38 |
39 | try {
40 | await rm(tmpDirectory, recursiveDelete);
41 | } catch (error) {
42 | if (callback) {
43 | callback(error as (NodeJS.ErrnoException | null));
44 | }
45 | return;
46 | }
47 | if (callback) {
48 | callback(null);
49 | }
50 | };
51 | exec('tar -cf "' + archtemp + '" -C "' + folderContainsMetaFolders + '" .', (err, stdout, stderr) => {
52 | if (err) {
53 | if (logger) {
54 | logger('stdout : ' + stdout);
55 | logger('stderr : ' + stderr);
56 | }
57 |
58 | throw err;
59 | }
60 |
61 | const sevenZipPath = '"C:\\Program Files\\7-Zip\\7z.exe"';
62 | if (existsSync(sevenZipPath)) {
63 | exec(sevenZipPath + ' a -tgzip "' + archtemp + '.gz" "' + archtemp + '"', totalEnd);
64 | }
65 | else {
66 | exec('gzip -f "' + archtemp + '"', totalEnd);
67 | }
68 | });
69 | };
70 |
71 | export async function createMetaFolderUnderFolder(
72 | metaFileRelativePathWithExtension: string,
73 | projectRoot: string,
74 | folderContainsMetaFolders: string,
75 | callback?: NoParamAsyncCallback,
76 | logger?: (logText: string) => void,
77 | ): Promise {
78 | const metaFileAbsolutePath = join(projectRoot, metaFileRelativePathWithExtension);
79 | const data = await readFile(metaFileAbsolutePath, { encoding: "utf-8" });
80 | const metaDatum = loadAssetMetaData(data);
81 | const guid = metaDatum.guid;
82 | const dir = join(folderContainsMetaFolders, guid);
83 | if (logger) {
84 | logger('create-directory : ' + dir);
85 | }
86 |
87 | await mkdir(dir);
88 | await copyFile(metaFileAbsolutePath, join(dir, "asset.meta"));
89 | if (metaDatum.folderAsset !== "yes") {
90 | const assetFileAbsolutePath = metaFileAbsolutePath.slice(0, metaFileAbsolutePath.length - 5);
91 | const stats = await stat(assetFileAbsolutePath);
92 | if (stats.isFile()) {
93 | await copyFile(assetFileAbsolutePath, join(dir, "asset"));
94 | }
95 | }
96 |
97 | const assetFileRelativePath = metaFileRelativePathWithExtension.slice(0, metaFileRelativePathWithExtension.length - 5);
98 | try {
99 | await writeFile(join(dir, "pathname"), assetFileRelativePath);
100 | }
101 | catch (error) {
102 | if (callback) {
103 | callback(error as (NodeJS.ErrnoException | null));
104 | }
105 | return;
106 | }
107 | if (callback) {
108 | callback(null);
109 | }
110 | };
111 |
112 | export async function createUnityPackageFromMetaFilePathsWithTempFolder(
113 | metaFiles: string[],
114 | projectRoot: string,
115 | output: string,
116 | folderContainsMetaFolders: string,
117 | logger?: (logText: string) => void,
118 | removeDirs?: string[],
119 | ): Promise {
120 | const processHasDone = new Array(metaFiles.length);
121 | processHasDone.fill(false);
122 | for (let index = 0; index < metaFiles.length; index++) {
123 | const currentIndex = index;
124 | const metaFilePath = metaFiles[currentIndex];
125 | const callback = async (err: NodeJS.ErrnoException | null): Promise => {
126 | if (err) {
127 | throw err;
128 | }
129 |
130 | processHasDone[currentIndex] = true;
131 | if (processHasDone.indexOf(false) === -1) {
132 | await createUnityPackageFromFolder(folderContainsMetaFolders, output, NoOperation, logger, removeDirs);
133 | }
134 | };
135 |
136 | await createMetaFolderUnderFolder(metaFilePath, projectRoot, folderContainsMetaFolders, callback, logger);
137 | }
138 | };
139 | }
140 |
141 | export default async function createUnityPackage(metaFiles: string[], projectRoot: string, output: string, logger?: (logText: string) => void): Promise {
142 | const folder = await mkdtemp("tempFolder");
143 | const folderContainsMetaFolders = join(folder, 'archtemp');
144 | await mkdir(folderContainsMetaFolders);
145 | await InternalImplementation.createUnityPackageFromMetaFilePathsWithTempFolder(metaFiles, projectRoot, output, folderContainsMetaFolders, logger, [folder]);
146 | };
--------------------------------------------------------------------------------