Skip to content

Commit 002f170

Browse files
authored
breaking: update to latest @primer/octicons v16 (#714)
* breaking: update to latest @primer/octicons v16 * feat: setup validate-peer-dependencies to check peerDeps are well installed in application
1 parent 41a0593 commit 002f170

File tree

7 files changed

+736
-635
lines changed

7 files changed

+736
-635
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[![Ember Observer Score](https://emberobserver.com/badges/ember-octicons.svg)](https://emberobserver.com/addons/ember-octicons)
66

7-
Easily import [GitHub Octicons](https://octicons.github.com/) into an Ember application's build.
7+
Easily import [GitHub Primer/Octicons](https://primer.style/octicons/) into an Ember application's build.
88

99
## Usage
1010

@@ -24,15 +24,15 @@ To import Octicon SVGs as build time assets, add an `octicons` configuration obj
2424
// ember-cli-build.js
2525
let app = new EmberAddon(defaults, {
2626
octicons: {
27-
icons: ['alert', 'bell', 'j', /* etc... */]
27+
icons: ['alert', 'bell', 'mark-github', /* etc... */]
2828
}
2929
});
3030
```
3131

3232
Now the SVG file can be used like any other asset:
3333

3434
```hbs
35-
<img src="images/svg/octicons/mark-github.svg">
35+
<img src="images/svg/octicons/mark-github-16.svg" class="octicon" />
3636
```
3737

3838
By default, SVG files will be imported into the `images/svg/octicons` directory. To customize the import destination, set a `destDir` in the `octicons` config:
@@ -60,7 +60,7 @@ If you would rather use [ember-svg-jar](https://github.com/ivanvotti/ember-svg-j
6060
svgJar: {
6161
sourceDirs: [
6262
'public', // default SVGJar lookup directory
63-
'node_modules/octicons/build/svg'
63+
'node_modules/@primer/octicons/build/svg'
6464
]
6565
}
6666
});
@@ -69,7 +69,7 @@ If you would rather use [ember-svg-jar](https://github.com/ivanvotti/ember-svg-j
6969
And then use Ember SVGJar's `{{svg-jar}}` helper:
7070

7171
```hbs
72-
{{svg-jar "mark-github" class="octicon"}}
72+
{{svg-jar "mark-github-16" class="octicon"}}
7373
```
7474

7575
### CSS

blueprints/ember-octicons/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ module.exports = {
22
normalizeEntityName() {}, // no-op since we're just adding dependencies
33

44
afterInstall() {
5-
return this.addPackageToProject('octicons', '^8.0.0');
5+
return this.addPackageToProject('@primer/octicons', '^16.0.0');
66
},
77
};

ember-cli-build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = function (defaults) {
99
icons: ['mark-github'],
1010
},
1111
svgJar: {
12-
sourceDirs: ['node_modules/octicons/build/svg'],
12+
sourceDirs: ['node_modules/@primer/octicons/build/svg'],
1313
},
1414
});
1515

index.js

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,53 @@
11
'use strict';
22

3-
var Funnel = require('broccoli-funnel');
4-
var fs = require('fs');
5-
var glob = require('glob');
3+
const Funnel = require('broccoli-funnel');
4+
const fs = require('fs');
5+
const glob = require('glob');
6+
const validatePeerDependencies = require('validate-peer-dependencies');
67

7-
var octiconsDir = 'node_modules/octicons';
8+
const octiconsDir = 'node_modules/@primer/octicons';
89

910
module.exports = {
1011
name: require('./package').name,
11-
octiconsConfig: null,
12+
13+
init() {
14+
this._super.init.apply(this, arguments);
15+
16+
validatePeerDependencies(__dirname, {
17+
resolvePeerDependenciesFrom: this.parent.root,
18+
});
19+
},
1220

1321
included(app) {
1422
this._super.included(app);
1523

16-
this.octiconsConfig = this.buildConfig();
24+
let octiconsConfig = this.buildConfig();
1725

1826
// Import SVG icons
19-
if (this.octiconsConfig.icons !== null) {
20-
let destDir = this.octiconsConfig.destDir || 'images/svg/octicons';
21-
this.octiconsConfig.icons.forEach((icon) => {
22-
let iconPath = `node_modules/octicons/build/svg/${icon}.svg`;
23-
if (fs.existsSync(iconPath)) {
24-
app.import(`node_modules/octicons/build/svg/${icon}.svg`, {
27+
if (octiconsConfig.icons !== null) {
28+
let destDir = octiconsConfig.destDir || 'images/svg/octicons';
29+
octiconsConfig.icons.forEach((icon) => {
30+
let baseFile = `${octiconsDir}/build/svg/${icon}`;
31+
let notFound = true;
32+
if (fs.existsSync(`${baseFile}.svg`)) {
33+
app.import(`${baseFile}.svg`, {
34+
destDir,
35+
});
36+
notFound = false;
37+
}
38+
if (fs.existsSync(`${baseFile}-16.svg`)) {
39+
app.import(`${baseFile}-16.svg`, {
40+
destDir,
41+
});
42+
notFound = false;
43+
}
44+
if (fs.existsSync(`${baseFile}-24.svg`)) {
45+
app.import(`${baseFile}-24.svg`, {
2546
destDir,
2647
});
27-
} else {
48+
notFound = false;
49+
}
50+
if (notFound) {
2851
this.writeWarning(`Unknown icon: '${icon}' will not be imported`);
2952
}
3053
});
@@ -51,18 +74,21 @@ module.exports = {
5174

5275
buildConfig() {
5376
let config = (this.app && this.app.options) || {};
54-
let octiconsConfig = config['octicons'] || {
55-
destDir: null,
56-
icons: [],
57-
};
77+
let octiconsConfig = Object.assign(
78+
{
79+
destDir: null,
80+
icons: [],
81+
},
82+
config['octicons']
83+
);
5884

5985
if (octiconsConfig.icons !== null && octiconsConfig.icons.length === 0) {
6086
this.writeWarning(
6187
'No octicons were specified in ember-cli-build; defaulting to all icons'
6288
);
6389

6490
glob
65-
.sync('node_modules/octicons/build/svg/*.svg')
91+
.sync(`${octiconsDir}/build/svg/*.svg`)
6692
.map((i) => i.split('/').pop())
6793
.map((i) => i.replace(/\.svg$/i, ''))
6894
.reduce((a, v) => {

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ember-octicons",
33
"version": "3.0.0",
4-
"description": "Easily add GitHub Octicons to your Ember project.",
4+
"description": "Easily add GitHub Primer/Octicons to your Ember project.",
55
"keywords": [
66
"ember-addon",
77
"octicons",
@@ -29,20 +29,21 @@
2929
},
3030
"dependencies": {
3131
"broccoli-funnel": "^3.0.1",
32-
"broccoli-merge-trees": "^4.1.0",
3332
"ember-cli-babel": "^7.26.6",
3433
"ember-cli-htmlbars": "^5.7.1",
35-
"glob": "^7.1.2"
34+
"glob": "^7.1.2",
35+
"validate-peer-dependencies": "^2.0.0"
3636
},
3737
"peerDependencies": {
38-
"octicons": "^8.0.0"
38+
"@primer/octicons": "^16.0.0"
3939
},
4040
"devDependencies": {
4141
"@ember/optional-features": "^2.0.0",
4242
"@ember/test-helpers": "^2.2.5",
4343
"@embroider/test-setup": "^0.46.2",
4444
"@glimmer/component": "^1.0.4",
4545
"@glimmer/tracking": "^1.0.4",
46+
"@primer/octicons": "^16.0.0",
4647
"babel-eslint": "^10.1.0",
4748
"broccoli-asset-rev": "^3.0.0",
4849
"ember-auto-import": "^1.11.3",
@@ -62,7 +63,7 @@
6263
"ember-resolver": "^8.0.0",
6364
"ember-source": "~3.28.0",
6465
"ember-source-channel-url": "^3.0.0",
65-
"ember-svg-jar": "^2.1.0",
66+
"ember-svg-jar": "^2.3.3",
6667
"ember-template-lint": "^3.4.2",
6768
"ember-try": "^1.4.0",
6869
"eslint": "^7.27.0",
@@ -73,7 +74,6 @@
7374
"eslint-plugin-qunit": "^6.1.1",
7475
"loader.js": "^4.7.0",
7576
"npm-run-all": "^4.1.5",
76-
"octicons": "^8.4.2",
7777
"prettier": "^2.3.0",
7878
"qunit": "^2.15.0",
7979
"qunit-dom": "^2.0.0"

tests/dummy/app/templates/application.hbs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
<img
99
alt="GitHub"
10-
src="images/svg/octicons/mark-github.svg"
11-
style="width:160px; height:160px;"
12-
>
10+
src="images/svg/octicons/mark-github-16.svg"
11+
class="octicon"
12+
/>
1313

1414
<h2>SVG Jar Embed</h2>
1515

16-
{{svg-jar "mark-github" class="octicon" width="160" height="160"}}
16+
{{svg-jar "mark-github-16" class="octicon"}}

0 commit comments

Comments
 (0)