Browse Source

refactor(project): refactor

evshiron 8 years ago
parent
commit
74dc3b46fb

+ 5 - 5
docs/Options.md

@@ -3,7 +3,7 @@
 
 Options can be defined in the `package.json` of the project under `build` property, see an [example](../assets/project/package.json).
 
-## build <- [BuildConfig](../src/lib/BuildConfig.ts)
+## build <- [BuildConfig](../src/lib/config/BuildConfig.ts)
 
 Name | Type | Description
 --- | --- | ---
@@ -17,7 +17,7 @@ excludes | string[] | Glob patterns for excluded files. Defaults to `[]`.
 appId | string | App identity URI. Defaults to `io.github.nwjs.${ name }`.
 ffmpegIntegration | boolean | Whether to integrate `iteufel/nwjs-ffmpeg-prebuilt`. If `true`, you can NOT use symbols in `nwVersion`. Defaults to `false`.
 
-## build.win <- [WinConfig](../src/lib/WinConfig.ts)
+## build.win <- [WinConfig](../src/lib/config/WinConfig.ts)
 
 Name | Type | Description
 --- | --- | ---
@@ -26,7 +26,7 @@ fileVersion | string | File version. Defaults to `${ productVersion }`
 versionStrings | { [key: string]: string } | `rcedit` version strings. Defaults to `{ ProductName: "${ name }", FileDescription: "${ description }" }`.
 icon | string | .ico icon file. Defaults to `undefined`.
 
-## build.mac <- [MacConfig](../src/lib/MacConfig.ts)
+## build.mac <- [MacConfig](../src/lib/config/MacConfig.ts)
 
 Name | Type | Description
 --- | --- | ---
