Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,26 @@ To ensure smooth development, debugging, and code management, we recommend setti
- The ZIP file, e.g., `DEMO_INST-Auto1.zip`, is automatically created in the `dist/` directory after a successful build.


### Creating Packages for Central Institutions (NZ)

To create a customization package that supports both individual institutions (IZ) and central institutions (NZ), follow these steps:

1. For **Central Institution (NZ)** packages, add the following property to the `build-settings.env` file:
```
ADDON_NAME=CustomModuleCentral
```

2. Ensure the `INST_ID` and `VIEW_ID` are set appropriately for the central institution.

3. Run the build command as usual:
```bash
npm run build
```

**Note:** The development that makes a difference for NZ (central institutions) is only available in the July version and later.

This configuration allows the package to be deployed for central institutions while maintaining compatibility with individual institution customizations.

### Step 6: Upload Customization Package to Alma
1. In Alma, navigate to **Discovery > View List > Edit**.
2. Go to the **Manage Customization Package** tab.
Expand Down
121 changes: 110 additions & 11 deletions postbuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,90 @@ function removeDirectory(directory, callback) {
fs.rm(directory, { recursive: true, force: true }, callback);
}

function normalizeManifestPath(filePath, rootDirectory) {
const absoluteRootDirectory = path.resolve(rootDirectory || path.dirname(filePath));
const absoluteFilePath = path.resolve(filePath);
const relativePath = path.relative(absoluteRootDirectory, absoluteFilePath);
if (!relativePath || relativePath === '.' || relativePath.startsWith('..')) {
return '';
}

return relativePath.split(path.sep).join('/');
}

function collectAssetManifest(rootDirectory) {
if (!fs.existsSync(rootDirectory)) {
throw new Error(`Asset manifest generation failed: output directory does not exist: ${rootDirectory}`);
}

if (!fs.statSync(rootDirectory).isDirectory()) {
throw new Error(`Asset manifest generation failed: output path is not a directory: ${rootDirectory}`);
}

const files = [];
const directories = new Set();
const stack = [rootDirectory];

while (stack.length > 0) {
const currentDirectory = stack.pop();
const entries = fs.readdirSync(currentDirectory, { withFileTypes: true }).sort((a, b) => a.name.localeCompare(b.name));

for (const entry of entries) {
const fullPath = path.join(currentDirectory, entry.name);
const relativePath = normalizeManifestPath(fullPath, rootDirectory);

if (!relativePath) {
continue;
}

if (entry.isDirectory()) {
directories.add(relativePath);
stack.push(fullPath);
} else if (entry.isFile()) {
if (entry.name === 'asset-manifest.json') {
continue;
}
files.push(relativePath);
}
}
}

const parentDirectories = new Set();
for (const filePath of files) {
const parts = filePath.split('/').slice(0, -1);
let currentPath = '';

for (const part of parts) {
currentPath = currentPath ? `${currentPath}/${part}` : part;
parentDirectories.add(currentPath);
}
}

for (const parentDirectory of parentDirectories) {
directories.add(parentDirectory);
}

return {
files: files.sort((a, b) => a.localeCompare(b)),
directories: Array.from(directories).sort((a, b) => a.localeCompare(b)),
};
}

function writeAssetManifest(rootDirectory) {
if (!fs.existsSync(rootDirectory)) {
throw new Error(`Asset manifest generation failed: output directory does not exist: ${rootDirectory}`);
}

const manifest = collectAssetManifest(rootDirectory);
const manifestPath = path.join(rootDirectory, 'asset-manifest.json');
fs.writeFileSync(manifestPath, `${JSON.stringify(manifest, null, 2)}\n`, 'utf8');
console.log(`[AssetManifest] Created ${manifestPath} with ${manifest.files.length} files and ${manifest.directories.length} directories`);
return manifestPath;
}

function renameAndArchive() {
fs.rename(distPath, targetPath, (err) => {
if (err) throw err;
try {
fs.renameSync(distPath, targetPath);
console.log(`Renamed directory to ${targetPath}`);

const output = fs.createWriteStream(zipPath);
Expand All @@ -38,17 +119,35 @@ function renameAndArchive() {
});

archive.pipe(output);
archive.directory(targetPath, path.basename(targetPath)); // This ensures the directory itself is included
archive.directory(targetPath, path.basename(targetPath));
archive.finalize();
});
} catch (error) {
console.error(error.message);
process.exit(1);
}
}

// Check if target directory exists and remove it if it does
if (fs.existsSync(targetPath)) {
removeDirectory(targetPath, (err) => {
if (err) throw err;
function runPostbuild() {
if (fs.existsSync(targetPath)) {
removeDirectory(targetPath, (err) => {
if (err) {
console.error(err.message);
process.exit(1);
}
renameAndArchive();
});
} else {
renameAndArchive();
});
} else {
renameAndArchive();
}
}

if (require.main === module) {
runPostbuild();
}

module.exports = {
removeDirectory,
normalizeManifestPath,
collectAssetManifest,
writeAssetManifest,
};
Loading