@tryghost/mg-json 0.8.6 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -18,7 +18,13 @@
18
18
  * }]
19
19
  * }
20
20
  */
21
- module.exports.toGhostJSON = require('./lib/to-ghost-json');
21
+ import toGhostJSON from './lib/to-ghost-json/index.js';
22
+ import hydrate from './lib/to-ghost-json/hydrate.js';
22
23
 
23
24
  // @TODO: validator
24
- // module.exports.validate = require('./lib/validator');
25
+ // import validate from './lib/validator.js';
26
+
27
+ export {
28
+ toGhostJSON,
29
+ hydrate
30
+ };
@@ -1,4 +1,5 @@
1
- const _ = require('lodash');
1
+ import _ from 'lodash';
2
+
2
3
  const baseJSON = `{
3
4
  "meta": {
4
5
  "exported_on": <%= timestamp %>,
@@ -9,7 +10,7 @@ const baseJSON = `{
9
10
  const baseTemplate = _.template(baseJSON);
10
11
  const defaultVersion = '2.0.0';
11
12
 
12
- module.exports = (version) => {
13
+ export default (version) => {
13
14
  return JSON.parse(baseTemplate({
14
15
  timestamp: Date.now(),
15
16
  version: version || defaultVersion
@@ -1,6 +1,6 @@
1
- const _ = require('lodash');
2
- const {slugify} = require('@tryghost/string');
3
- const Entities = require('html-entities');
1
+ import _ from 'lodash';
2
+ import {slugify} from '@tryghost/string';
3
+ import Entities from 'html-entities';
4
4
  /**
5
5
  * Hydrate Ghost objects
6
6
  * Extend object with the minimum data needed for an import to succeed
@@ -52,8 +52,7 @@ const hydrateUser = (input, options) => {
52
52
  return input;
53
53
  };
54
54
 
55
- // Alias plural form only, as this should already have been normalised
56
- module.exports.users = hydrateUser;
55
+ const users = hydrateUser;
57
56
 
58
57
  /**
59
58
  * Tags(s)
@@ -75,7 +74,7 @@ const hydrateTag = (input) => {
75
74
  return input;
76
75
  };
77
76
 
78
- module.exports.tags = hydrateTag;
77
+ const tags = hydrateTag;
79
78
 
80
79
  /**
81
80
  * Post(s)
@@ -103,4 +102,10 @@ const hydratePost = (input, options) => {
103
102
  return input;
104
103
  };
105
104
 
106
- module.exports.posts = hydratePost;
105
+ const posts = hydratePost;
106
+
107
+ export default {
108
+ users,
109
+ tags,
110
+ posts
111
+ };
@@ -1,10 +1,10 @@
1
- const baseTemplate = require('./base-template');
2
- const stripMeta = require('./meta-to-ghost');
3
- const processPostRelations = require('./process-post-relations');
4
- const validate = require('./validate');
5
- const reorderTags = require('./reorder-tags');
1
+ import baseTemplate from './base-template.js';
2
+ import stripMeta from './meta-to-ghost.js';
3
+ import processPostRelations from './process-post-relations.js';
4
+ import validate from './validate.js';
5
+ import reorderTags from './reorder-tags.js';
6
6
 
7
- module.exports = (input, options = {}) => {
7
+ export default (input, options = {}) => {
8
8
  // Construct a basic Ghost JSON template
9
9
  let output = baseTemplate();
10
10
 
@@ -1,7 +1,7 @@
1
- const _ = require('lodash');
2
- const schema = require('../utils/schema');
3
- const hydrate = require('./hydrate');
4
- const ObjectID = require('bson-objectid');
1
+ import _ from 'lodash';
2
+ import ObjectID from 'bson-objectid';
3
+ import schema from '../utils/schema.js';
4
+ import hydrate from './hydrate.js';
5
5
  /**
6
6
  * A resource might be a plain resource ready for import, or if it came from our migrate tooling,
7
7
  * probably an object with some metadata (like URL) and a `data` key with the resource fields
@@ -78,7 +78,7 @@ const normalizeValue = (value) => {
78
78
  * We expect an object with keys that match Ghost resources
79
79
  * Iterate over each key and return only ones that we recognise
80
80
  */
81
- module.exports = (input, options) => {
81
+ export default (input, options) => {
82
82
  return _.reduce(input, (data, inputValue, inputKey) => {
83
83
  let key = normalizeKey(inputKey);
84
84
  let entries = normalizeValue(inputValue);
@@ -1,8 +1,8 @@
1
- const _ = require('lodash');
2
- const schema = require('../utils/schema');
3
- const ObjectID = require('bson-objectid');
1
+ import _ from 'lodash';
2
+ import ObjectID from 'bson-objectid';
3
+ import schema from '../utils/schema.js';
4
4
 
5
- module.exports = (json) => {
5
+ export default (json) => {
6
6
  json.users = json.users || [];
7
7
  json.tags = json.tags || []; // expected to be empty
8
8
 
@@ -1,4 +1,4 @@
1
- module.exports = (json) => {
1
+ export default (json) => {
2
2
  json.posts.forEach((post) => {
3
3
  let tags = post.data.tags || [];
4
4
  let publicTags = [];
@@ -1,4 +1,4 @@
1
- module.exports = (json) => {
1
+ export default (json) => {
2
2
  json.posts.forEach((item, index) => {
3
3
  let input = item.data;
4
4
 
@@ -3,20 +3,26 @@
3
3
  // From Ghost core, along with a bunch of utility classes
4
4
 
5
5
  // @TODO extend this to all importable Ghost resources
6
- module.exports.RESOURCES = [
6
+ const RESOURCES = [
7
7
  'posts', 'posts_authors', 'posts_meta', 'posts_tags', 'tags', 'users'
8
8
  ];
9
9
 
10
- module.exports.RESOURCE_SINGULAR_TO_PLURAL = {
10
+ const RESOURCE_SINGULAR_TO_PLURAL = {
11
11
  user: 'users',
12
12
  author: 'authors',
13
13
  post: 'posts',
14
14
  tag: 'tags'
15
15
  };
16
16
 
17
- module.exports.AUTHOR_ALIASES = [
17
+ const AUTHOR_ALIASES = [
18
18
  'author',
19
19
  'authors',
20
20
  'primary_author',
21
21
  'author_id'
22
22
  ];
23
+
24
+ export default {
25
+ RESOURCES,
26
+ RESOURCE_SINGULAR_TO_PLURAL,
27
+ AUTHOR_ALIASES
28
+ };
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "@tryghost/mg-json",
3
- "version": "0.8.6",
3
+ "version": "0.9.0",
4
4
  "repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-json",
5
5
  "author": "Ghost Foundation",
6
6
  "license": "MIT",
7
7
  "main": "index.js",
8
+ "type": "module",
8
9
  "scripts": {
9
10
  "dev": "echo \"Implement me!\"",
10
- "test": "NODE_ENV=testing mocha ./test/**/*.test.js",
11
+ "test": "node --experimental-vm-modules $(yarn bin jest)",
11
12
  "lint": "eslint . --ext .js --cache",
12
13
  "posttest": "yarn lint"
13
14
  },
@@ -19,15 +20,15 @@
19
20
  "access": "public"
20
21
  },
21
22
  "devDependencies": {
22
- "mocha": "10.0.0",
23
- "should": "13.2.3",
24
- "sinon": "14.0.0"
23
+ "eslint": "8.25.0",
24
+ "jest": "29.1.2",
25
+ "jest-extended": "3.1.0"
25
26
  },
26
27
  "dependencies": {
27
- "@tryghost/string": "0.1.26",
28
+ "@tryghost/string": "0.2.1",
28
29
  "bson-objectid": "2.0.3",
29
30
  "html-entities": "2.3.3",
30
31
  "lodash": "4.17.21"
31
32
  },
32
- "gitHead": "68aae057039319cd550afe37426c0db4145bd29e"
33
+ "gitHead": "35cb5c1ca6a826e1e596c4f2e209ab690fa06fa0"
33
34
  }