Skip to content

Instantly share code, notes, and snippets.

@chee
Created February 12, 2019 09:43
Show Gist options
  • Save chee/82f15207e93cfb1b1f9f676faa9f23a9 to your computer and use it in GitHub Desktop.
Save chee/82f15207e93cfb1b1f9f676faa9f23a9 to your computer and use it in GitHub Desktop.
convert bower manifest to npm manifest
[
"fticons",
"o-assets",
"o-autoinit",
"o-banner",
"o-brand",
"o-buttons",
"o-colors",
"o-cookie-message",
"o-date",
"o-dom",
"o-element-visibility",
"o-errors",
"o-expander",
"o-fetch-jsonp",
"o-fonts",
"o-footer",
"o-footer-services",
"o-forms",
"o-ft-affiliate-ribbon",
"o-grid",
"o-header",
"o-header-services",
"o-hierarchical-nav",
"o-hoverable",
"o-icons",
"o-labels",
"o-layers",
"o-layout",
"o-link-list",
"o-loading",
"o-message",
"o-normalise",
"o-overlay",
"o-quote",
"o-share",
"o-squishy-list",
"o-subs-card",
"o-syntax-highlight",
"o-table",
"o-tabs",
"o-teaser",
"o-teaser-collection",
"o-techdocs",
"o-toggle",
"o-tooltip",
"o-topper",
"o-typography",
"o-utils",
"o-video",
"o-viewport",
"o-visual-effects"
]
#!/usr/bin/env perl6
use JSON::Pretty;
my $components = from-json(slurp "components.json");
my $mappings = from-json(slurp "components.json");
sub add-npm-org (Str $name) {
return qq「@financial-times/{$name}」;
}
sub create-npm-dependency (Str $name, Str $version) {
my $is-origami-component = $components.contains($name);
if ($is-origami-component) {
return add-npm-org($name), $version;
}
my $name-is-mapped = $mappings<name>.keys.contains($name);
if ($name-is-mapped) {
return $mappings<name><<$name>>, $version;
}
my $version-is-mapped = $mappings<version>.keys.contains($version);
if ($version-is-mapped) {
return $name, $mappings<version><<$version>>;
}
my $hash-version-match = $version ~~ /'#'(\^?\d+\.\d+\.\d+)/;
if ($hash-version-match.so) {
return $name, @$hash-version-match[0].Str;
}
return $name, $version;
}
sub MAIN (Str $version where * ~~ /^\d+\.\d+\.\d+$/) {
my $bowerManifest = from-json(lines);
my $packageManifest = {};
$packageManifest<version> = $version;
$packageManifest<name> = add-npm-org($bowerManifest<name>);
$packageManifest<description> = $bowerManifest<description>;
$packageManifest<homepage> = $bowerManifest<homepage>;
$packageManifest<license> = $bowerManifest<license>;
$packageManifest<dependencies> = $bowerManifest<dependencies>.map({
my ($name, $version) = create-npm-dependency(.key, .value);
Pair.new: $name, $version;
}).Hash;
put to-json($packageManifest);
}
{
"name": {
"ftdomdelegate": "dom-delegate",
"prism": "prismjs",
"hogan": "hogan.js"
},
"version": {
"Financial-Times/highlight.js-shim": "^8.4.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment