@open-audio-stack/core 0.0.4 → 0.0.6

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/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # open-audio-stack-core
2
2
 
3
3
  ![Test](https://github.com/open-audio-stack/open-audio-stack-core/workflows/Test/badge.svg)
4
+ ![Release](https://github.com/open-audio-stack/open-audio-stack-core/workflows/Release/badge.svg)
4
5
 
5
6
  Common methods package shared across Open Audio Stack compatible registries, command-line tools, apps and websites for handling installing DAW VST plugin dependencies.
6
7
 
package/build/Config.d.ts CHANGED
@@ -12,7 +12,7 @@ import { ProjectType } from './types/ProjectType.js';
12
12
  import { SystemType } from './types/SystemType.js';
13
13
  export declare class Config {
14
14
  config: ConfigInterface;
15
- constructor(config: ConfigInterface);
15
+ constructor(config?: ConfigInterface);
16
16
  get(): ConfigInterface;
17
17
  architecture(type: Architecture): import("./types/Architecture.js").ArchitectureOption;
18
18
  architectures(): import("./types/Architecture.js").ArchitectureOption[];
package/build/Config.js CHANGED
@@ -12,7 +12,7 @@ import { systemTypes } from './types/SystemType.js';
12
12
  export class Config {
13
13
  config;
14
14
  constructor(config) {
15
- this.config = config;
15
+ this.config = Object.assign({}, config);
16
16
  }
17
17
  get() {
18
18
  return this.config;
@@ -1,8 +1,11 @@
1
1
  import { PackageInterface, PackageValidationError, PackageVersions, PackageVersionType } from './types/Package.js';
2
- import { RegistryInterface } from './types/Registry.js';
2
+ import { RegistryInterface, RegistryPackages } from './types/Registry.js';
3
+ import { PluginType } from './types/PluginType.js';
4
+ import { PresetType } from './types/PresetType.js';
5
+ import { ProjectType } from './types/ProjectType.js';
3
6
  export declare class Registry {
4
7
  registry: RegistryInterface;
5
- constructor(registry: RegistryInterface);
8
+ constructor(registry?: RegistryInterface);
6
9
  packageAdd(slug: string): {
7
10
  slug: string;
8
11
  version: string;
@@ -10,7 +13,9 @@ export declare class Registry {
10
13
  };
11
14
  packageVersionAdd(slug: string, version: string, pkgVersion: PackageVersionType): void;
12
15
  package(slug: string): PackageInterface;
13
- packages(): import("./types/Registry.js").RegistryPackages;
16
+ packages(): RegistryPackages;
17
+ packagesFilter(type: typeof PluginType | typeof PresetType | typeof ProjectType): RegistryPackages;
18
+ packageLatest(slug: string, version?: string): PackageVersionType;
14
19
  packageVersionLatest(versions: PackageVersions): string;
15
20
  get(): RegistryInterface;
16
21
  name(): string;
package/build/Registry.js CHANGED
@@ -3,7 +3,7 @@ import { PackageValidation, } from './types/Package.js';
3
3
  export class Registry {
4
4
  registry;
5
5
  constructor(registry) {
6
- this.registry = registry;
6
+ this.registry = Object.assign({}, registry);
7
7
  }
8
8
  packageAdd(slug) {
9
9
  return (this.registry.packages[slug] = {
@@ -26,6 +26,19 @@ export class Registry {
26
26
  packages() {
27
27
  return this.registry.packages;
28
28
  }
29
+ packagesFilter(type) {
30
+ const registryFiltered = {};
31
+ Object.keys(this.registry.packages).forEach((slug) => {
32
+ if (Object.values(type).includes(this.packageLatest(slug).type))
33
+ registryFiltered[slug] = this.registry.packages[slug];
34
+ });
35
+ return registryFiltered;
36
+ }
37
+ packageLatest(slug, version) {
38
+ const pkg = this.package(slug);
39
+ const pkgVersion = this.packageVersionLatest(pkg.versions);
40
+ return pkg.versions[version || pkgVersion];
41
+ }
29
42
  packageVersionLatest(versions) {
30
43
  let latest = '0.0.0';
31
44
  Object.keys(versions).forEach((version) => {
@@ -62,11 +75,13 @@ export class Registry {
62
75
  }
63
76
  packageVersionValidate(pkgVersion) {
64
77
  const fields = [
78
+ { name: 'audio', type: 'string' },
65
79
  { name: 'author', type: 'string' },
66
80
  { name: 'changes', type: 'string' },
67
81
  { name: 'date', type: 'string' },
68
82
  { name: 'description', type: 'string' },
69
83
  { name: 'files', type: 'object' },
84
+ { name: 'image', type: 'string' },
70
85
  { name: 'license', type: 'string' },
71
86
  { name: 'name', type: 'string' },
72
87
  { name: 'tags', type: 'object' },
@@ -76,7 +91,7 @@ export class Registry {
76
91
  const errors = [];
77
92
  fields.forEach((field) => {
78
93
  const versionField = pkgVersion[field.name];
79
- if (!versionField) {
94
+ if (versionField === undefined) {
80
95
  errors.push({
81
96
  field: field.name,
82
97
  error: PackageValidation.MISSING_FIELD,
@@ -0,0 +1,30 @@
1
+ import { PackageInterface } from '../types/Package.js';
2
+ export declare function dirApp(): string;
3
+ export declare function dirCreate(dir: string): string | false;
4
+ export declare function dirDelete(dir: string): false | void;
5
+ export declare function dirEmpty(dir: string): boolean;
6
+ export declare function dirExists(dir: string): boolean;
7
+ export declare function dirIs(dir: string): boolean;
8
+ export declare function dirMove(dir: string, dirNew: string): void | boolean;
9
+ export declare function dirOpen(dir: string): Buffer;
10
+ export declare function dirPackage(pkg: PackageInterface): string;
11
+ export declare function dirPlugins(): string;
12
+ export declare function dirPresets(): string;
13
+ export declare function dirProjects(): string;
14
+ export declare function dirRead(dir: string, options?: any): string[];
15
+ export declare function dirRename(dir: string, dirNew: string): void | boolean;
16
+ export declare function fileCreate(filePath: string, data: string | Buffer): void;
17
+ export declare function fileDate(filePath: string): Date;
18
+ export declare function fileDelete(filePath: string): boolean | void;
19
+ export declare function fileExec(filePath: string): void;
20
+ export declare function fileExists(filePath: string): boolean;
21
+ export declare function fileJsonCreate(filePath: string, data: object): void;
22
+ export declare function fileMove(filePath: string, newPath: string): void | boolean;
23
+ export declare function fileOpen(filePath: string): Buffer;
24
+ export declare function fileRead(filePath: string): Buffer;
25
+ export declare function fileReadJson(filePath: string): any;
26
+ export declare function fileReadString(filePath: string): string;
27
+ export declare function fileReadYaml(filePath: string): unknown;
28
+ export declare function fileSize(filePath: string): number;
29
+ export declare function zipCreate(filesPath: string, zipPath: string): void;
30
+ export declare function zipExtract(content: any, dirPath: string): void;
@@ -0,0 +1,198 @@
1
+ import AdmZip from 'adm-zip';
2
+ import { execSync } from 'child_process';
3
+ import { chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, unlinkSync, writeFileSync, } from 'fs';
4
+ import { globSync } from 'glob';
5
+ import { moveSync } from 'fs-extra/esm';
6
+ import os from 'os';
7
+ import path from 'path';
8
+ import yaml from 'js-yaml';
9
+ export function dirApp() {
10
+ if (process.platform === 'win32')
11
+ return process.env.APPDATA || os.homedir();
12
+ else if (process.platform === 'darwin')
13
+ return path.join(os.homedir(), 'Library', 'Preferences');
14
+ return path.join(os.homedir(), '.local', 'share');
15
+ }
16
+ export function dirCreate(dir) {
17
+ if (!dirExists(dir)) {
18
+ console.log('+', dir);
19
+ mkdirSync(dir, { recursive: true });
20
+ return dir;
21
+ }
22
+ return false;
23
+ }
24
+ export function dirDelete(dir) {
25
+ if (dirExists(dir)) {
26
+ console.log('-', dir);
27
+ return rmSync(dir, { recursive: true });
28
+ }
29
+ return false;
30
+ }
31
+ export function dirEmpty(dir) {
32
+ const files = readdirSync(dir);
33
+ return files.length === 0 || (files.length === 1 && files[0] === '.DS_Store');
34
+ }
35
+ export function dirExists(dir) {
36
+ return existsSync(dir);
37
+ }
38
+ export function dirIs(dir) {
39
+ return statSync(dir).isDirectory();
40
+ }
41
+ export function dirMove(dir, dirNew) {
42
+ if (dirExists(dir)) {
43
+ console.log('-', dir);
44
+ console.log('+', dirNew);
45
+ return moveSync(dir, dirNew, { overwrite: true });
46
+ }
47
+ return false;
48
+ }
49
+ export function dirOpen(dir) {
50
+ let command = '';
51
+ if (process.env.CI)
52
+ return new Buffer('');
53
+ if (process.platform === 'win32')
54
+ command = 'start ""';
55
+ else if (process.platform === 'darwin')
56
+ command = 'open';
57
+ else
58
+ command = 'xdg-open';
59
+ console.log('⎋', `${command} "${dir}"`);
60
+ return execSync(`${command} "${dir}"`);
61
+ }
62
+ export function dirPackage(pkg) {
63
+ const parts = pkg.slug.split('/');
64
+ parts.push(pkg.version);
65
+ return path.join(...parts);
66
+ }
67
+ export function dirPlugins() {
68
+ if (process.platform === 'win32')
69
+ return path.join('Program Files', 'Common Files');
70
+ else if (process.platform === 'darwin')
71
+ return path.join(os.homedir(), 'Library', 'Audio', 'Plug-ins');
72
+ return path.join('usr', 'local', 'lib');
73
+ }
74
+ export function dirPresets() {
75
+ if (process.platform === 'win32')
76
+ return path.join(os.homedir(), 'Documents', 'VST3 Presets');
77
+ else if (process.platform === 'darwin')
78
+ return path.join(os.homedir(), 'Library', 'Audio', 'Presets');
79
+ return path.join(os.homedir(), '.vst3', 'presets');
80
+ }
81
+ export function dirProjects() {
82
+ // Windows throws permissions errors if you scan hidden folders
83
+ // Therefore set to a more specific path than Documents
84
+ if (process.platform === 'win32')
85
+ return path.join(os.homedir(), 'Documents', 'Audio');
86
+ else if (process.platform === 'darwin')
87
+ return path.join(os.homedir(), 'Documents', 'Audio');
88
+ return path.join(os.homedir(), 'Documents', 'Audio');
89
+ }
90
+ export function dirRead(dir, options) {
91
+ console.log('⌕', dir);
92
+ // Glob now expects forward slashes on Windows
93
+ // Convert backslashes from path.join() to forwardslashes
94
+ if (process.platform === 'win32') {
95
+ dir = dir.replace(/\\/g, '/');
96
+ }
97
+ return globSync(dir, options);
98
+ }
99
+ export function dirRename(dir, dirNew) {
100
+ if (dirExists(dir)) {
101
+ return moveSync(dir, dirNew, { overwrite: true });
102
+ }
103
+ return false;
104
+ }
105
+ export function fileCreate(filePath, data) {
106
+ console.log('+', filePath);
107
+ return writeFileSync(filePath, data);
108
+ }
109
+ export function fileDate(filePath) {
110
+ return statSync(filePath).mtime;
111
+ }
112
+ export function fileDelete(filePath) {
113
+ if (fileExists(filePath)) {
114
+ console.log('-', filePath);
115
+ return unlinkSync(filePath);
116
+ }
117
+ return false;
118
+ }
119
+ export function fileExec(filePath) {
120
+ return chmodSync(filePath, '755');
121
+ }
122
+ export function fileExists(filePath) {
123
+ return existsSync(filePath);
124
+ }
125
+ export function fileJsonCreate(filePath, data) {
126
+ return fileCreate(filePath, JSON.stringify(data, null, 2));
127
+ }
128
+ export function fileMove(filePath, newPath) {
129
+ if (fileExists(filePath)) {
130
+ console.log('-', filePath);
131
+ console.log('+', newPath);
132
+ return moveSync(filePath, newPath, { overwrite: true });
133
+ }
134
+ return false;
135
+ }
136
+ export function fileOpen(filePath) {
137
+ let command = '';
138
+ if (process.env.CI)
139
+ return new Buffer('');
140
+ if (process.platform === 'win32')
141
+ command = 'open';
142
+ else if (process.platform === 'darwin')
143
+ command = 'start ""';
144
+ else
145
+ command = 'xdg-open';
146
+ console.log('⎋', `${command} "${filePath}"`);
147
+ return execSync(`${command} "${filePath}"`);
148
+ }
149
+ export function fileRead(filePath) {
150
+ console.log('⎋', filePath);
151
+ return readFileSync(filePath);
152
+ }
153
+ export function fileReadJson(filePath) {
154
+ if (fileExists(filePath)) {
155
+ console.log('⎋', filePath);
156
+ return JSON.parse(readFileSync(filePath).toString());
157
+ }
158
+ return false;
159
+ }
160
+ export function fileReadString(filePath) {
161
+ console.log('⎋', filePath);
162
+ return readFileSync(filePath).toString();
163
+ }
164
+ export function fileReadYaml(filePath) {
165
+ const file = fileReadString(filePath);
166
+ return yaml.load(file);
167
+ }
168
+ export function fileSize(filePath) {
169
+ return statSync(filePath).size;
170
+ }
171
+ export function zipCreate(filesPath, zipPath) {
172
+ if (fileExists(zipPath)) {
173
+ unlinkSync(zipPath);
174
+ }
175
+ const zip = new AdmZip();
176
+ const pathList = dirRead(filesPath);
177
+ pathList.forEach(pathItem => {
178
+ console.log('⎋', pathItem);
179
+ try {
180
+ if (dirIs(pathItem)) {
181
+ zip.addLocalFolder(pathItem, path.basename(pathItem));
182
+ }
183
+ else {
184
+ zip.addLocalFile(pathItem);
185
+ }
186
+ }
187
+ catch (error) {
188
+ console.log(error);
189
+ }
190
+ });
191
+ console.log('+', zipPath);
192
+ return zip.writeZip(zipPath);
193
+ }
194
+ export function zipExtract(content, dirPath) {
195
+ console.log('⎋', dirPath);
196
+ const zip = new AdmZip(content);
197
+ return zip.extractAllTo(dirPath);
198
+ }
@@ -0,0 +1,5 @@
1
+ export declare function pathGetExt(path: string, sep?: string): string;
2
+ export declare function pathGetDirectory(path: string, sep?: string): string;
3
+ export declare function pathGetFilename(path: string, sep?: string): string;
4
+ export declare function pathGetSlug(path: string, sep?: string): string;
5
+ export declare function pathGetVersion(path: string, sep?: string): string;
@@ -0,0 +1,17 @@
1
+ export function pathGetExt(path, sep = '.') {
2
+ return path.substring(path.lastIndexOf(sep) + 1);
3
+ }
4
+ export function pathGetDirectory(path, sep = '/') {
5
+ return path.substring(0, path.lastIndexOf(sep));
6
+ }
7
+ export function pathGetFilename(path, sep = '/') {
8
+ return path.substring(path.lastIndexOf(sep) + 1);
9
+ }
10
+ export function pathGetSlug(path, sep = '/') {
11
+ const parts = path.split(sep);
12
+ return parts[0] + '/' + parts[1];
13
+ }
14
+ export function pathGetVersion(path, sep = '/') {
15
+ const parts = path.split(sep);
16
+ return parts[parts.length - 2];
17
+ }
@@ -1,5 +1,6 @@
1
1
  export * from './Config.js';
2
2
  export * from './Registry.js';
3
+ export * from './helpers/utils.js';
3
4
  export * from './types/Architecture.js';
4
5
  export * from './types/Config.js';
5
6
  export * from './types/File.js';
@@ -4,8 +4,10 @@
4
4
  // Comment out any files which are not browser compatible.
5
5
  // Classes
6
6
  export * from './Config.js';
7
- // export * from './FileSystem.js';
8
7
  export * from './Registry.js';
8
+ // Helpers
9
+ // export * from './helpers/file.js';
10
+ export * from './helpers/utils.js';
9
11
  // Types
10
12
  export * from './types/Architecture.js';
11
13
  export * from './types/Config.js';
package/build/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './Config.js';
2
- export * from './FileSystem.js';
3
2
  export * from './Registry.js';
3
+ export * from './helpers/file.js';
4
+ export * from './helpers/utils.js';
4
5
  export * from './types/Architecture.js';
5
6
  export * from './types/Config.js';
6
7
  export * from './types/File.js';
package/build/index.js CHANGED
@@ -4,8 +4,10 @@
4
4
  // Comment out any files which are not NodeJS compatible.
5
5
  // Classes
6
6
  export * from './Config.js';
7
- export * from './FileSystem.js';
8
7
  export * from './Registry.js';
8
+ // Helpers
9
+ export * from './helpers/file.js';
10
+ export * from './helpers/utils.js';
9
11
  // Types
10
12
  export * from './types/Architecture.js';
11
13
  export * from './types/Config.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-audio-stack/core",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "Open-source audio plugin management software",
5
5
  "type": "module",
6
6
  "main": "./build/index.js",
@@ -1,33 +0,0 @@
1
- import { PackageInterface } from '../src/types/Package.js';
2
- export declare class FileSystem {
3
- constructor();
4
- dirApp(): string;
5
- dirCreate(dir: string): string | false;
6
- dirDelete(dir: string): false | void;
7
- dirEmpty(dir: string): boolean;
8
- dirExists(dir: string): boolean;
9
- dirIs(dir: string): boolean;
10
- dirMove(dir: string, dirNew: string): void | boolean;
11
- dirOpen(dir: string): Buffer;
12
- dirPackage(pkg: PackageInterface): string;
13
- dirPlugins(): string;
14
- dirPresets(): string;
15
- dirProjects(): string;
16
- dirRead(dir: string, options?: any): string[];
17
- dirRename(dir: string, dirNew: string): void | boolean;
18
- fileCreate(filePath: string, data: string | Buffer): void;
19
- fileDate(filePath: string): Date;
20
- fileDelete(filePath: string): boolean | void;
21
- fileExec(filePath: string): void;
22
- fileExists(filePath: string): boolean;
23
- fileJsonCreate(filePath: string, data: object): void;
24
- fileMove(filePath: string, newPath: string): void | boolean;
25
- fileOpen(filePath: string): Buffer;
26
- fileRead(filePath: string): Buffer;
27
- fileReadJson(filePath: string): any;
28
- fileReadString(filePath: string): string;
29
- fileReadYaml(filePath: string): unknown;
30
- fileSize(filePath: string): number;
31
- zipCreate(filesPath: string, zipPath: string): void;
32
- zipExtract(content: any, dirPath: string): void;
33
- }
@@ -1,201 +0,0 @@
1
- import AdmZip from 'adm-zip';
2
- import { execSync } from 'child_process';
3
- import { chmodSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, unlinkSync, writeFileSync, } from 'fs';
4
- import { globSync } from 'glob';
5
- import { moveSync } from 'fs-extra/esm';
6
- import os from 'os';
7
- import path from 'path';
8
- import yaml from 'js-yaml';
9
- export class FileSystem {
10
- constructor() { }
11
- dirApp() {
12
- if (process.platform === 'win32')
13
- return process.env.APPDATA || os.homedir();
14
- else if (process.platform === 'darwin')
15
- return path.join(os.homedir(), 'Library', 'Preferences');
16
- return path.join(os.homedir(), '.local', 'share');
17
- }
18
- dirCreate(dir) {
19
- if (!this.dirExists(dir)) {
20
- console.log('+', dir);
21
- mkdirSync(dir, { recursive: true });
22
- return dir;
23
- }
24
- return false;
25
- }
26
- dirDelete(dir) {
27
- if (this.dirExists(dir)) {
28
- console.log('-', dir);
29
- return rmSync(dir, { recursive: true });
30
- }
31
- return false;
32
- }
33
- dirEmpty(dir) {
34
- const files = readdirSync(dir);
35
- return files.length === 0 || (files.length === 1 && files[0] === '.DS_Store');
36
- }
37
- dirExists(dir) {
38
- return existsSync(dir);
39
- }
40
- dirIs(dir) {
41
- return statSync(dir).isDirectory();
42
- }
43
- dirMove(dir, dirNew) {
44
- if (this.dirExists(dir)) {
45
- console.log('-', dir);
46
- console.log('+', dirNew);
47
- return moveSync(dir, dirNew, { overwrite: true });
48
- }
49
- return false;
50
- }
51
- dirOpen(dir) {
52
- let command = '';
53
- if (process.env.CI)
54
- return new Buffer('');
55
- if (process.platform === 'win32')
56
- command = 'open';
57
- else if (process.platform === 'darwin')
58
- command = 'start ""';
59
- else
60
- command = 'xdg-open';
61
- console.log('⎋', `${command} "${dir}"`);
62
- return execSync(`${command} "${dir}"`);
63
- }
64
- dirPackage(pkg) {
65
- const parts = pkg.slug.split('/');
66
- parts.push(pkg.version);
67
- return path.join(...parts);
68
- }
69
- dirPlugins() {
70
- if (process.platform === 'win32')
71
- return path.join('Program Files', 'Common Files');
72
- else if (process.platform === 'darwin')
73
- return path.join(os.homedir(), 'Library', 'Audio', 'Plug-ins');
74
- return path.join('usr', 'local', 'lib');
75
- }
76
- dirPresets() {
77
- if (process.platform === 'win32')
78
- return path.join(os.homedir(), 'Documents', 'VST3 Presets');
79
- else if (process.platform === 'darwin')
80
- return path.join(os.homedir(), 'Library', 'Audio', 'Presets');
81
- return path.join(os.homedir(), '.vst3', 'presets');
82
- }
83
- dirProjects() {
84
- // Windows throws permissions errors if you scan hidden folders
85
- // Therefore set to a more specific path than Documents
86
- if (process.platform === 'win32')
87
- return path.join(os.homedir(), 'Documents', 'Audio');
88
- else if (process.platform === 'darwin')
89
- return path.join(os.homedir(), 'Documents', 'Audio');
90
- return path.join(os.homedir(), 'Documents', 'Audio');
91
- }
92
- dirRead(dir, options) {
93
- console.log('⌕', dir);
94
- // Glob now expects forward slashes on Windows
95
- // Convert backslashes from path.join() to forwardslashes
96
- if (process.platform === 'win32') {
97
- dir = dir.replace(/\\/g, '/');
98
- }
99
- return globSync(dir, options);
100
- }
101
- dirRename(dir, dirNew) {
102
- if (this.dirExists(dir)) {
103
- return moveSync(dir, dirNew, { overwrite: true });
104
- }
105
- return false;
106
- }
107
- fileCreate(filePath, data) {
108
- console.log('+', filePath);
109
- return writeFileSync(filePath, data);
110
- }
111
- fileDate(filePath) {
112
- return statSync(filePath).mtime;
113
- }
114
- fileDelete(filePath) {
115
- if (this.fileExists(filePath)) {
116
- console.log('-', filePath);
117
- return unlinkSync(filePath);
118
- }
119
- return false;
120
- }
121
- fileExec(filePath) {
122
- return chmodSync(filePath, '755');
123
- }
124
- fileExists(filePath) {
125
- return existsSync(filePath);
126
- }
127
- fileJsonCreate(filePath, data) {
128
- return this.fileCreate(filePath, JSON.stringify(data, null, 2));
129
- }
130
- fileMove(filePath, newPath) {
131
- if (this.fileExists(filePath)) {
132
- console.log('-', filePath);
133
- console.log('+', newPath);
134
- return moveSync(filePath, newPath, { overwrite: true });
135
- }
136
- return false;
137
- }
138
- fileOpen(filePath) {
139
- let command = '';
140
- if (process.env.CI)
141
- return new Buffer('');
142
- if (process.platform === 'win32')
143
- command = 'open';
144
- else if (process.platform === 'darwin')
145
- command = 'start ""';
146
- else
147
- command = 'xdg-open';
148
- console.log('⎋', `${command} "${filePath}"`);
149
- return execSync(`${command} "${filePath}"`);
150
- }
151
- fileRead(filePath) {
152
- console.log('⎋', filePath);
153
- return readFileSync(filePath);
154
- }
155
- fileReadJson(filePath) {
156
- if (this.fileExists(filePath)) {
157
- console.log('⎋', filePath);
158
- return JSON.parse(readFileSync(filePath).toString());
159
- }
160
- return false;
161
- }
162
- fileReadString(filePath) {
163
- console.log('⎋', filePath);
164
- return readFileSync(filePath).toString();
165
- }
166
- fileReadYaml(filePath) {
167
- const file = this.fileReadString(filePath);
168
- return yaml.load(file);
169
- }
170
- fileSize(filePath) {
171
- return statSync(filePath).size;
172
- }
173
- zipCreate(filesPath, zipPath) {
174
- if (this.fileExists(zipPath)) {
175
- unlinkSync(zipPath);
176
- }
177
- const zip = new AdmZip();
178
- const pathList = this.dirRead(filesPath);
179
- pathList.forEach(pathItem => {
180
- console.log('⎋', pathItem);
181
- try {
182
- if (this.dirIs(pathItem)) {
183
- zip.addLocalFolder(pathItem, path.basename(pathItem));
184
- }
185
- else {
186
- zip.addLocalFile(pathItem);
187
- }
188
- }
189
- catch (error) {
190
- console.log(error);
191
- }
192
- });
193
- console.log('+', zipPath);
194
- return zip.writeZip(zipPath);
195
- }
196
- zipExtract(content, dirPath) {
197
- console.log('⎋', dirPath);
198
- const zip = new AdmZip(content);
199
- return zip.extractAllTo(dirPath);
200
- }
201
- }