in app/exec/extension/_lib/manifest.ts [227:313]
protected addFile(file: FileDeclaration, defer: boolean = false) {
if (defer) {
this.deferredFiles.push(file);
return file;
}
if (!file.partName && file.packagePath) {
file.partName = file.packagePath;
}
if (_.isArray(file.partName)) {
let lastAdd = null;
for (let i = 0; i < file.partName.length; ++i) {
const newFile = { ...file };
newFile.partName = file.partName[i];
lastAdd = this.addFile(newFile);
}
return lastAdd;
}
if (typeof file.assetType === "string") {
file.assetType = [<string>file.assetType];
}
file.path = cleanAssetPath(file.path, this.extRoot);
if (!file.partName) {
file.partName = "/" + path.relative(this.extRoot, file.path);
}
if (!file.partName) {
throw new Error("Every file must have a path specified name.");
}
file.partName = forwardSlashesPath(file.partName);
// Default the assetType to the partName.
if (file.addressable && !file.assetType) {
file.assetType = [toZipItemName(file.partName)];
}
if (this.packageFiles[file.path]) {
if (_.isArray(this.packageFiles[file.path].assetType) && file.assetType) {
file.assetType = (<string[]>this.packageFiles[file.path].assetType).concat(<string[]>file.assetType);
this.packageFiles[file.path].assetType = file.assetType;
}
}
// Files added recursively, i.e. from a directory, get lower
// priority than those specified explicitly. Therefore, if
// the file has already been added to the package list, don't
// re-add (overwrite) with this file if it is an auto (from a dir)
if (file.auto && this.packageFiles[file.path] && this.packageFiles[file.path].partName === file.partName) {
// Don't add files discovered via directory if they've already
// been added.
} else {
let existPartName = this.lcPartNames[file.partName.toLowerCase()];
if (!existPartName || file.partName === existPartName) {
// key off a guid if there is no file path.
const key = file.path || common.newGuid();
if (this.packageFiles[key]) {
// Additional package paths is an UNSUPPORTED and UNDOCUMENTED feature.
// It may trample on other existing files with no warning or error.
// Use at your own risk.
const additionalPackagePaths = (this.packageFiles[key] as any)._additionalPackagePaths;
if (additionalPackagePaths) {
additionalPackagePaths.push(file.partName);
} else {
(this.packageFiles[key] as any)._additionalPackagePaths = [file.partName];
}
} else {
this.packageFiles[key] = file;
this.lcPartNames[file.partName.toLowerCase()] = file.partName;
}
} else {
throw new Error(
"All files in the package must have a case-insensitive unique filename. Trying to add " +
file.partName +
", but " +
existPartName +
" was already added to the package.",
);
}
}
if (file.contentType && this.packageFiles[file.path]) {
this.packageFiles[file.path].contentType = file.contentType;
}
return file;
}