@diquattro/cfnassets 0.6.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.
- package/README.md +55 -0
- package/lib/cli/build.d.ts +3 -0
- package/lib/cli/build.d.ts.map +1 -0
- package/lib/cli/build.js +77 -0
- package/lib/cli/build.js.map +1 -0
- package/lib/cli/cfnassets.d.ts +3 -0
- package/lib/cli/cfnassets.d.ts.map +1 -0
- package/lib/cli/cfnassets.js +7 -0
- package/lib/cli/cfnassets.js.map +1 -0
- package/lib/core/rollup/makeRollupPackageStream.d.ts +16 -0
- package/lib/core/rollup/makeRollupPackageStream.d.ts.map +1 -0
- package/lib/core/rollup/makeRollupPackageStream.js +27 -0
- package/lib/core/rollup/makeRollupPackageStream.js.map +1 -0
- package/lib/core/rollup/rollupPackageDir.d.ts +14 -0
- package/lib/core/rollup/rollupPackageDir.d.ts.map +1 -0
- package/lib/core/rollup/rollupPackageDir.js +36 -0
- package/lib/core/rollup/rollupPackageDir.js.map +1 -0
- package/lib/core/rollup/rollupPackageEntries.d.ts +5 -0
- package/lib/core/rollup/rollupPackageEntries.d.ts.map +1 -0
- package/lib/core/rollup/rollupPackageEntries.js +35 -0
- package/lib/core/rollup/rollupPackageEntries.js.map +1 -0
- package/lib/core/zip/ZipAssetEntry.d.ts +9 -0
- package/lib/core/zip/ZipAssetEntry.d.ts.map +1 -0
- package/lib/core/zip/ZipAssetEntry.js +2 -0
- package/lib/core/zip/ZipAssetEntry.js.map +1 -0
- package/lib/core/zip/getFolderEntries.d.ts +8 -0
- package/lib/core/zip/getFolderEntries.d.ts.map +1 -0
- package/lib/core/zip/getFolderEntries.js +32 -0
- package/lib/core/zip/getFolderEntries.js.map +1 -0
- package/lib/core/zip/getPackageEntries.d.ts +12 -0
- package/lib/core/zip/getPackageEntries.d.ts.map +1 -0
- package/lib/core/zip/getPackageEntries.js +73 -0
- package/lib/core/zip/getPackageEntries.js.map +1 -0
- package/lib/core/zip/makeZipPackageStream.d.ts +5 -0
- package/lib/core/zip/makeZipPackageStream.d.ts.map +1 -0
- package/lib/core/zip/makeZipPackageStream.js +29 -0
- package/lib/core/zip/makeZipPackageStream.js.map +1 -0
- package/lib/core/zip/zipDir.d.ts +8 -0
- package/lib/core/zip/zipDir.d.ts.map +1 -0
- package/lib/core/zip/zipDir.js +24 -0
- package/lib/core/zip/zipDir.js.map +1 -0
- package/lib/index.d.ts +25 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +26 -0
- package/lib/index.js.map +1 -0
- package/lib/internal/HashStream.d.ts +13 -0
- package/lib/internal/HashStream.d.ts.map +1 -0
- package/lib/internal/HashStream.js +28 -0
- package/lib/internal/HashStream.js.map +1 -0
- package/lib/internal/ProgressStream.d.ts +11 -0
- package/lib/internal/ProgressStream.d.ts.map +1 -0
- package/lib/internal/ProgressStream.js +25 -0
- package/lib/internal/ProgressStream.js.map +1 -0
- package/lib/internal/addBundleInfoToPackageJson.d.ts +6 -0
- package/lib/internal/addBundleInfoToPackageJson.d.ts.map +1 -0
- package/lib/internal/addBundleInfoToPackageJson.js +36 -0
- package/lib/internal/addBundleInfoToPackageJson.js.map +1 -0
- package/lib/internal/getPackagePath.d.ts +2 -0
- package/lib/internal/getPackagePath.d.ts.map +1 -0
- package/lib/internal/getPackagePath.js +11 -0
- package/lib/internal/getPackagePath.js.map +1 -0
- package/lib/internal/hash.d.ts +3 -0
- package/lib/internal/hash.d.ts.map +1 -0
- package/lib/internal/hash.js +9 -0
- package/lib/internal/hash.js.map +1 -0
- package/lib/internal/readDotIgnoreFile.d.ts +2 -0
- package/lib/internal/readDotIgnoreFile.d.ts.map +1 -0
- package/lib/internal/readDotIgnoreFile.js +13 -0
- package/lib/internal/readDotIgnoreFile.js.map +1 -0
- package/lib/internal/readDotIgnoreForFolder.d.ts +2 -0
- package/lib/internal/readDotIgnoreForFolder.d.ts.map +1 -0
- package/lib/internal/readDotIgnoreForFolder.js +6 -0
- package/lib/internal/readDotIgnoreForFolder.js.map +1 -0
- package/lib/internal/tryStat.d.ts +4 -0
- package/lib/internal/tryStat.d.ts.map +1 -0
- package/lib/internal/tryStat.js +13 -0
- package/lib/internal/tryStat.js.map +1 -0
- package/lib/template/AssetAttributes.d.ts +5 -0
- package/lib/template/AssetAttributes.d.ts.map +1 -0
- package/lib/template/AssetAttributes.js +2 -0
- package/lib/template/AssetAttributes.js.map +1 -0
- package/lib/template/AssetBase.d.ts +14 -0
- package/lib/template/AssetBase.d.ts.map +1 -0
- package/lib/template/AssetBase.js +34 -0
- package/lib/template/AssetBase.js.map +1 -0
- package/lib/template/AssetBuilder.d.ts +6 -0
- package/lib/template/AssetBuilder.d.ts.map +1 -0
- package/lib/template/AssetBuilder.js +2 -0
- package/lib/template/AssetBuilder.js.map +1 -0
- package/lib/template/AssetContext.d.ts +7 -0
- package/lib/template/AssetContext.d.ts.map +1 -0
- package/lib/template/AssetContext.js +12 -0
- package/lib/template/AssetContext.js.map +1 -0
- package/lib/template/AssetDefinition.d.ts +8 -0
- package/lib/template/AssetDefinition.d.ts.map +1 -0
- package/lib/template/AssetDefinition.js +2 -0
- package/lib/template/AssetDefinition.js.map +1 -0
- package/lib/template/AssetGenerator.d.ts +5 -0
- package/lib/template/AssetGenerator.d.ts.map +1 -0
- package/lib/template/AssetGenerator.js +2 -0
- package/lib/template/AssetGenerator.js.map +1 -0
- package/lib/template/AssetManifest.d.ts +13 -0
- package/lib/template/AssetManifest.d.ts.map +1 -0
- package/lib/template/AssetManifest.js +12 -0
- package/lib/template/AssetManifest.js.map +1 -0
- package/lib/template/AssetOutput.d.ts +7 -0
- package/lib/template/AssetOutput.d.ts.map +1 -0
- package/lib/template/AssetOutput.js +2 -0
- package/lib/template/AssetOutput.js.map +1 -0
- package/lib/template/AssetRef.d.ts +5 -0
- package/lib/template/AssetRef.d.ts.map +1 -0
- package/lib/template/AssetRef.js +2 -0
- package/lib/template/AssetRef.js.map +1 -0
- package/lib/template/CustomAsset.d.ts +7 -0
- package/lib/template/CustomAsset.d.ts.map +1 -0
- package/lib/template/CustomAsset.js +9 -0
- package/lib/template/CustomAsset.js.map +1 -0
- package/lib/template/DeploymentBundle.d.ts +16 -0
- package/lib/template/DeploymentBundle.d.ts.map +1 -0
- package/lib/template/DeploymentBundle.js +2 -0
- package/lib/template/DeploymentBundle.js.map +1 -0
- package/lib/template/FileSystemDeploymentBundle.d.ts +20 -0
- package/lib/template/FileSystemDeploymentBundle.d.ts.map +1 -0
- package/lib/template/FileSystemDeploymentBundle.js +72 -0
- package/lib/template/FileSystemDeploymentBundle.js.map +1 -0
- package/lib/template/ProgressStats.d.ts +6 -0
- package/lib/template/ProgressStats.d.ts.map +1 -0
- package/lib/template/ProgressStats.js +2 -0
- package/lib/template/ProgressStats.js.map +1 -0
- package/lib/template/makeAsset.d.ts +5 -0
- package/lib/template/makeAsset.d.ts.map +1 -0
- package/lib/template/makeAsset.js +6 -0
- package/lib/template/makeAsset.js.map +1 -0
- package/lib/template/makeAssetFromPackage.d.ts +12 -0
- package/lib/template/makeAssetFromPackage.d.ts.map +1 -0
- package/lib/template/makeAssetFromPackage.js +29 -0
- package/lib/template/makeAssetFromPackage.js.map +1 -0
- package/lib/template/processAssets.d.ts +4 -0
- package/lib/template/processAssets.d.ts.map +1 -0
- package/lib/template/processAssets.js +24 -0
- package/lib/template/processAssets.js.map +1 -0
- package/package.json +71 -0
- package/src/cli/build.ts +131 -0
- package/src/cli/cfnassets.ts +9 -0
- package/src/core/rollup/makeRollupPackageStream.ts +55 -0
- package/src/core/rollup/rollupPackageDir.ts +64 -0
- package/src/core/rollup/rollupPackageEntries.ts +46 -0
- package/src/core/zip/ZipAssetEntry.ts +11 -0
- package/src/core/zip/getFolderEntries.ts +47 -0
- package/src/core/zip/getPackageEntries.ts +104 -0
- package/src/core/zip/makeZipPackageStream.ts +41 -0
- package/src/core/zip/zipDir.ts +43 -0
- package/src/index.ts +25 -0
- package/src/internal/HashStream.ts +36 -0
- package/src/internal/ProgressStream.ts +32 -0
- package/src/internal/addBundleInfoToPackageJson.ts +52 -0
- package/src/internal/getPackagePath.ts +13 -0
- package/src/internal/hash.ts +9 -0
- package/src/internal/readDotIgnoreFile.ts +15 -0
- package/src/internal/readDotIgnoreForFolder.ts +8 -0
- package/src/internal/tryStat.ts +12 -0
- package/src/template/AssetAttributes.ts +5 -0
- package/src/template/AssetBase.ts +60 -0
- package/src/template/AssetBuilder.ts +8 -0
- package/src/template/AssetContext.ts +15 -0
- package/src/template/AssetDefinition.ts +8 -0
- package/src/template/AssetGenerator.ts +5 -0
- package/src/template/AssetManifest.ts +25 -0
- package/src/template/AssetOutput.ts +6 -0
- package/src/template/AssetRef.ts +4 -0
- package/src/template/CustomAsset.ts +11 -0
- package/src/template/DeploymentBundle.ts +20 -0
- package/src/template/FileSystemDeploymentBundle.ts +112 -0
- package/src/template/ProgressStats.ts +5 -0
- package/src/template/makeAsset.ts +12 -0
- package/src/template/makeAssetFromPackage.ts +42 -0
- package/src/template/processAssets.ts +40 -0
- package/src/types/loadConfigFile.d.ts +20 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CustomAsset.js","sourceRoot":"","sources":["../../src/template/CustomAsset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C,MAAM,OAAO,WAAY,SAAQ,SAAS;IAGtB;IAFlB,YACE,IAAY,EACI,QAAwB;QAExC,KAAK,CAAC,IAAI,CAAC,CAAC;QAFI,aAAQ,GAAR,QAAQ,CAAgB;IAG1C,CAAC;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import { Readable } from 'stream';
|
|
4
|
+
export interface AddAssetOpts {
|
|
5
|
+
keepName?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface DeploymentBundleAsset {
|
|
8
|
+
name: string;
|
|
9
|
+
size: number;
|
|
10
|
+
createReadStream(encoding?: BufferEncoding): Readable;
|
|
11
|
+
}
|
|
12
|
+
export interface DeploymentBundle {
|
|
13
|
+
addAsset(fileName: string, stream: Readable, opts?: AddAssetOpts): PromiseLike<string>;
|
|
14
|
+
assets: DeploymentBundleAsset[];
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=DeploymentBundle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeploymentBundle.d.ts","sourceRoot":"","sources":["../../src/template/DeploymentBundle.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB,CAAC,QAAQ,CAAC,EAAE,cAAc,GAAG,QAAQ,CAAC;CACvD;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CACN,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,QAAQ,EAChB,IAAI,CAAC,EAAE,YAAY,GAClB,WAAW,CAAC,MAAM,CAAC,CAAC;IACvB,MAAM,EAAE,qBAAqB,EAAE,CAAC;CACjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeploymentBundle.js","sourceRoot":"","sources":["../../src/template/DeploymentBundle.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import { Readable } from 'stream';
|
|
3
|
+
import { TypedEmitter } from 'tiny-typed-emitter';
|
|
4
|
+
import { AddAssetOpts, DeploymentBundle, DeploymentBundleAsset } from './DeploymentBundle.js';
|
|
5
|
+
import { ProgressStats } from './ProgressStats.js';
|
|
6
|
+
export interface FileSystemBundleOptions {
|
|
7
|
+
stagingDirectory?: string;
|
|
8
|
+
}
|
|
9
|
+
export interface FileSystemDeploymentBundleEvents {
|
|
10
|
+
assetProgress(name: string, stats: ProgressStats): void;
|
|
11
|
+
assetRename(oldName: string, rename: string): void;
|
|
12
|
+
}
|
|
13
|
+
export declare class FileSystemDeploymentBundle extends TypedEmitter<FileSystemDeploymentBundleEvents> implements DeploymentBundle {
|
|
14
|
+
private readonly outputDir;
|
|
15
|
+
readonly assets: DeploymentBundleAsset[];
|
|
16
|
+
constructor(options: FileSystemBundleOptions);
|
|
17
|
+
addAsset(fileName: string, content: Readable, opts?: AddAssetOpts): Promise<string>;
|
|
18
|
+
private getOutputDir;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=FileSystemDeploymentBundle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileSystemDeploymentBundle.d.ts","sourceRoot":"","sources":["../../src/template/FileSystemDeploymentBundle.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAGlC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIlD,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,qBAAqB,EACtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,WAAW,uBAAuB;IACtC,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,gCAAgC;IAC/C,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,IAAI,CAAC;IACxD,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACpD;AAED,qBAAa,0BACX,SAAQ,YAAY,CAAC,gCAAgC,CACrD,YAAW,gBAAgB;IAE3B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,SAAgB,MAAM,EAAE,qBAAqB,EAAE,CAAM;gBAEzC,OAAO,EAAE,uBAAuB;IAK/B,QAAQ,CACnB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,QAAQ,EACjB,IAAI,GAAE,YAAiB,GACtB,OAAO,CAAC,MAAM,CAAC;IA2DlB,OAAO,CAAC,YAAY,CASf;CACN"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { createReadStream, createWriteStream } from 'fs';
|
|
2
|
+
import { mkdir, rename, stat } from 'fs/promises';
|
|
3
|
+
import { basename, dirname, extname, join } from 'path';
|
|
4
|
+
import { pipeline } from 'stream/promises';
|
|
5
|
+
import { temporaryDirectory } from 'tempy';
|
|
6
|
+
import { TypedEmitter } from 'tiny-typed-emitter';
|
|
7
|
+
import { hash } from '../internal/hash.js';
|
|
8
|
+
import { HashStream } from '../internal/HashStream.js';
|
|
9
|
+
import { ProgressStream } from '../internal/ProgressStream.js';
|
|
10
|
+
export class FileSystemDeploymentBundle extends TypedEmitter {
|
|
11
|
+
outputDir;
|
|
12
|
+
assets = [];
|
|
13
|
+
constructor(options) {
|
|
14
|
+
super();
|
|
15
|
+
this.outputDir = options.stagingDirectory ?? temporaryDirectory();
|
|
16
|
+
}
|
|
17
|
+
async addAsset(fileName, content, opts = {}) {
|
|
18
|
+
if (dirname(fileName) !== '.') {
|
|
19
|
+
throw new Error(`the fileName must not be within a directory`);
|
|
20
|
+
}
|
|
21
|
+
this.emit('assetProgress', fileName, {});
|
|
22
|
+
const outDir = await this.getOutputDir();
|
|
23
|
+
const originalExt = extname(fileName);
|
|
24
|
+
const originalBasename = basename(fileName, originalExt);
|
|
25
|
+
const stagingExt = `.stagingprogress_${hash([
|
|
26
|
+
`${Date.now()}`,
|
|
27
|
+
fileName,
|
|
28
|
+
`${Math.random()}`,
|
|
29
|
+
])}`;
|
|
30
|
+
const outPath = join(outDir, fileName + stagingExt);
|
|
31
|
+
const outStream = createWriteStream(outPath);
|
|
32
|
+
const progress = new ProgressStream((total) => this.emit('assetProgress', fileName, { total }));
|
|
33
|
+
progress.on('finish', () => this.emit('assetProgress', fileName, { complete: true }));
|
|
34
|
+
if (opts.keepName) {
|
|
35
|
+
await pipeline(content, progress, outStream);
|
|
36
|
+
const finalPath = join(outDir, originalBasename + originalExt);
|
|
37
|
+
await rename(outPath, finalPath);
|
|
38
|
+
this.assets.push({
|
|
39
|
+
name: fileName,
|
|
40
|
+
size: (await stat(finalPath)).size,
|
|
41
|
+
createReadStream: (encoding) => createReadStream(finalPath, encoding),
|
|
42
|
+
});
|
|
43
|
+
return fileName;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
const hashStream = new HashStream();
|
|
47
|
+
await pipeline(content, progress, hashStream, outStream);
|
|
48
|
+
const sha = hashStream.digest('hex');
|
|
49
|
+
const finalBasename = originalBasename + `.${sha}` + originalExt;
|
|
50
|
+
const finalPath = join(outDir, finalBasename);
|
|
51
|
+
await rename(outPath, finalPath);
|
|
52
|
+
this.emit('assetRename', fileName, finalBasename);
|
|
53
|
+
this.assets.push({
|
|
54
|
+
name: finalBasename,
|
|
55
|
+
size: (await stat(finalPath)).size,
|
|
56
|
+
createReadStream: (encoding) => createReadStream(finalPath, encoding),
|
|
57
|
+
});
|
|
58
|
+
return finalBasename;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
getOutputDir = (() => {
|
|
62
|
+
let created = false;
|
|
63
|
+
return async () => {
|
|
64
|
+
if (!created) {
|
|
65
|
+
await mkdir(this.outputDir, { recursive: true });
|
|
66
|
+
created = true;
|
|
67
|
+
}
|
|
68
|
+
return this.outputDir;
|
|
69
|
+
};
|
|
70
|
+
})();
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=FileSystemDeploymentBundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileSystemDeploymentBundle.js","sourceRoot":"","sources":["../../src/template/FileSystemDeploymentBundle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,iB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1 @@
|
|
|
1
|
+
{"version":3,"file":"ProgressStats.js","sourceRoot":"","sources":["../../src/template/ProgressStats.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { TemplateBuilder } from '@awboost/cfntemplate';
|
|
2
|
+
import { AssetAttributes } from './AssetAttributes.js';
|
|
3
|
+
import { AssetGenerator } from './AssetGenerator.js';
|
|
4
|
+
export declare function makeAsset(name: string, generate: AssetGenerator): [TemplateBuilder, AssetAttributes];
|
|
5
|
+
//# sourceMappingURL=makeAsset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeAsset.d.ts","sourceRoot":"","sources":["../../src/template/makeAsset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,cAAc,GACvB,CAAC,eAAe,EAAE,eAAe,CAAC,CAGpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeAsset.js","sourceRoot":"","sources":["../../src/template/makeAsset.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,UAAU,SAAS,CACvB,IAAY,EACZ,QAAwB;IAExB,MAAM,KAAK,GAAG,IAAI,WAAW,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC9C,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TemplateBuilder } from '@awboost/cfntemplate';
|
|
2
|
+
import { AssetAttributes } from './AssetAttributes.js';
|
|
3
|
+
import { AssetBase } from './AssetBase.js';
|
|
4
|
+
import { AssetOutput } from './AssetOutput.js';
|
|
5
|
+
export declare class PackageAsset extends AssetBase {
|
|
6
|
+
private readonly packagePath;
|
|
7
|
+
private readonly assetName;
|
|
8
|
+
constructor(name: string, packagePath: string, assetName: string);
|
|
9
|
+
generate(): Promise<AssetOutput>;
|
|
10
|
+
}
|
|
11
|
+
export declare function makeAssetFromPackage(name: string, packagePath: string, assetName: string): [TemplateBuilder, AssetAttributes];
|
|
12
|
+
//# sourceMappingURL=makeAssetFromPackage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeAssetFromPackage.d.ts","sourceRoot":"","sources":["../../src/template/makeAssetFromPackage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAIvD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,qBAAa,YAAa,SAAQ,SAAS;IAGvC,OAAO,CAAC,QAAQ,CAAC,WAAW;IAC5B,OAAO,CAAC,QAAQ,CAAC,SAAS;gBAF1B,IAAI,EAAE,MAAM,EACK,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM;IAKd,QAAQ,IAAI,OAAO,CAAC,WAAW,CAAC;CAevD;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,GAChB,CAAC,eAAe,EAAE,eAAe,CAAC,CAGpC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createReadStream } from 'fs';
|
|
2
|
+
import { readFile } from 'fs/promises';
|
|
3
|
+
import { basename, dirname, join } from 'path';
|
|
4
|
+
import { AssetBase } from './AssetBase.js';
|
|
5
|
+
export class PackageAsset extends AssetBase {
|
|
6
|
+
packagePath;
|
|
7
|
+
assetName;
|
|
8
|
+
constructor(name, packagePath, assetName) {
|
|
9
|
+
super(name);
|
|
10
|
+
this.packagePath = packagePath;
|
|
11
|
+
this.assetName = assetName;
|
|
12
|
+
}
|
|
13
|
+
async generate() {
|
|
14
|
+
const pkg = JSON.parse(await readFile(this.packagePath, 'utf8'));
|
|
15
|
+
if (!pkg.bundles || !pkg.bundles[this.assetName]?.path) {
|
|
16
|
+
throw new Error(`expected package.json to have a bundles entry for '${this.assetName}'`);
|
|
17
|
+
}
|
|
18
|
+
const assetPath = pkg.bundles[this.assetName].path;
|
|
19
|
+
return {
|
|
20
|
+
content: createReadStream(join(dirname(this.packagePath), assetPath)),
|
|
21
|
+
fileName: basename(assetPath),
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export function makeAssetFromPackage(name, packagePath, assetName) {
|
|
26
|
+
const asset = new PackageAsset(name, packagePath, assetName);
|
|
27
|
+
return [asset, asset];
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=makeAssetFromPackage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeAssetFromPackage.js","sourceRoot":"","sources":["../../src/template/makeAssetFromPackage.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,IAAI,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE/C,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C,MAAM,OAAO,YAAa,SAAQ,SAAS;IAGtB;IACA;IAHnB,YACE,IAAY,EACK,WAAmB,EACnB,SAAiB;QAElC,KAAK,CAAC,IAAI,CAAC,CAAC;QAHK,gBAAW,GAAX,WAAW,CAAQ;QACnB,cAAS,GAAT,SAAS,CAAQ;IAGpC,CAAC;IAEe,KAAK,CAAC,QAAQ;QAC5B,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;QAEjE,IAAI,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE;YACtD,MAAM,IAAI,KAAK,CACb,sDAAsD,IAAI,CAAC,SAAS,GAAG,CACxE,CAAC;SACH;QACD,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC;QAEnD,OAAO;YACL,OAAO,EAAE,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,SAAS,CAAC,CAAC;YACrE,QAAQ,EAAE,QAAQ,CAAC,SAAS,CAAC;SAC9B,CAAC;IACJ,CAAC;CACF;AAED,MAAM,UAAU,oBAAoB,CAClC,IAAY,EACZ,WAAmB,EACnB,SAAiB;IAEjB,MAAM,KAAK,GAAG,IAAI,YAAY,CAAC,IAAI,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;IAC7D,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { BuilderContext, Template } from '@awboost/cfntemplate';
|
|
2
|
+
import { DeploymentBundle } from './DeploymentBundle.js';
|
|
3
|
+
export declare function processAssets(template: Template, ctx: BuilderContext, bundle: DeploymentBundle): Promise<Template>;
|
|
4
|
+
//# sourceMappingURL=processAssets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processAssets.d.ts","sourceRoot":"","sources":["../../src/template/processAssets.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,QAAQ,EAET,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,wBAAsB,aAAa,CACjC,QAAQ,EAAE,QAAQ,EAClB,GAAG,EAAE,cAAc,EACnB,MAAM,EAAE,gBAAgB,GACvB,OAAO,CAAC,QAAQ,CAAC,CA0BnB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { TemplateFragment, } from '@awboost/cfntemplate';
|
|
2
|
+
import { AssetContext } from './AssetContext.js';
|
|
3
|
+
import { AssetManifestMetadataKey } from './AssetManifest.js';
|
|
4
|
+
export async function processAssets(template, ctx, bundle) {
|
|
5
|
+
const assets = ctx.get(AssetContext).assets;
|
|
6
|
+
if (!assets?.length) {
|
|
7
|
+
return template;
|
|
8
|
+
}
|
|
9
|
+
const manifest = {
|
|
10
|
+
assets: [],
|
|
11
|
+
};
|
|
12
|
+
for (const asset of assets) {
|
|
13
|
+
const output = await asset.generate();
|
|
14
|
+
const key = await bundle.addAsset(output.fileName, output.content);
|
|
15
|
+
manifest.assets.push({
|
|
16
|
+
bucketParam: asset.parameters.S3Bucket,
|
|
17
|
+
key,
|
|
18
|
+
keyParam: asset.parameters.S3Key,
|
|
19
|
+
name: asset.name,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return TemplateFragment.metadata(AssetManifestMetadataKey, manifest).build(template, ctx);
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=processAssets.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"processAssets.js","sourceRoot":"","sources":["../../src/template/processAssets.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAiB,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAG7E,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,QAAkB,EAClB,GAAmB,EACnB,MAAwB;IAExB,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC;IAC5C,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE;QACnB,OAAO,QAAQ,CAAC;KACjB;IAED,MAAM,QAAQ,GAAkB;QAC9B,MAAM,EAAE,EAAE;KACX,CAAC;IAEF,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;QAC1B,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,QAAQ,EAAE,CAAC;QACtC,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;QAEnE,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC;YACnB,WAAW,EAAE,KAAK,CAAC,UAAU,CAAC,QAAQ;YACtC,GAAG;YACH,QAAQ,EAAE,KAAK,CAAC,UAAU,CAAC,KAAK;YAChC,IAAI,EAAE,KAAK,CAAC,IAAI;SACjB,CAAC,CAAC;KACJ;IAED,OAAO,gBAAgB,CAAC,QAAQ,CAAC,wBAAwB,EAAE,QAAQ,CAAC,CAAC,KAAK,CACxE,QAAQ,EACR,GAAG,CACJ,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@diquattro/cfnassets",
|
|
3
|
+
"version": "0.6.1",
|
|
4
|
+
"description": "Build asset zip packages for deployment. Fork of @awboost/cfnassets with pnpm support.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/diegodi4/cfnassets.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/diegodi4/cfnassets#readme",
|
|
11
|
+
"author": "diegodi4",
|
|
12
|
+
"contributors": [
|
|
13
|
+
{
|
|
14
|
+
"name": "Gordon Leigh",
|
|
15
|
+
"email": "gordonmleigh@gmail.com"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"private": false,
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./lib/index.d.ts",
|
|
26
|
+
"default": "./lib/index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"bin": {
|
|
30
|
+
"cfnassets": "./lib/cli/cfnassets.js"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"lib/**/*.js",
|
|
34
|
+
"lib/**/*.d.ts",
|
|
35
|
+
"lib/**/*.map",
|
|
36
|
+
"!lib/**/*.test.*",
|
|
37
|
+
"src/**/*.ts",
|
|
38
|
+
"!src/**/*.test.ts"
|
|
39
|
+
],
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "npm run clean && npm run index && npm run compile && npm run lint",
|
|
42
|
+
"clean": "rm -rf docs/ lib/ *.tsbuildinfo",
|
|
43
|
+
"compile": "npm run index && tsc",
|
|
44
|
+
"index": "node makeIndex.js src/",
|
|
45
|
+
"lint": "eslint src/ --ext=ts",
|
|
46
|
+
"watch:compile": "tsc -w"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/archiver": "^5.3.1",
|
|
50
|
+
"@types/node": "^18.18.13",
|
|
51
|
+
"@typescript-eslint/eslint-plugin": "^6.12.0",
|
|
52
|
+
"@typescript-eslint/parser": "^6.12.0",
|
|
53
|
+
"eslint": "^8.54.0",
|
|
54
|
+
"eslint-config-prettier": "^9.0.0",
|
|
55
|
+
"eslint-plugin-import": "^2.29.0",
|
|
56
|
+
"eslint-plugin-prettier": "^5.0.1",
|
|
57
|
+
"prettier": "^3.1.0",
|
|
58
|
+
"typescript": "~5.2"
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@awboost/cfntemplate": "^0.6.0",
|
|
62
|
+
"@fmtk/decoders": "^0.5.2",
|
|
63
|
+
"archiver": "^5.3.1",
|
|
64
|
+
"chalk": "^5.0.1",
|
|
65
|
+
"commander": "^9.2.0",
|
|
66
|
+
"ignore": "^5.2.0",
|
|
67
|
+
"rollup": "^2.73.0",
|
|
68
|
+
"tempy": "^3.0.0",
|
|
69
|
+
"tiny-typed-emitter": "^2.1.0"
|
|
70
|
+
}
|
|
71
|
+
}
|
package/src/cli/build.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import {
|
|
2
|
+
array,
|
|
3
|
+
assert,
|
|
4
|
+
choose,
|
|
5
|
+
is,
|
|
6
|
+
object,
|
|
7
|
+
optional,
|
|
8
|
+
record,
|
|
9
|
+
text,
|
|
10
|
+
} from '@fmtk/decoders';
|
|
11
|
+
import { Command } from 'commander';
|
|
12
|
+
import fs from 'fs';
|
|
13
|
+
import { dirname, resolve } from 'path';
|
|
14
|
+
import { rollupPackageDir } from '../core/rollup/rollupPackageDir.js';
|
|
15
|
+
import { zipDir } from '../core/zip/zipDir.js';
|
|
16
|
+
import { getPackagePath } from '../internal/getPackagePath.js';
|
|
17
|
+
|
|
18
|
+
interface RollupOptions {
|
|
19
|
+
type: 'rollup';
|
|
20
|
+
options: {
|
|
21
|
+
entrypoint: string;
|
|
22
|
+
ignore?: string[];
|
|
23
|
+
install?: string[];
|
|
24
|
+
packageArch?: string;
|
|
25
|
+
packageFilePath?: string;
|
|
26
|
+
packagePlatform?: string;
|
|
27
|
+
packageLockPath?: string;
|
|
28
|
+
rollupConfigPath?: string;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface ContentOptions {
|
|
33
|
+
type: 'content';
|
|
34
|
+
options: {
|
|
35
|
+
source: string;
|
|
36
|
+
ignore?: string[];
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const decodeOptions = choose(
|
|
41
|
+
object<RollupOptions>({
|
|
42
|
+
type: is('rollup'),
|
|
43
|
+
options: object<RollupOptions['options']>({
|
|
44
|
+
entrypoint: text,
|
|
45
|
+
ignore: optional(array(text)),
|
|
46
|
+
install: optional(array(text)),
|
|
47
|
+
packageArch: optional(text),
|
|
48
|
+
packageFilePath: optional(text),
|
|
49
|
+
packagePlatform: optional(text),
|
|
50
|
+
packageLockPath: optional(text),
|
|
51
|
+
rollupConfigPath: optional(text),
|
|
52
|
+
}),
|
|
53
|
+
}),
|
|
54
|
+
object<ContentOptions>({
|
|
55
|
+
type: is('content'),
|
|
56
|
+
options: object<ContentOptions['options']>({
|
|
57
|
+
source: text,
|
|
58
|
+
ignore: optional(array(text)),
|
|
59
|
+
}),
|
|
60
|
+
}),
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const decodeConfig = record(text, decodeOptions);
|
|
64
|
+
|
|
65
|
+
export function addBuildCommand(program: Command): void {
|
|
66
|
+
program
|
|
67
|
+
.command('build')
|
|
68
|
+
.description('create one or more packages based on a config file')
|
|
69
|
+
.requiredOption('-c, --config <name>', 'the config file')
|
|
70
|
+
.option('--only <name...>', 'only process the named asset(s)')
|
|
71
|
+
.option('-o, --output-dir <path>', 'the output directory')
|
|
72
|
+
.action(
|
|
73
|
+
async (options: {
|
|
74
|
+
config: string;
|
|
75
|
+
only?: string[];
|
|
76
|
+
outputDir?: string;
|
|
77
|
+
}): Promise<void> => {
|
|
78
|
+
const cfg = assert(
|
|
79
|
+
decodeConfig,
|
|
80
|
+
JSON.parse(fs.readFileSync(options.config, 'utf8')),
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
const source = dirname(resolve(options.config));
|
|
84
|
+
const filter = options.only && new Set(options.only);
|
|
85
|
+
|
|
86
|
+
for (const key in cfg) {
|
|
87
|
+
if (filter && !filter.has(key)) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const item = cfg[key];
|
|
91
|
+
console.log(`Processing asset ${key}`);
|
|
92
|
+
|
|
93
|
+
switch (item.type) {
|
|
94
|
+
case 'content':
|
|
95
|
+
await zipDir(item.options.source, {
|
|
96
|
+
bundleName: key,
|
|
97
|
+
packagePath: await getPackagePath(item.options.source),
|
|
98
|
+
outputPath: options.outputDir,
|
|
99
|
+
ignorePaths: item.options.ignore,
|
|
100
|
+
});
|
|
101
|
+
break;
|
|
102
|
+
|
|
103
|
+
case 'rollup':
|
|
104
|
+
await rollupPackageDir(source, {
|
|
105
|
+
bundleName: key,
|
|
106
|
+
entrypoint: item.options.entrypoint,
|
|
107
|
+
ignorePaths: item.options.ignore,
|
|
108
|
+
installPackages: item.options.install,
|
|
109
|
+
outputPath: options.outputDir,
|
|
110
|
+
packageArch: item.options.packageArch,
|
|
111
|
+
packageFilePath:
|
|
112
|
+
item.options.packageFilePath &&
|
|
113
|
+
resolve(source, item.options.packageFilePath),
|
|
114
|
+
packagePlatform: item.options.packagePlatform,
|
|
115
|
+
packageLockPath:
|
|
116
|
+
item.options.packageLockPath &&
|
|
117
|
+
resolve(source, item.options.packageLockPath),
|
|
118
|
+
rollupConfigPath:
|
|
119
|
+
item.options.rollupConfigPath &&
|
|
120
|
+
resolve(source, item.options.rollupConfigPath),
|
|
121
|
+
});
|
|
122
|
+
break;
|
|
123
|
+
|
|
124
|
+
default:
|
|
125
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
126
|
+
throw new Error(`unknown asset type ${(item as any).type}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
);
|
|
131
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { MergedRollupOptions } from 'rollup';
|
|
2
|
+
import { BatchWarnings } from 'rollup/loadConfigFile';
|
|
3
|
+
import { Readable } from 'stream';
|
|
4
|
+
import { getPackageEntries } from '../zip/getPackageEntries.js';
|
|
5
|
+
import { makeZipPackageStream } from '../zip/makeZipPackageStream.js';
|
|
6
|
+
import { ZipAssetEntry } from '../zip/ZipAssetEntry.js';
|
|
7
|
+
import { rollupPackageEntries } from './rollupPackageEntries.js';
|
|
8
|
+
|
|
9
|
+
export interface RollupPackageOptions {
|
|
10
|
+
ignore?: string[];
|
|
11
|
+
installPackages?: string[];
|
|
12
|
+
options: MergedRollupOptions[];
|
|
13
|
+
packageArch?: string;
|
|
14
|
+
packageFilePath?: string;
|
|
15
|
+
packagePlatform?: string;
|
|
16
|
+
packageLockPath?: string;
|
|
17
|
+
warnings: BatchWarnings;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export async function makeRollupPackageStream({
|
|
21
|
+
ignore,
|
|
22
|
+
installPackages,
|
|
23
|
+
options,
|
|
24
|
+
packageArch,
|
|
25
|
+
packageFilePath,
|
|
26
|
+
packagePlatform,
|
|
27
|
+
packageLockPath,
|
|
28
|
+
warnings,
|
|
29
|
+
}: RollupPackageOptions): Promise<Readable> {
|
|
30
|
+
const entries: ZipAssetEntry[] = [];
|
|
31
|
+
|
|
32
|
+
for await (const entry of rollupPackageEntries(options, warnings)) {
|
|
33
|
+
entries.push(entry);
|
|
34
|
+
}
|
|
35
|
+
if (installPackages?.length) {
|
|
36
|
+
if (!packageFilePath || !packageLockPath) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
`must specify package lock path and package.json path when installing packages`,
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
const packageFiles = getPackageEntries({
|
|
42
|
+
ignorePaths: ignore,
|
|
43
|
+
packageArch,
|
|
44
|
+
packageFilePath,
|
|
45
|
+
packagePlatform,
|
|
46
|
+
packageLockPath,
|
|
47
|
+
packageNames: installPackages,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
for await (const entry of packageFiles) {
|
|
51
|
+
entries.push(entry);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return makeZipPackageStream(entries);
|
|
55
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { createWriteStream } from 'fs';
|
|
2
|
+
import { mkdir } from 'fs/promises';
|
|
3
|
+
import { dirname, resolve } from 'path';
|
|
4
|
+
import { MergedRollupOptions } from 'rollup';
|
|
5
|
+
import loadConfigFile from 'rollup/loadConfigFile';
|
|
6
|
+
import { pipeline } from 'stream/promises';
|
|
7
|
+
import { addBundleInfoToPackageJson } from '../../internal/addBundleInfoToPackageJson.js';
|
|
8
|
+
import { readDotIgnoreForFolder } from '../../internal/readDotIgnoreForFolder.js';
|
|
9
|
+
import { makeRollupPackageStream } from './makeRollupPackageStream.js';
|
|
10
|
+
|
|
11
|
+
export interface RollupPackageDirOptions {
|
|
12
|
+
bundleName?: string;
|
|
13
|
+
entrypoint?: string;
|
|
14
|
+
ignorePaths?: string[];
|
|
15
|
+
installPackages?: string[];
|
|
16
|
+
outputPath?: string;
|
|
17
|
+
packageArch?: string;
|
|
18
|
+
packageFilePath?: string;
|
|
19
|
+
packagePlatform?: string;
|
|
20
|
+
packageLockPath?: string;
|
|
21
|
+
rollupConfigPath?: string;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export async function rollupPackageDir(
|
|
25
|
+
dirPath: string,
|
|
26
|
+
opts?: RollupPackageDirOptions,
|
|
27
|
+
): Promise<void> {
|
|
28
|
+
const outputPath =
|
|
29
|
+
opts?.outputPath || `dist/${opts?.bundleName || 'bundle'}.zip`;
|
|
30
|
+
const fullOutputPath = resolve(outputPath);
|
|
31
|
+
const installPackages = opts?.installPackages || [];
|
|
32
|
+
|
|
33
|
+
const ignorePaths = opts?.ignorePaths || [];
|
|
34
|
+
ignorePaths.push(...(await readDotIgnoreForFolder(dirPath)));
|
|
35
|
+
|
|
36
|
+
const rollupConfigPath = opts?.rollupConfigPath || 'rollup.config.js';
|
|
37
|
+
|
|
38
|
+
const { options, warnings } = await loadConfigFile(
|
|
39
|
+
resolve(dirPath, rollupConfigPath),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const output = await makeRollupPackageStream({
|
|
43
|
+
ignore: ignorePaths,
|
|
44
|
+
installPackages,
|
|
45
|
+
options: opts?.entrypoint
|
|
46
|
+
? options.map(
|
|
47
|
+
(x): MergedRollupOptions => ({ ...x, input: opts.entrypoint }),
|
|
48
|
+
)
|
|
49
|
+
: options,
|
|
50
|
+
packageArch: opts?.packageArch,
|
|
51
|
+
packageFilePath: opts?.packageFilePath,
|
|
52
|
+
packagePlatform: opts?.packagePlatform,
|
|
53
|
+
packageLockPath: opts?.packageLockPath,
|
|
54
|
+
warnings,
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
await mkdir(dirname(fullOutputPath), { recursive: true });
|
|
58
|
+
await pipeline(output, createWriteStream(fullOutputPath));
|
|
59
|
+
|
|
60
|
+
await addBundleInfoToPackageJson(dirPath, {
|
|
61
|
+
name: opts?.bundleName,
|
|
62
|
+
path: outputPath,
|
|
63
|
+
});
|
|
64
|
+
}
|