Skip to content

Commit f7978d2

Browse files
committed
Merge branch 'dev' into feature/update-uikit-build-tools
2 parents 395ab87 + 2b70ff4 commit f7978d2

File tree

6 files changed

+38
-32
lines changed

6 files changed

+38
-32
lines changed

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"eslint-plugin-prettier": "2.6.0",
3131
"prettier": "1.11.1",
3232
"proxyquire": "2.0.1",
33-
"tap": "11.1.1"
33+
"tap": "11.1.5"
3434
},
3535
"files": [
3636
"bin"

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"pretty-quick": "1.2.2",
3131
"rewire": "2.5.2",
3232
"standard-version": "4.3.0",
33-
"tap": "11.1.1"
33+
"tap": "11.1.5"
3434
},
3535
"keywords": [
3636
"Pattern Lab",

packages/core/src/lib/annotation_exporter.js renamed to packages/core/src/lib/annotationExporter.js

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,49 @@ const _ = require('lodash');
66
const mp = require('./markdown_parser');
77
const logger = require('./log');
88

9-
const annotations_exporter = function(pl) {
9+
const annotationExporter = function(pl) {
1010
const paths = pl.config.paths;
11-
let oldAnnotations;
1211

1312
/**
1413
* Parses JS annotations.
1514
* @returns array of comments that used to be wrapped in raw JS
1615
*/
17-
function parseAnnotationsJS() {
16+
function parseAnnotationsJSON() {
17+
const jsonPath = path.resolve(paths.source.annotations, 'annotations.json');
18+
let annotations;
19+
1820
//attempt to read the file
1921
try {
20-
oldAnnotations = fs.readFileSync(
21-
path.resolve(paths.source.annotations, 'annotations.js'),
22-
'utf8'
23-
);
22+
if (fs.pathExistsSync(jsonPath)) {
23+
//read the new file
24+
annotations = fs.readFileSync(jsonPath, 'utf8');
25+
} else {
26+
//read the old file
27+
const jsPath = path.resolve(paths.source.annotations, 'annotations.js');
28+
29+
annotations = fs
30+
.readFileSync(jsPath, 'utf8')
31+
.replace(/^\s*var comments ?= ?/, '')
32+
.replace(/};\s*$/, '}');
33+
34+
logger.info(
35+
`Please convert ${jsPath} to JSON and rename it annotations.json.`
36+
);
37+
}
2438
} catch (ex) {
2539
logger.debug(
26-
`annotations.js file missing from ${
40+
`annotations.json file missing from ${
2741
paths.source.annotations
2842
}. This may be expected if you do not use annotations or are using markdown.`
2943
);
3044
return [];
3145
}
3246

33-
//parse as JSON by removing the old wrapping js syntax. comments and the trailing semi-colon
34-
oldAnnotations = oldAnnotations.replace('var comments = ', '');
35-
oldAnnotations = oldAnnotations.replace('};', '}');
36-
3747
try {
38-
const oldAnnotationsJSON = JSON.parse(oldAnnotations);
39-
return oldAnnotationsJSON.comments;
48+
const annotationsJSON = JSON.parse(annotations);
49+
return annotationsJSON.comments;
4050
} catch (ex) {
41-
logger.error(
42-
`There was an error parsing JSON for ${
43-
paths.source.annotations
44-
}annotations.js`
45-
);
51+
logger.error(`There was an error parsing JSON for ${jsonPath}`);
4652
return [];
4753
}
4854
}
@@ -108,7 +114,7 @@ const annotations_exporter = function(pl) {
108114
* @returns array of annotations
109115
*/
110116
function gatherAnnotations() {
111-
const annotationsJS = parseAnnotationsJS();
117+
const annotationsJS = parseAnnotationsJSON();
112118
const annotationsMD = parseAnnotationsMD();
113119
return _.unionBy(annotationsJS, annotationsMD, 'el');
114120
}
@@ -117,13 +123,13 @@ const annotations_exporter = function(pl) {
117123
gather: function() {
118124
return gatherAnnotations();
119125
},
120-
gatherJS: function() {
121-
return parseAnnotationsJS();
126+
gatherJSON: function() {
127+
return parseAnnotationsJSON();
122128
},
123129
gatherMD: function() {
124130
return parseAnnotationsMD();
125131
},
126132
};
127133
};
128134

129-
module.exports = annotations_exporter;
135+
module.exports = annotationExporter;

packages/core/src/lib/exportData.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const eol = require('os').EOL;
44
const path = require('path');
55
const _ = require('lodash');
66

7-
const ae = require('./annotation_exporter');
7+
const ae = require('./annotationExporter');
88

99
let fs = require('fs-extra'); //eslint-disable-line prefer-const
1010

@@ -13,7 +13,7 @@ let fs = require('fs-extra'); //eslint-disable-line prefer-const
1313
* @param patternlab - global data store
1414
*/
1515
module.exports = function(patternlab) {
16-
const annotation_exporter = new ae(patternlab);
16+
const annotationExporter = new ae(patternlab);
1717

1818
const paths = patternlab.config.paths;
1919

@@ -68,7 +68,7 @@ module.exports = function(patternlab) {
6868
eol;
6969

7070
//annotations
71-
const annotationsJSON = annotation_exporter.gather();
71+
const annotationsJSON = annotationExporter.gather();
7272
const annotations =
7373
'var comments = { "comments" : ' + JSON.stringify(annotationsJSON) + '};';
7474
_.each(patternlab.uikits, uikit => {

packages/core/test/annotation_exporter_tests.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ function createFakePatternLab(anPath, customProps) {
2020
}
2121

2222
var patternlab = createFakePatternLab(anPath);
23-
var ae = require('../src/lib/annotation_exporter')(patternlab);
23+
var ae = require('../src/lib/annotationExporter')(patternlab);
2424

2525
tap.test('converts old JS annotations into new format', function(test) {
2626
//arrange
2727
//act
28-
var annotations = ae.gatherJS();
28+
var annotations = ae.gatherJSON();
2929

3030
//assert
3131
test.equals(annotations.length, 2);
@@ -77,7 +77,7 @@ tap.test('merges both annotation methods into one array', function(test) {
7777
tap.test('when there are 0 annotation files', function(test) {
7878
var emptyAnPath = './test/files/empty/';
7979
var patternlab2 = createFakePatternLab(emptyAnPath);
80-
var ae2 = require('../src/lib/annotation_exporter')(patternlab2);
80+
var ae2 = require('../src/lib/annotationExporter')(patternlab2);
8181

8282
var annotations = ae2.gather();
8383
test.equals(annotations.length, 0);

packages/engine-mustache/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "lib/engine_mustache.js",
66
"dependencies": {
77
"fs-extra": "0.30.0",
8-
"mustache": "2.2.0"
8+
"mustache": "2.3.0"
99
},
1010
"keywords": [
1111
"Pattern Lab",

0 commit comments

Comments
 (0)