@travetto/pack 2.1.3 → 2.2.2
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 +4 -4
- package/bin/cli-pack.ts +3 -3
- package/bin/cli-pack_assemble.ts +11 -3
- package/bin/cli-pack_docker-export.ts +12 -4
- package/bin/cli-pack_docker.ts +14 -3
- package/bin/cli-pack_zip.ts +9 -3
- package/bin/lib/assemble.ts +18 -18
- package/bin/lib/{depdencies.ts → dependencies.ts} +16 -7
- package/bin/lib/util.ts +14 -12
- package/bin/operation/assemble.ts +1 -1
- package/bin/operation/docker.ts +1 -1
- package/bin/operation/pack.ts +18 -6
- package/bin/pack-base.ts +18 -12
- package/package.json +3 -3
- package/support/pack.config.ts +1 -1
package/README.md
CHANGED
|
@@ -39,14 +39,14 @@ Assemble is the operation that stages the project's code for deployment. The as
|
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
1. Cleaning Workspace - Cleans workspace to start with an empty workspace
|
|
42
|
-
1. Copying Dependencies - Computes the prod
|
|
42
|
+
1. Copying Dependencies - Computes the prod dependencies and copies them into the new workspace
|
|
43
43
|
1. Copying App Content - Copies over application content (src/resources/support/bin)
|
|
44
44
|
1. Excluding Pre-Compile Files - Any files that should be excluded pre-compilation, are removed
|
|
45
45
|
1. Compiling - Compiles the code in the new workspace, isolating it from your local development
|
|
46
46
|
1. Excluding Post-Compile Files - Removes any files that should be excluded, post compilation
|
|
47
47
|
1. Copying Added Content - Adds in any additional content that is not in the standard locations
|
|
48
48
|
1. Removing Empty Folders - Purge all empty folders, recursively
|
|
49
|
-
1.
|
|
49
|
+
1. Writing Env.js - Write out the .env.js file with computed any env vars that should be set for the deployed app
|
|
50
50
|
1. Remove Source Maps - If keep source is false, all source maps are purged from your app's code
|
|
51
51
|
1. Emptying .ts Files - If keep source is false, all .ts files are emptied, as compilation will not occur at runtime
|
|
52
52
|
|
|
@@ -168,7 +168,7 @@ Various modules may provide customizations to the default `pack.config.ts` to al
|
|
|
168
168
|
|
|
169
169
|
**Code: Rest, pack.lambda.ts**
|
|
170
170
|
```typescript
|
|
171
|
-
import * as fs from 'fs';
|
|
171
|
+
import * as fs from 'fs/promises';
|
|
172
172
|
|
|
173
173
|
import { PathUtil } from '@travetto/boot';
|
|
174
174
|
import type { AllConfigPartial } from '@travetto/pack';
|
|
@@ -186,7 +186,7 @@ export const config: AllConfigPartial = {
|
|
|
186
186
|
},
|
|
187
187
|
postProcess: [{
|
|
188
188
|
['Lambda Entrypoint']: cfg =>
|
|
189
|
-
fs.
|
|
189
|
+
fs.copyFile(
|
|
190
190
|
PathUtil.resolveUnix(__dirname, 'aws-lambda.handler.js'),
|
|
191
191
|
PathUtil.resolveUnix(cfg.workspace, 'index.js')
|
|
192
192
|
)
|
package/bin/cli-pack.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { BasePackPlugin } from './pack-base';
|
|
1
|
+
import { BaseOptions, BasePackPlugin } from './pack-base';
|
|
2
2
|
import { Pack, AllConfig } from './operation/pack';
|
|
3
3
|
|
|
4
|
-
export class PackPlugin extends BasePackPlugin<AllConfig> {
|
|
4
|
+
export class PackPlugin extends BasePackPlugin<BaseOptions, AllConfig> {
|
|
5
5
|
operation = Pack;
|
|
6
6
|
|
|
7
|
-
getOptions() {
|
|
7
|
+
getOptions(): BaseOptions {
|
|
8
8
|
return this.defaultOptions();
|
|
9
9
|
}
|
|
10
10
|
}
|
package/bin/cli-pack_assemble.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OptionConfig } from '@travetto/cli/src/plugin-base';
|
|
2
|
+
|
|
3
|
+
import { BaseOptions, BasePackPlugin } from './pack-base';
|
|
2
4
|
import { Assemble, AssembleConfig } from './operation/assemble';
|
|
3
5
|
|
|
4
|
-
|
|
6
|
+
type Options = BaseOptions & {
|
|
7
|
+
keepSource: OptionConfig<boolean>;
|
|
8
|
+
readonly: OptionConfig<boolean>;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export class PackAssemblePlugin extends BasePackPlugin<Options, AssembleConfig> {
|
|
5
12
|
operation = Assemble;
|
|
6
|
-
|
|
13
|
+
|
|
14
|
+
getOptions(): Options {
|
|
7
15
|
return {
|
|
8
16
|
...this.defaultOptions(),
|
|
9
17
|
keepSource: this.boolOption({ desc: 'Should source be preserved' }),
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import * as fs from 'fs/promises';
|
|
2
2
|
|
|
3
3
|
import { FsUtil, PathUtil } from '@travetto/boot';
|
|
4
|
-
import { BasePlugin } from '@travetto/cli/src/plugin-base';
|
|
4
|
+
import { BasePlugin, OptionConfig } from '@travetto/cli/src/plugin-base';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
type Options = {
|
|
7
|
+
app: OptionConfig<string>;
|
|
8
|
+
image: OptionConfig<string>;
|
|
9
|
+
port: OptionConfig<number>;
|
|
10
|
+
add: OptionConfig<string[]>;
|
|
11
|
+
output: OptionConfig<string>;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export class PackDockerExportPlugin extends BasePlugin<Options> {
|
|
7
15
|
|
|
8
16
|
name = 'pack:docker-export';
|
|
9
17
|
|
|
10
|
-
getOptions() {
|
|
18
|
+
getOptions(): Options {
|
|
11
19
|
return {
|
|
12
20
|
app: this.option({ desc: 'The application target to run', def: 'rest' }),
|
|
13
21
|
image: this.option({ desc: 'Docker image to extend', def: 'node:16-alpine' }),
|
|
@@ -17,7 +25,7 @@ export class PackDockerExportPlugin extends BasePlugin {
|
|
|
17
25
|
};
|
|
18
26
|
}
|
|
19
27
|
|
|
20
|
-
async action(...args: unknown[]) {
|
|
28
|
+
async action(...args: unknown[]): Promise<void> {
|
|
21
29
|
const files = ['src', 'bin', 'support', 'resources', 'package.json', 'package-lock.json', ...this.cmd.add]
|
|
22
30
|
.filter(x => FsUtil.existsSync(PathUtil.resolveUnix(x)));
|
|
23
31
|
|
package/bin/cli-pack_docker.ts
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OptionConfig } from '@travetto/cli/src/plugin-base';
|
|
2
|
+
|
|
3
|
+
import { BaseOptions, BasePackPlugin } from './pack-base';
|
|
2
4
|
import { Docker, DockerConfig } from './operation/docker';
|
|
3
5
|
|
|
4
|
-
|
|
6
|
+
type Options = BaseOptions & {
|
|
7
|
+
image: OptionConfig<string>;
|
|
8
|
+
name: OptionConfig<string>;
|
|
9
|
+
tag: OptionConfig<string[]>;
|
|
10
|
+
port: OptionConfig<string[]>;
|
|
11
|
+
push: OptionConfig<boolean>;
|
|
12
|
+
registry: OptionConfig<string>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export class PackDockerPlugin extends BasePackPlugin<Options, DockerConfig> {
|
|
5
16
|
operation = Docker;
|
|
6
17
|
|
|
7
|
-
getOptions() {
|
|
18
|
+
getOptions(): Options {
|
|
8
19
|
return {
|
|
9
20
|
...this.defaultOptions(),
|
|
10
21
|
image: this.option({ desc: 'Docker Image to extend' }),
|
package/bin/cli-pack_zip.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { OptionConfig } from '@travetto/cli/src/plugin-base';
|
|
2
|
+
|
|
3
|
+
import { BaseOptions, BasePackPlugin } from './pack-base';
|
|
2
4
|
import { Zip, ZipConfig } from './operation/zip';
|
|
3
5
|
|
|
4
|
-
|
|
6
|
+
type Options = BaseOptions & {
|
|
7
|
+
output: OptionConfig<string>;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export class PackZipPlugin extends BasePackPlugin<Options, ZipConfig> {
|
|
5
11
|
operation = Zip;
|
|
6
12
|
|
|
7
|
-
getOptions() {
|
|
13
|
+
getOptions(): Options {
|
|
8
14
|
return {
|
|
9
15
|
...this.defaultOptions(),
|
|
10
16
|
output: this.option({ desc: 'Output File' })
|
package/bin/lib/assemble.ts
CHANGED
|
@@ -3,20 +3,20 @@ import { promises as fs } from 'fs';
|
|
|
3
3
|
|
|
4
4
|
import { ExecUtil, PathUtil, ScanFs, FsUtil } from '@travetto/boot';
|
|
5
5
|
|
|
6
|
-
import { DependenciesUtil, DepType } from './
|
|
6
|
+
import { DependenciesUtil, DepType } from './dependencies';
|
|
7
7
|
import { PackUtil } from './util';
|
|
8
8
|
|
|
9
9
|
const MODULE_DIRS = ['src', 'bin', 'support', 'resources', 'index.ts', 'package.json', 'tsconfig.trv.json'];
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* Utils for
|
|
12
|
+
* Utils for assembling
|
|
13
13
|
*/
|
|
14
14
|
export class AssembleUtil {
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Minimize cached source files, by removing source mapping info
|
|
18
18
|
*/
|
|
19
|
-
static async cleanCache(cache: string) {
|
|
19
|
+
static async cleanCache(cache: string): Promise<void> {
|
|
20
20
|
for (const el of await fs.readdir(cache)) {
|
|
21
21
|
if (el.endsWith('.ts')) {
|
|
22
22
|
const content = (await fs.readFile(`${cache}/${el}`, 'utf8')).replace(/\/\/# sourceMap.*/g, '');
|
|
@@ -28,10 +28,10 @@ export class AssembleUtil {
|
|
|
28
28
|
/**
|
|
29
29
|
* Truncate all app source files, and framework source files
|
|
30
30
|
*/
|
|
31
|
-
static async purgeSource(folders: string[]) {
|
|
31
|
+
static async purgeSource(folders: string[]): Promise<void> {
|
|
32
32
|
for (const sub of folders) {
|
|
33
33
|
for (const f of await ScanFs.scanDir({ testFile: x => x.endsWith('.ts'), testDir: x => true }, sub)) {
|
|
34
|
-
if (f.stats
|
|
34
|
+
if (f.stats?.isFile() && !f.module.startsWith('cli/')) {
|
|
35
35
|
await fs.writeFile(f.file, '');
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -41,17 +41,17 @@ export class AssembleUtil {
|
|
|
41
41
|
/**
|
|
42
42
|
* Copy a module
|
|
43
43
|
*/
|
|
44
|
-
static async copyModule(root: string, target: string) {
|
|
44
|
+
static async copyModule(root: string, target: string): Promise<void> {
|
|
45
45
|
for (const f of MODULE_DIRS) {
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
const found = await FsUtil.exists(
|
|
46
|
+
const sourceFile = PathUtil.resolveUnix(root, f);
|
|
47
|
+
const targetFile = PathUtil.resolveUnix(target, f);
|
|
48
|
+
const found = await FsUtil.exists(sourceFile);
|
|
49
49
|
if (found) {
|
|
50
50
|
if (found.isFile()) {
|
|
51
|
-
await fs.copyFile(
|
|
51
|
+
await fs.copyFile(sourceFile, targetFile);
|
|
52
52
|
} else {
|
|
53
|
-
await fs.mkdir(
|
|
54
|
-
await FsUtil.copyRecursive(`${
|
|
53
|
+
await fs.mkdir(targetFile, { recursive: true });
|
|
54
|
+
await FsUtil.copyRecursive(`${sourceFile}/*`, targetFile);
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
}
|
|
@@ -60,10 +60,10 @@ export class AssembleUtil {
|
|
|
60
60
|
/**
|
|
61
61
|
* Purge workspace using file rules
|
|
62
62
|
*/
|
|
63
|
-
static async excludeFiles(root: string, files: string[]) {
|
|
63
|
+
static async excludeFiles(root: string, files: string[]): Promise<void> {
|
|
64
64
|
const checker = PackUtil.excludeChecker(files, root);
|
|
65
65
|
for (const el of await ScanFs.scanDir({ testDir: x => true, testFile: checker, withHidden: true }, root)) {
|
|
66
|
-
if (!el.stats.isFile()) { continue; }
|
|
66
|
+
if (!el.stats || !el.stats.isFile()) { continue; }
|
|
67
67
|
try {
|
|
68
68
|
await fs.unlink(el.file);
|
|
69
69
|
} catch { }
|
|
@@ -71,9 +71,9 @@ export class AssembleUtil {
|
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
|
-
* Copy over all prod
|
|
74
|
+
* Copy over all prod dependencies
|
|
75
75
|
*/
|
|
76
|
-
static async copyDependencies(workspace: string, types: DepType[] = ['prod', 'opt', 'optPeer']) {
|
|
76
|
+
static async copyDependencies(workspace: string, types: DepType[] = ['prod', 'opt', 'optPeer']): Promise<void> {
|
|
77
77
|
|
|
78
78
|
for (const el of await DependenciesUtil.resolveDependencies({ types })) {
|
|
79
79
|
const sub = PathUtil.normalizeFrameworkPath(el.file, 'node_modules/')
|
|
@@ -103,7 +103,7 @@ export class AssembleUtil {
|
|
|
103
103
|
/**
|
|
104
104
|
* Compile workspace
|
|
105
105
|
*/
|
|
106
|
-
static async buildWorkspace(root: string, cacheDir: string) {
|
|
106
|
+
static async buildWorkspace(root: string, cacheDir: string): Promise<void> {
|
|
107
107
|
await ExecUtil.spawn('node', ['./node_modules/@travetto/cli/bin/trv.js', 'build'],
|
|
108
108
|
{
|
|
109
109
|
cwd: root, isolatedEnv: true,
|
|
@@ -115,7 +115,7 @@ export class AssembleUtil {
|
|
|
115
115
|
/**
|
|
116
116
|
* Copy over added content
|
|
117
117
|
*/
|
|
118
|
-
static async copyAddedContent(workspace: string, files: Record<string, string>[]) {
|
|
118
|
+
static async copyAddedContent(workspace: string, files: Record<string, string>[]): Promise<void> {
|
|
119
119
|
for (const a of files) {
|
|
120
120
|
let [src, dest] = Object.entries(a)[0];
|
|
121
121
|
[src, dest] = [PathUtil.resolveUnix(src), PathUtil.resolveUnix(workspace, dest)];
|
|
@@ -15,6 +15,14 @@ const DEP_MAPPING = {
|
|
|
15
15
|
optPeer: 'optionalPeerDependencies'
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
+
type PackageShape = {
|
|
19
|
+
name: string;
|
|
20
|
+
} & {
|
|
21
|
+
[key: string]: {
|
|
22
|
+
[key: string]: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
18
26
|
/**
|
|
19
27
|
* Utilities for processing the package.json dependencies
|
|
20
28
|
*/
|
|
@@ -25,7 +33,7 @@ export class DependenciesUtil {
|
|
|
25
33
|
* @param dep
|
|
26
34
|
* @param root
|
|
27
35
|
*/
|
|
28
|
-
static resolveDependencyPackageJson(dep: string, root: string) {
|
|
36
|
+
static resolveDependencyPackageJson(dep: string, root: string): string {
|
|
29
37
|
const paths = [root, ...(require.resolve.paths(root) || [])];
|
|
30
38
|
let folder: string;
|
|
31
39
|
try {
|
|
@@ -52,8 +60,8 @@ export class DependenciesUtil {
|
|
|
52
60
|
root = PathUtil.cwd,
|
|
53
61
|
types = ['prod'],
|
|
54
62
|
maxDepth = Number.MAX_SAFE_INTEGER
|
|
55
|
-
}: DepResolveConfig) {
|
|
56
|
-
const pending
|
|
63
|
+
}: DepResolveConfig): Promise<ResolvedDep[]> {
|
|
64
|
+
const pending: [string, number][] = [[root, 0]];
|
|
57
65
|
const foundSet = new Set<string>();
|
|
58
66
|
const found: ResolvedDep[] = [];
|
|
59
67
|
while (pending.length) {
|
|
@@ -61,14 +69,15 @@ export class DependenciesUtil {
|
|
|
61
69
|
if (depth > maxDepth) { // Ignore if greater than valid max depth
|
|
62
70
|
continue;
|
|
63
71
|
}
|
|
64
|
-
|
|
65
|
-
const
|
|
72
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
73
|
+
const p = await import(`${top}/package.json`) as PackageShape;
|
|
74
|
+
const deps: (readonly [name: string, type: DepType, version: string])[] = [];
|
|
66
75
|
for (const type of types) {
|
|
67
76
|
if (
|
|
68
77
|
type !== 'dev' ||
|
|
69
78
|
maxDepth === 0
|
|
70
79
|
) {
|
|
71
|
-
deps.push(...Object.entries(p[DEP_MAPPING[type]] ?? {}).map(([name, version]) => [name, type
|
|
80
|
+
deps.push(...Object.entries(p[DEP_MAPPING[type]] ?? {}).map(([name, version]) => [name, type, version] as const));
|
|
72
81
|
}
|
|
73
82
|
}
|
|
74
83
|
for (const [dep, type, version] of deps) {
|
|
@@ -80,7 +89,7 @@ export class DependenciesUtil {
|
|
|
80
89
|
found.push({ file: resolved, type, dep, version });
|
|
81
90
|
pending.push([resolved, depth + 1]);
|
|
82
91
|
}
|
|
83
|
-
} catch
|
|
92
|
+
} catch {
|
|
84
93
|
if (!dep.startsWith('@types') && type !== 'opt' && type !== 'optPeer') {
|
|
85
94
|
console.error('Unable to resolve', { type, dependency: dep });
|
|
86
95
|
}
|
package/bin/lib/util.ts
CHANGED
|
@@ -18,23 +18,25 @@ export class PackUtil {
|
|
|
18
18
|
static #modes: Partial<CommonConfig>[];
|
|
19
19
|
|
|
20
20
|
static commonExtend<T extends CommonConfig>(a: T, b: Partial<T>): T {
|
|
21
|
-
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
22
|
+
const out = {
|
|
22
23
|
active: b.active ?? a.active,
|
|
23
24
|
workspace: b.workspace ?? a.workspace,
|
|
24
25
|
preProcess: [...(b.preProcess ?? []), ...(a.preProcess ?? [])],
|
|
25
26
|
postProcess: [...(b.postProcess ?? []), ...(a.postProcess ?? [])],
|
|
26
|
-
} as T;
|
|
27
|
+
} as unknown as T;
|
|
28
|
+
return out;
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
/**
|
|
30
32
|
* Find pack modes with associated metadata
|
|
31
33
|
*/
|
|
32
|
-
static async modeList() {
|
|
34
|
+
static async modeList(): Promise<Partial<CommonConfig>[]> {
|
|
33
35
|
if (!this.#modes) {
|
|
34
36
|
this.#modes = await Promise.all(
|
|
35
37
|
SourceIndex.find({ folder: 'support', filter: f => /\/pack[.].*[.]ts/.test(f) })
|
|
36
38
|
.map(async (x) => {
|
|
37
|
-
const req = (await import(x.file)).config
|
|
39
|
+
const req: Partial<CommonConfig> = (await import(x.file)).config;
|
|
38
40
|
req.file = x.module.replace(/^node_modules\//, '');
|
|
39
41
|
return req;
|
|
40
42
|
})
|
|
@@ -47,7 +49,7 @@ export class PackUtil {
|
|
|
47
49
|
/**
|
|
48
50
|
* Build file include/exclude lists/checker
|
|
49
51
|
*/
|
|
50
|
-
static excludeChecker(files: string[], base: string) {
|
|
52
|
+
static excludeChecker(files: string[], base: string): (file: string) => boolean {
|
|
51
53
|
const all = files.map(x => {
|
|
52
54
|
const negate = x.startsWith('!') || x.startsWith('^');
|
|
53
55
|
x = negate ? x.substring(1) : x;
|
|
@@ -57,7 +59,7 @@ export class PackUtil {
|
|
|
57
59
|
return [match, negate] as const;
|
|
58
60
|
});
|
|
59
61
|
|
|
60
|
-
return (f: string) => {
|
|
62
|
+
return (f: string): boolean => {
|
|
61
63
|
let exclude = undefined;
|
|
62
64
|
f = PathUtil.resolveUnix(base, f);
|
|
63
65
|
for (const [match, n] of all) {
|
|
@@ -75,13 +77,13 @@ export class PackUtil {
|
|
|
75
77
|
/**
|
|
76
78
|
* Update .env.js with new env data
|
|
77
79
|
*/
|
|
78
|
-
static async writeEnvJs(workspace: string, env: Record<string, string | undefined>) {
|
|
80
|
+
static async writeEnvJs(workspace: string, env: Record<string, string | undefined>): Promise<void> {
|
|
79
81
|
const out = `${workspace}/.env.js`;
|
|
80
82
|
let src = '';
|
|
81
83
|
if (!!(await FsUtil.exists(out))) {
|
|
82
84
|
src = await fs.readFile(out, 'utf8');
|
|
83
85
|
}
|
|
84
|
-
const lines = Object.entries(env).map(([k, v]) => v ? `process.env['${k}'] = \`${v
|
|
86
|
+
const lines = Object.entries(env).map(([k, v]) => v ? `process.env['${k}'] = \`${v.replace(/`/g, '\\`')}\`;` : '');
|
|
85
87
|
const content = `${src}\n${lines.join('\n')}`;
|
|
86
88
|
await fs.writeFile(PathUtil.resolveUnix(workspace, '.env.js'), content, { encoding: 'utf8' });
|
|
87
89
|
}
|
|
@@ -89,7 +91,7 @@ export class PackUtil {
|
|
|
89
91
|
/**
|
|
90
92
|
* Delete all empty folders
|
|
91
93
|
*/
|
|
92
|
-
static async removeEmptyFolders(root: string) {
|
|
94
|
+
static async removeEmptyFolders(root: string): Promise<void> {
|
|
93
95
|
for (const el of await ScanFs.scanDir({ testDir: x => true, testFile: x => false, withHidden: true }, root)) {
|
|
94
96
|
let dir = el.file;
|
|
95
97
|
while ((await fs.readdir(dir)).length === 0) { // empty
|
|
@@ -102,14 +104,14 @@ export class PackUtil {
|
|
|
102
104
|
/**
|
|
103
105
|
* Run operation with logging
|
|
104
106
|
*/
|
|
105
|
-
static async runOperation<T extends CommonConfig>(op: PackOperation<T>, cfg: T, indent = 0) {
|
|
107
|
+
static async runOperation<T extends CommonConfig>(op: PackOperation<T>, cfg: T, indent = 0): Promise<void> {
|
|
106
108
|
const spacer = ' '.repeat(indent);
|
|
107
109
|
const ctx = await op.context(cfg);
|
|
108
110
|
const title = color`${{ title: op.title }} ${ctx}`;
|
|
109
111
|
const width = Math.max(title.replace(/\x1b\[\d+m/g, '').length, 50); // eslint-disable-line
|
|
110
112
|
|
|
111
113
|
let i = 0;
|
|
112
|
-
function stdout(msg?: string) {
|
|
114
|
+
function stdout(msg?: string): void {
|
|
113
115
|
if (i++ > 0) {
|
|
114
116
|
process.stdout.write(color`${spacer}${{ param: 'done' }}\n`);
|
|
115
117
|
}
|
|
@@ -118,7 +120,7 @@ export class PackUtil {
|
|
|
118
120
|
}
|
|
119
121
|
}
|
|
120
122
|
|
|
121
|
-
async function runPhase(phase: 'preProcess' | 'postProcess') {
|
|
123
|
+
async function runPhase(phase: 'preProcess' | 'postProcess'): Promise<void> {
|
|
122
124
|
for (const el of cfg[phase] ?? []) {
|
|
123
125
|
const [name, fn] = Object.entries(el)[0];
|
|
124
126
|
await stdout(name);
|
|
@@ -56,7 +56,7 @@ export const Assemble: PackOperation<AssembleConfig> = {
|
|
|
56
56
|
yield 'Excluding Post-Compile Files'; await AssembleUtil.excludeFiles(ws, exclude);
|
|
57
57
|
yield 'Copying Added Content'; await AssembleUtil.copyAddedContent(ws, add);
|
|
58
58
|
yield 'Removing Empty Folders'; await PackUtil.removeEmptyFolders(ws);
|
|
59
|
-
yield '
|
|
59
|
+
yield 'Writing Env.js'; await PackUtil.writeEnvJs(ws, {
|
|
60
60
|
...env,
|
|
61
61
|
TRV_CACHE: `\${__dirname}/${cacheDir}`,
|
|
62
62
|
...(readonly ? { TRV_READONLY: '1' } : {})
|
package/bin/operation/docker.ts
CHANGED
|
@@ -19,7 +19,7 @@ export interface DockerConfig extends CommonConfig {
|
|
|
19
19
|
push?: boolean;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
const dockerFileBuilder = ({ image, port, app = 'rest', env }: DockerConfig) => `
|
|
22
|
+
const dockerFileBuilder = ({ image, port, app = 'rest', env }: DockerConfig): string => `
|
|
23
23
|
FROM ${image}
|
|
24
24
|
WORKDIR /app
|
|
25
25
|
COPY . .
|
package/bin/operation/pack.ts
CHANGED
|
@@ -26,6 +26,8 @@ export type AllConfig = CommonConfig &
|
|
|
26
26
|
|
|
27
27
|
export type AllConfigPartial = DeepPartial<AllConfig>;
|
|
28
28
|
|
|
29
|
+
type DefaultOpType = ['assemble', typeof Assemble];
|
|
30
|
+
|
|
29
31
|
export const Pack: PackOperation<AllConfig> = {
|
|
30
32
|
key: '',
|
|
31
33
|
title: 'Packing',
|
|
@@ -33,23 +35,33 @@ export const Pack: PackOperation<AllConfig> = {
|
|
|
33
35
|
const ret: Partial<AllConfig> = {
|
|
34
36
|
workspace: b.workspace ?? a.workspace,
|
|
35
37
|
};
|
|
36
|
-
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
39
|
+
for (const [k, op] of (Object.entries(ops) as DefaultOpType[])) {
|
|
37
40
|
ret[k] = op.extend(op.extend(a[k] ?? {}, b[k] ?? {}), op.overrides ?? {});
|
|
38
41
|
}
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
39
43
|
return ret as AllConfig;
|
|
40
44
|
},
|
|
41
45
|
async context(cfg: AllConfig) {
|
|
42
|
-
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
47
|
+
return `[ ${(Object.entries(ops) as DefaultOpType[])
|
|
48
|
+
.filter(x => cfg[x[0]].active)
|
|
49
|
+
.map(x => x[0])
|
|
50
|
+
.join(', ')} ]`;
|
|
43
51
|
},
|
|
44
52
|
async * exec(cfg: AllConfig) {
|
|
45
|
-
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
54
|
+
const steps = (Object.entries(ops) as DefaultOpType[])
|
|
55
|
+
.filter(x => cfg[x[0]].active);
|
|
56
|
+
|
|
46
57
|
if (!steps.length) {
|
|
47
58
|
throw new Error('Pack operation has zero active steps');
|
|
48
59
|
}
|
|
49
|
-
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
61
|
+
for (const [step, op] of steps as DefaultOpType[]) {
|
|
50
62
|
process.stdout.write('\n');
|
|
51
|
-
cfg[step
|
|
52
|
-
await PackUtil.runOperation(op
|
|
63
|
+
cfg[step].workspace = cfg.workspace;
|
|
64
|
+
await PackUtil.runOperation(op, cfg[step], 2);
|
|
53
65
|
}
|
|
54
66
|
process.stdout.write('\n');
|
|
55
67
|
yield color`${{ success: 'Successfully' }} packed project`;
|
package/bin/pack-base.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as os from 'os';
|
|
2
2
|
|
|
3
|
-
import { BasePlugin } from '@travetto/cli/src/plugin-base';
|
|
3
|
+
import { BasePlugin, OptionConfig } from '@travetto/cli/src/plugin-base';
|
|
4
4
|
import { color } from '@travetto/cli/src/color';
|
|
5
5
|
import { PathUtil, Package, FsUtil } from '@travetto/boot';
|
|
6
6
|
|
|
@@ -12,21 +12,25 @@ const packName = `pack_${Package.name}`
|
|
|
12
12
|
.replace(/[^a-z]+/g, '_')
|
|
13
13
|
.replace(/_+/g, '_');
|
|
14
14
|
|
|
15
|
+
export type BaseOptions = {
|
|
16
|
+
workspace: OptionConfig<string>;
|
|
17
|
+
};
|
|
18
|
+
|
|
15
19
|
/**
|
|
16
20
|
* Supports packing a project into a directory, ready for archiving
|
|
17
21
|
*/
|
|
18
|
-
export abstract class BasePackPlugin<C extends CommonConfig> extends BasePlugin {
|
|
22
|
+
export abstract class BasePackPlugin<V extends BaseOptions, C extends CommonConfig> extends BasePlugin<V> {
|
|
19
23
|
|
|
20
24
|
/**
|
|
21
25
|
* Package stage name
|
|
22
26
|
*/
|
|
23
27
|
abstract get operation(): PackOperation<C>;
|
|
24
28
|
|
|
25
|
-
get name() {
|
|
29
|
+
get name(): string {
|
|
26
30
|
return this.operation.key ? `pack:${this.operation.key}` : 'pack';
|
|
27
31
|
}
|
|
28
32
|
|
|
29
|
-
defaultOptions() {
|
|
33
|
+
defaultOptions(): BaseOptions {
|
|
30
34
|
return { workspace: this.option({ desc: 'Working directory' }) } as const;
|
|
31
35
|
}
|
|
32
36
|
|
|
@@ -41,19 +45,21 @@ export abstract class BasePackPlugin<C extends CommonConfig> extends BasePlugin
|
|
|
41
45
|
this.showHelp(`Unknown config mode: ${this.args[0]}`);
|
|
42
46
|
}
|
|
43
47
|
const def = list.find(c => c.name === 'default');
|
|
44
|
-
const out
|
|
48
|
+
const out = [def, cfg, extra]
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
45
50
|
.map(x => this.operation.key && this.operation.key in (x ?? {}) ? ((x as Record<string, C>)[this.operation.key] as C) : x as C)
|
|
46
|
-
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
52
|
+
.reduce<C>((acc, l) => this.operation.extend(acc, l ?? {}), (this.operation.overrides ?? {}) as C);
|
|
47
53
|
out.workspace ??= PathUtil.resolveUnix(os.tmpdir(), packName);
|
|
48
54
|
out.active = true;
|
|
49
55
|
return out;
|
|
50
56
|
}
|
|
51
57
|
|
|
52
|
-
getArgs() {
|
|
58
|
+
getArgs(): string {
|
|
53
59
|
return '[mode]';
|
|
54
60
|
}
|
|
55
61
|
|
|
56
|
-
async help() {
|
|
62
|
+
async help(): Promise<string> {
|
|
57
63
|
const lines = await PackUtil.modeList();
|
|
58
64
|
|
|
59
65
|
const out = [];
|
|
@@ -67,15 +73,15 @@ export abstract class BasePackPlugin<C extends CommonConfig> extends BasePlugin
|
|
|
67
73
|
return out.join('\n');
|
|
68
74
|
}
|
|
69
75
|
|
|
70
|
-
override async complete() {
|
|
76
|
+
override async complete(): Promise<Record<string, string[]>> {
|
|
71
77
|
return { '': (await PackUtil.modeList()).map(x => x.name!) };
|
|
72
78
|
}
|
|
73
79
|
|
|
74
|
-
async action() {
|
|
75
|
-
const resolved = await this.resolveConfigs();
|
|
80
|
+
async action(): Promise<void> {
|
|
81
|
+
const resolved: C = await this.resolveConfigs();
|
|
76
82
|
if (await FsUtil.exists(PathUtil.resolveUnix(resolved.workspace, '.git'))) {
|
|
77
83
|
throw new Error('Refusing to use workspace with a .git directory');
|
|
78
84
|
}
|
|
79
|
-
return PackUtil.runOperation(this.operation, resolved
|
|
85
|
+
return PackUtil.runOperation(this.operation, resolved);
|
|
80
86
|
}
|
|
81
87
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/pack",
|
|
3
3
|
"displayName": "Pack",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.2.2",
|
|
5
5
|
"description": "Code packing utilities",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"travetto",
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
"directory": "module/pack"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@travetto/base": "^2.
|
|
28
|
+
"@travetto/base": "^2.2.2",
|
|
29
29
|
"@types/picomatch": "^2.3.0",
|
|
30
30
|
"picomatch": "^2.3.1"
|
|
31
31
|
},
|
|
32
32
|
"optionalPeerDependencies": {
|
|
33
|
-
"@travetto/cli": "^2.
|
|
33
|
+
"@travetto/cli": "^2.2.2"
|
|
34
34
|
},
|
|
35
35
|
"docDependencies": {
|
|
36
36
|
"@travetto/rest": true
|
package/support/pack.config.ts
CHANGED