@@ -37,11 +37,11 @@ description | string | Description in `InfoPlist.strings`. Defaults to `${ descr
 copyright | string | Copyright in `InfoPlist.strings`. Defaults to `""`.
 icon | string | .icns icon file. Defaults to `undefined`.
 
-## build.linux <- [LinuxConfig](../src/lib/LinuxConfig.ts)
+## build.linux <- [LinuxConfig](../src/lib/config/LinuxConfig.ts)
 
 Currently noop.
 
-## build.nsis <- [NsisConfig](../src/lib/NsisConfig.ts)
+## build.nsis <- [NsisConfig](../src/lib/config/NsisConfig.ts)
 
 Name | Type | Description
 --- | --- | ---

+ 5 - 6
src/lib/Builder.ts

@@ -11,11 +11,10 @@ const plist = require('plist');
 
 import { Downloader } from './Downloader';
 import { FFmpegDownloader } from './FFmpegDownloader';
-import { extractGeneric, compress } from './archive';
-import { BuildConfig } from './BuildConfig';
-import { NsisVersions } from './NsisVersions';
+import { BuildConfig } from './config';
+import { NsisVersions } from './common/NsisVersions';
 import { NsisComposer, NsisDiffer, nsisBuild } from './nsis-gen';
-import { mergeOptions, findExecutable, findFFmpeg, findRuntimeRoot, findExcludableDependencies, tmpName, tmpFile, tmpDir, cpAsync } from './util';
+import { mergeOptions, findExecutable, findFFmpeg, findRuntimeRoot, findExcludableDependencies, tmpName, tmpFile, tmpDir, copyFileAsync, extractGeneric, compress } from './util';
 
 interface IBuilderOptions {
     win?: boolean;
@@ -293,7 +292,7 @@ export class Builder {
             case 'osx':
             case 'mac':
                 for(const file of files) {
-                    await cpAsync(join(this.dir, file), join(appRoot, file));
+                    await copyFileAsync(join(this.dir, file), join(appRoot, file));
                 }
                 break;
             default:
@@ -304,7 +303,7 @@ export class Builder {
         else {
 
             for(const file of files) {
-                await cpAsync(join(this.dir, file), join(appRoot, file));
+                await copyFileAsync(join(this.dir, file), join(appRoot, file));
             }
 
         }

+ 1 - 1
src/lib/Downloader.ts

@@ -3,7 +3,7 @@ import { dirname, basename, resolve } from 'path';
 
 const debug = require('debug')('build:downloader');
 
-import { DownloaderBase } from './DownloaderBase';
+import { DownloaderBase } from './common/DownloaderBase';
 import { mergeOptions } from './util';
 
 interface IDownloaderOptions {

+ 2 - 4
src/lib/FFmpegDownloader.ts

@@ -8,10 +8,8 @@ import { ensureDirSync, exists, writeFile } from 'fs-extra-promise';
 const debug = require('debug')('build:ffmpegDownloader');
 const progress = require('request-progress');
 
-import { DownloaderBase } from './DownloaderBase';
-import { Event } from './Event';
-import { extractGeneric } from './archive';
-import { mergeOptions } from './util';
+import { Event, DownloaderBase } from './common';
+import { mergeOptions, extractGeneric } from './util';
 
 interface IRequestProgress {
     percent: number;

+ 2 - 3
src/lib/Runner.ts

@@ -8,9 +8,8 @@ const debug = require('debug')('build:runner');
 
 import { Downloader } from './Downloader';
 import { FFmpegDownloader } from './FFmpegDownloader';
-import { BuildConfig } from './BuildConfig';
-import { extractGeneric } from './archive';
-import { mergeOptions, findExecutable, findFFmpeg, tmpDir, spawnAsync } from './util';
+import { BuildConfig } from './config';
+import { mergeOptions, findExecutable, findFFmpeg, tmpDir, spawnAsync, extractGeneric } from './util';
 
 interface IRunnerOptions {
     x86?: boolean;

+ 2 - 3
src/lib/DownloaderBase.ts

@@ -9,10 +9,9 @@ const debug = require('debug')('build:downloader');
 const progress = require('request-progress');
 
 import { Event } from './Event';
-import { extractGeneric } from './archive';
-import { mergeOptions } from './util';
+import { mergeOptions, extractGeneric } from '../util';
 
-const DIR_CACHES = resolve(dirname(module.filename), '..', '..', 'caches');
+const DIR_CACHES = resolve(dirname(module.filename), '..', '..', '..', 'caches');
 ensureDirSync(DIR_CACHES);
 
 interface IRequestProgress {

src/lib/Event.ts → src/lib/common/Event.ts


src/lib/NsisVersions.ts → src/lib/common/NsisVersions.ts


+ 4 - 0
src/lib/common/index.ts

@@ -0,0 +1,4 @@
+
+export * from './Event';
+export * from './DownloaderBase';
+export * from './NsisVersions';

src/lib/BuildConfig.ts → src/lib/config/BuildConfig.ts


src/lib/LinuxConfig.ts → src/lib/config/LinuxConfig.ts


src/lib/MacConfig.ts → src/lib/config/MacConfig.ts


src/lib/NsisConfig.ts → src/lib/config/NsisConfig.ts


src/lib/WinConfig.ts → src/lib/config/WinConfig.ts


+ 6 - 0
src/lib/config/index.ts

@@ -0,0 +1,6 @@
+
+export * from './BuildConfig';
+export * from './WinConfig';
+export * from './MacConfig';
+export * from './LinuxConfig';
+export * from './NsisConfig';

+ 3 - 5
src/lib/index.ts

@@ -1,8 +1,6 @@
 
 import 'source-map-support/register';
 
-import { Runner } from './Runner';
-import { Builder } from './Builder';
-import { Downloader } from './Downloader';
-
-export { Runner, Builder, Downloader };
+export * from './Runner';
+export * from './Builder';
+export * from './Downloader';

+ 1 - 1
src/lib/archive.ts

@@ -6,7 +6,7 @@ import { path7za } from '7zip-bin';
 
 const debug = require('debug')('build:archive');
 
-import { tmpFile, spawnAsync } from './util';
+import { tmpFile, spawnAsync } from './';
 
 interface IExtractOptions {
     overwrite: boolean;

+ 3 - 1
src/lib/util.ts

@@ -9,6 +9,8 @@ import { lstatAsync, ensureDirAsync, readFileAsync, outputFileAsync } from 'fs-e
 const debug = require('debug')('build:util');
 const globby = require('globby');
 
+export * from './archive';
+
 export function mergeOptions(defaults: any, options: any) {
 
     const opts: any = {};
@@ -221,7 +223,7 @@ export function tmpDir(options: any = {}): Promise<{
     });
 }
 
-export async function cpAsync(src: string, dest: string) {
+export async function copyFileAsync(src: string, dest: string) {
 
     const stats = await lstatAsync(src);
 

+ 0 - 19
test/archive.js

@@ -1,19 +0,0 @@
-
-import { test } from 'ava';
-
-import { removeAsync } from 'fs-extra-promise';
-
-import { compress } from '../dist/lib/archive';
-import { tmpName, tmpFile, tmpDir } from '../dist/lib/util';
-
-(process.env.CI ? test.skip : test)('compress', async (t) => {
-
-    // Don't use `tmpFile`, which keeps the file open and results in exceptions when spawning.
-    const path = await tmpName();
-
-    const code = await compress('./assets/', [ './project/index.html', './project/package.json' ], 'zip', path);
-    t.is(code, 0);
-
-    await removeAsync(path);
-
-});

+ 15 - 1
test/util.js

@@ -1,7 +1,9 @@
 
 import { test } from 'ava';
 
-import { mergeOptions } from '../dist/lib/util';
+import { removeAsync } from 'fs-extra-promise';
+
+import { mergeOptions, tmpName, tmpFile, tmpDir, compress } from '../dist/lib/util';
 
 test('mergeOptions', async (t) => {
 
@@ -23,3 +25,15 @@ test('mergeOptions', async (t) => {
     });
 
 });
+
+test('compress', async (t) => {
+
+    // Don't use `tmpFile`, which keeps the file open and results in exceptions when spawning.
+    const path = await tmpName();
+
+    const code = await compress('./assets/', [ './project/index.html', './project/package.json' ], 'zip', path);
+    t.is(code, 0);
+
+    await removeAsync(path);
+
+});