@tryghost/mg-tinynews-members 0.0.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2013-2023 Ghost Foundation
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # Migrate Tiny News Members
2
+
3
+ Convert a Tiny News subscribers CSV to a CSV compatible with Ghost.
4
+
5
+
6
+ ## Install
7
+
8
+ To install the CLI, which is required for the Usage commands below:
9
+
10
+ ```sh
11
+ npm install --global @tryghost/migrate
12
+ ```
13
+
14
+ To use this package in your own project:
15
+
16
+ `npm install @tryghost/mg-tinynews-members --save`
17
+
18
+ or
19
+
20
+ `yarn add @tryghost/mg-tinynews-members`
21
+
22
+
23
+ ## Usage
24
+
25
+ To run a Tiny News members migration, the required command is:
26
+
27
+ ```sh
28
+ migrate tinynews-members --pathToFile /path/to/emails.csv
29
+ ```
30
+
31
+ It's possible to pass more options, in order to achieve a better migration file for Ghost:
32
+
33
+ - **`--pathToFile`** (required)
34
+ - Path to the subscribers CSV file as generated by Tiny News
35
+ - string - default: `null`
36
+ - **`-V` `--verbose`**
37
+ - Show verbose output
38
+ - bool - default: `false`
39
+
40
+
41
+ ## Develop
42
+
43
+ This is a mono repository, managed with [lerna](https://lerna.js.org).
44
+
45
+ Follow the instructions for the top-level repo.
46
+ 1. `git clone` this repo & `cd` into it as usual
47
+ 2. Run `yarn` to install top-level dependencies.
48
+
49
+
50
+ ### Run
51
+
52
+ To run a local development copy, `cd` into this directory, and use `yarn dev` instead of `migrate` like so:
53
+
54
+ ```sh
55
+ yarn dev tinynews-members --pathToFile /path/to/emails.csv
56
+ ```
57
+
58
+
59
+ ## Test
60
+
61
+ - `yarn lint` run just eslint
62
+ - `yarn test` run lint and tests
63
+
64
+
65
+ # Copyright & License
66
+
67
+ Copyright (c) 2013-2023 Ghost Foundation - Released under the [MIT license](LICENSE).
package/index.js ADDED
@@ -0,0 +1,9 @@
1
+ import parse from './lib/parse-members-csv.js';
2
+ import process from './lib/process.js';
3
+
4
+ export default async (ctx) => {
5
+ const parsed = await parse(ctx);
6
+ const normalized = await process(parsed, ctx);
7
+
8
+ return normalized;
9
+ };
@@ -0,0 +1,11 @@
1
+ import fsUtils from '@tryghost/mg-fs-utils';
2
+
3
+ const parseCSV = fsUtils.csv.parseCSV;
4
+
5
+ export default async (ctx) => {
6
+ const {options} = ctx;
7
+
8
+ let parsed = await parseCSV(options.pathToFile);
9
+
10
+ return parsed;
11
+ };
package/lib/process.js ADDED
@@ -0,0 +1,55 @@
1
+ const emailFields = ['Email', 'email'];
2
+ const firstNameFields = ['Name', 'First name'];
3
+ const lastNameFields = ['Surname', 'Last name'];
4
+ const createdAtFields = ['Created at', 'Date added'];
5
+ const statusFields = ['Status', 'status'];
6
+
7
+ const colMapper = (opts, obj) => {
8
+ let keys = Object.keys(obj);
9
+
10
+ let useThis;
11
+
12
+ opts.forEach((opt) => {
13
+ if (keys.includes(opt)) {
14
+ useThis = obj[opt];
15
+ }
16
+ });
17
+
18
+ return useThis;
19
+ };
20
+
21
+ const processMember = (tMember) => {
22
+ const email = colMapper(emailFields, tMember);
23
+ const firstName = colMapper(firstNameFields, tMember);
24
+ const lastName = colMapper(lastNameFields, tMember);
25
+ const createdAt = colMapper(createdAtFields, tMember);
26
+ const status = colMapper(statusFields, tMember);
27
+
28
+ let member = {
29
+ email: email,
30
+ name: [firstName, lastName].map(e => e.trim()).join(' ').trim(),
31
+ complimentary_plan: false,
32
+ created_at: new Date(createdAt).toISOString(), // Given values are UTC
33
+ labels: ['tinynews'],
34
+ subscribed_to_emails: false
35
+ };
36
+
37
+ if (tMember?.Tags) {
38
+ member.labels = member.labels.concat(tMember.Tags.replace(/\|/gm, ',').split(',').filter(e => e).map(e => e.trim()));
39
+ }
40
+
41
+ if (status === 'Subscribed' || status === '1' || status === 1 || status === '2' || status === 2) {
42
+ member.subscribed_to_emails = true;
43
+ }
44
+
45
+ return member;
46
+ };
47
+
48
+ export default async (input, ctx) => {
49
+ const {options} = ctx;
50
+ ctx.logs = [];
51
+
52
+ const processed = await input.map(member => processMember(member, options));
53
+
54
+ return processed;
55
+ };
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@tryghost/mg-tinynews-members",
3
+ "version": "0.0.2",
4
+ "repository": "https://github.com/TryGhost/migrate/tree/main/packages/mg-tinynews-members",
5
+ "author": "Ghost Foundation",
6
+ "license": "MIT",
7
+ "main": "index.js",
8
+ "type": "module",
9
+ "scripts": {
10
+ "dev": "echo \"Implement me!\"",
11
+ "test": "TZ=utc NODE_OPTIONS=--experimental-vm-modules jest",
12
+ "lint": "eslint . --ext .js --cache",
13
+ "posttest": "yarn lint"
14
+ },
15
+ "files": [
16
+ "index.js",
17
+ "lib"
18
+ ],
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "devDependencies": {
23
+ "eslint": "8.47.0",
24
+ "jest": "29.6.2",
25
+ "jest-extended": "3.2.4"
26
+ },
27
+ "dependencies": {
28
+ "@tryghost/mg-fs-utils": "0.12.13"
29
+ },
30
+ "gitHead": "0df990176ed00c9076d1bec7ddafa2a6b2ddd967"
31
+ }