Restructure Script

The restructure.js script cleans and standardizes the AWS icon ZIP contents by consolidating and merging assets from multiple origin folders into a single structured output directory. It filters by size, respects icon type, and harmonizes naming inconsistencies using category aliases.

What It Does

  • Parses raw-aws-icons for subdirectories like Architecture and Resource Icons.
  • Identifies matching categories using both slug and alias logic.
  • Merges compatible icons into unified folders with size and format filters.
  • Sorts unpaired Architecture-only folders separately and warns on mismatches.
  • Writes the cleaned output to aws-icons/, ready for downstream renaming.

Category Matching and Aliasing

AWS splits icon sets across Architecture and Resource ZIPs. These don't always use consistent naming. The script reconciles mismatches using "slug-based" comparisons and a manual alias map.

const manualAlias = {
  appintegration: "applicationintegration",
  iot: "internetofthings"
};
const autoAlias = {};
for (const k of archCats.keys()) {
  if (!resCats.has(k)) {
    const hit = [...resCats.keys()].find(x => x.includes(k));
    if (hit) autoAlias[k] = hit;
  }
}

This dual strategy ensures robustness even as AWS evolves its naming conventions.

Size and Format Filtering

Only SVG files of a specific resolution (default: 48) and format (default: svg) are selected. This avoids polluting the output with irrelevant or duplicate assets.

const matchesSize = (fp) => {
  const ext = path.extname(fp).slice(1).toLowerCase();
  if (!cfg.formats.includes(ext)) return false;
  const base = path.basename(fp).toLowerCase();
  return base.endsWith(`_${cfg.size}.${ext}`) || 
         fp.split(path.sep).includes(cfg.size);
};

Merging Strategy

After matching categories, the script moves files in parallel into the destination directory. Duplicates are skipped gracefully. General icons and dark variants are sorted into light/dark subfolders.

await ingest(archDir);
await ingest(resDir);
...
if (fsc.existsSync(dst)) {
  console.warn(`Warning: destination exists, skipping ${newName}`);
  return;
}

Output Directory Layout

After restructuring, your workspace will contain:

aws-icons/
├── Categories/
├── General-Icons-Light/
├── General-Icons-Dark/
├── Architecture-Group/
├── ApplicationIntegration/
├── Compute/
└── ...

The directory structure is clean, flattened, and free from AWS's original ZIP nesting or numeric suffixes.

Command-Line Options

This script accepts multiple flags for flexible control:

  • --source        Input directory (default: raw-aws-icons)
  • --dest             Output folder (default: aws-icons)
  • --size             Only include icons of this size (default: 48)
  • --formats       Include file types (comma-separated)
  • --dry-run         Simulate actions without writing to disk