cannibalizr 1.0.2 → 2.0.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/dist/index.cjs ADDED
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.cannibalizr = cannibalizr;
7
+ exports.default = void 0;
8
+ var _nodeFs = _interopRequireDefault(require("node:fs"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ /***
11
+ * Copyright (c) 2016 - 2022 Alex Grant (@localnerve), LocalNerve LLC
12
+ * Copyrights licensed under the MIT License. See the accompanying LICENSE file
13
+ * for terms.
14
+ */
15
+ var _default = cannibalizr;
16
+ /**
17
+ * Pull strings from multiple input files, write to structured json.
18
+ *
19
+ * json output file structure:
20
+ * {
21
+ * manifest: {
22
+ * // any output manifest data supplied in options
23
+ * },
24
+ * anyname: [
25
+ * 'some captured string',
26
+ * 'another captured string'
27
+ * ]
28
+ * }
29
+ *
30
+ * @param {Object} options - Cannibalizr options.
31
+ * @param {Object} options.input - input options.
32
+ * @param {Object} options.input.anyname - At least one input is required,
33
+ * use a name that makes sense for what is being captured.
34
+ * @param {String} options.input.anyname.file - The path of the input file.
35
+ * @param {Array} options.input.anyname.captures - The captures to run against
36
+ * the input file.
37
+ * @param {Boolean} options.input.anyname.captures.n.global - true if the regex
38
+ * is global, false otherwise.
39
+ * @param {Number} options.input.anyname.captures.n.matchIndex - The match index
40
+ * to use to capture data for the regex.
41
+ * @param {Regex} options.input.anyname.captures.n.re - The capturing regex to
42
+ * use to get data.
43
+ * @param {Object} options.output - output options.
44
+ * @param {String} options.output.file - The path of the json output file.
45
+ * @param {Object} [options.output.manifest] - An arbitrary manifest to write
46
+ * to the json output file.
47
+ * @param {Function} [options.logger] - A logger to use.
48
+ * @returns {Undefined} Nothing.
49
+ */
50
+ exports.default = _default;
51
+ function cannibalizr(options) {
52
+ const output = {};
53
+
54
+ // used to trim "|' from the beginning and end of a captured result.
55
+ const reClean = /^(?:\s+|"|')|(?:\s+|"|')$/g;
56
+
57
+ // basic input check
58
+ const inputOk = options.input && Object.keys(options.input).length && options.output && options.output.file;
59
+ if (!inputOk) {
60
+ throw new Error('Cannibalizr received invalid options. Please review readme');
61
+ }
62
+ if (options.output.manifest) {
63
+ output.manifest = options.output.manifest;
64
+ }
65
+
66
+ /**
67
+ * Report output results
68
+ *
69
+ * @param {Object} items - An array of output values.
70
+ * @param {String} name - The name assocaited with the output.
71
+ * @returns {Undefined} Nothing.
72
+ */
73
+ const report = function (items, name) {
74
+ if (options.logger) {
75
+ if (items && items.length) {
76
+ items.forEach(str => {
77
+ options.logger(`"${name}": ${str}`);
78
+ });
79
+ } else {
80
+ options.logger(`nothing found for "${name}"`);
81
+ }
82
+ }
83
+ };
84
+ Object.keys(options.input).forEach(item => {
85
+ options.input[item].forEach(input => {
86
+ const contents = _nodeFs.default.readFileSync(input.file, {
87
+ encoding: 'utf8'
88
+ });
89
+ input.captures.forEach(capSpec => {
90
+ let m;
91
+ output[item] || (output[item] = []);
92
+ if (capSpec.global) {
93
+ while ((m = capSpec.re.exec(contents)) !== null) {
94
+ output[item].push(m[capSpec.matchIndex].replace(reClean, ''));
95
+ }
96
+ } else {
97
+ m = capSpec.re.exec(contents);
98
+ if (m) {
99
+ output[item].push(m[capSpec.matchIndex].replace(reClean, ''));
100
+ }
101
+ }
102
+ });
103
+ });
104
+ report(output[item], item);
105
+ });
106
+ _nodeFs.default.writeFileSync(options.output.file, JSON.stringify(output));
107
+ }
@@ -3,8 +3,8 @@
3
3
  * Copyrights licensed under the MIT License. See the accompanying LICENSE file
4
4
  * for terms.
5
5
  */
6
- const fs = require('fs');
7
-
6
+ import fs from 'node:fs';
7
+ export default cannibalizr;
8
8
  /**
9
9
  * Pull strings from multiple input files, write to structured json.
10
10
  *
@@ -39,7 +39,7 @@ const fs = require('fs');
39
39
  * @param {Function} [options.logger] - A logger to use.
40
40
  * @returns {Undefined} Nothing.
41
41
  */
42
- module.exports = function cannibalizr (options) {
42
+ export function cannibalizr (options) {
43
43
  const output = {};
44
44
 
45
45
  // used to trim "|' from the beginning and end of a captured result.
@@ -105,4 +105,4 @@ module.exports = function cannibalizr (options) {
105
105
  fs.writeFileSync(options.output.file, JSON.stringify(
106
106
  output
107
107
  ));
108
- };
108
+ }
package/package.json CHANGED
@@ -1,9 +1,16 @@
1
1
  {
2
2
  "name": "cannibalizr",
3
- "version": "1.0.2",
3
+ "version": "2.0.0",
4
4
  "description": "Turns an old pile of rusty files into a new json data source",
5
- "main": "index.js",
5
+ "main": "dist/index.js",
6
+ "type": "module",
7
+ "exports": {
8
+ "import": "./dist/index.js",
9
+ "require": "./dist/index.cjs",
10
+ "default": "./dist/index.js"
11
+ },
6
12
  "scripts": {
13
+ "prepublishOnly": "rimraf ./dist && babel ./lib/index.js -o ./dist/index.cjs && node -e 'require(\"fs\").copyFileSync(\"./lib/index.js\", \"./dist/index.js\");'",
7
14
  "test": "mocha ./tests/unit --recursive --reporter spec",
8
15
  "cover": "c8 -- npm test",
9
16
  "lint": "eslint .",
@@ -31,18 +38,17 @@
31
38
  "engines": {
32
39
  "node": ">= 14"
33
40
  },
34
- "dependencies": {},
35
41
  "devDependencies": {
36
- "@babel/core": "^7.17.8",
37
- "@babel/preset-env": "^7.16.11",
38
- "@babel/eslint-parser": "^7.17.0",
39
- "c8": "^7.11.2",
40
- "chai": "^4.3.6",
41
- "coveralls": "^3.1.1",
42
- "eslint": "^8.12.0",
43
- "mkdirp": "^1.0.4",
44
- "mocha": "^9.2.2",
45
- "precommit-hook": "^3.0.0"
42
+ "@babel/cli": "^7.19.3",
43
+ "@babel/core": "^7.20.2",
44
+ "@babel/eslint-parser": "^7.19.1",
45
+ "@babel/preset-env": "^7.20.2",
46
+ "c8": "^7.12.0",
47
+ "chai": "^4.3.7",
48
+ "eslint": "^8.28.0",
49
+ "mocha": "^10.1.0",
50
+ "precommit-hook": "^3.0.0",
51
+ "rimraf": "^3.0.2"
46
52
  },
47
53
  "pre-commit": [
48
54
  "lint",
package/.c8rc.json DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "reporter": ["lcov", "json"],
3
- "reports-dir": "reports/coverage",
4
- "exclude": ["tmp", "reports", "node_modules", "tests", ".github"]
5
- }
package/.eslintignore DELETED
@@ -1,4 +0,0 @@
1
- /reports
2
- /node_modules
3
- /tmp
4
- /package
package/.eslintrc.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "env": {
3
- "node": true
4
- },
5
- "parser": "@babel/eslint-parser",
6
- "extends": "eslint:recommended",
7
- "rules": {
8
- "indent": [2, 2, {"SwitchCase": 1}],
9
- "quotes": [2, "single"],
10
- "dot-notation": [2, {"allowKeywords": true}]
11
- }
12
- }
@@ -1,32 +0,0 @@
1
- name: Verify
2
- on:
3
- push:
4
- branches: [ master ]
5
- pull_request:
6
- branches: [ master ]
7
-
8
- jobs:
9
- verify:
10
-
11
- runs-on: ubuntu-latest
12
-
13
- strategy:
14
- matrix:
15
- node-version: [14.x, 16.x]
16
- # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
17
-
18
- steps:
19
- - uses: actions/checkout@v3
20
- - name: Use Node.js ${{ matrix.node-version }}
21
- uses: actions/setup-node@v3.0.0
22
- with:
23
- node-version: ${{ matrix.node-version }}
24
- - run: npm ci
25
- - name: Lint, Test, And Coverage
26
- run: npm run lint && npm run cover
27
- - name: Coverage Upload
28
- if: ${{ success() }}
29
- uses: coverallsapp/github-action@master
30
- with:
31
- github-token: ${{ secrets.GITHUB_TOKEN }}
32
- path-to-lcov: ./reports/coverage/lcov.info
package/babel.config.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "presets": [
3
- [
4
- "@babel/preset-env",
5
- {
6
- "targets": {
7
- "node": "14"
8
- }
9
- }
10
- ]
11
- ]
12
- }
@@ -1,21 +0,0 @@
1
- //
2
- // Copyright (c) 2016 - 2022 Alex Grant (@localnerve), LocalNerve LLC
3
- // Copyrights licensed under the BSD License. See the accompanying LICENSE file for terms.
4
- //
5
- // font styles
6
- // -------------------------
7
-
8
- @font-face {
9
- font-family: "Source Sans Pro";
10
- src: local("Source Sans Pro"), local("SourceSansPro-Regular"),
11
- url("//fonts.gstatic.com/s/sourcesanspro/v9/ODelI1aHBYDBqgeIAH2zlNV_2ngZ8dMf8fLgjYEouxg.woff2") format("woff2"),
12
- url("//fonts.gstatic.com/s/sourcesanspro/v9/ODelI1aHBYDBqgeIAH2zlBM0YzuT7MdOe03otPbuUS0.woff") format("woff"),
13
- url("//fonts.gstatic.com/s/sourcesanspro/v9/ODelI1aHBYDBqgeIAH2zlEY6Fu39Tt9XkmtSosaMoEA.ttf") format("truetype");
14
- /* unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215, U+E0FF, U+EFFD, U+F000; */
15
- font-weight: 400;
16
- font-style: normal;
17
- }
18
-
19
- .fonts-loaded body {
20
- font-family: "Source Sans Pro", sans-serif;
21
- }
@@ -1,35 +0,0 @@
1
- /***
2
- * Copyright (c) 2016 - 2022 Alex Grant (@localnerve), LocalNerve LLC
3
- * Copyrights licensed under the BSD License. See the accompanying LICENSE file for terms.
4
- *
5
- * Assemble the Fluxible app.
6
- */
7
- 'use strict';
8
-
9
- var debug = require('debug')('Example:App');
10
- var FluxibleApp = require('fluxible');
11
- var fetchrPlugin = require('fluxible-plugin-fetchr');
12
- var ApplicationStore = require('./stores/ApplicationStore');
13
- var ContentStore = require('./stores/ContentStore');
14
- var ContactStore = require('./stores/ContactStore');
15
- var BackgroundStore = require('./stores/BackgroundStore');
16
- var RouteStore = require('./stores/RouteStore');
17
- var ModalStore = require('./stores/ModalStore');
18
-
19
- debug('Creating FluxibleApp');
20
- var app = new FluxibleApp({
21
- component: require('./components/Application.jsx')
22
- });
23
-
24
- debug('Adding Plugins');
25
- app.plug(fetchrPlugin({ xhrPath: '/_api' }));
26
-
27
- debug('Registering Stores');
28
- app.registerStore(ApplicationStore);
29
- app.registerStore(ContentStore);
30
- app.registerStore(ContactStore);
31
- app.registerStore(BackgroundStore);
32
- app.registerStore(RouteStore);
33
- app.registerStore(ModalStore);
34
-
35
- module.exports = app;
@@ -1,37 +0,0 @@
1
- /**
2
- * Copyright (c) 2016 - 2022 Alex Grant (@localnerve), LocalNerve LLC
3
- * Copyrights licensed under the MIT License. See the accompanying LICENSE file
4
- * for terms.
5
- */
6
- /*eslint no-console:0 */
7
- const path = require('path');
8
-
9
- module.exports = {
10
- output: {
11
- manifest: {
12
- id: 123,
13
- version: '0.1.0',
14
- whatever: 'string I want'
15
- },
16
- file: path.join(__dirname, './tmp/test_out.json')
17
- },
18
- input: {
19
- assets: [{
20
- file: path.join(__dirname, './files/_fonts.scss'),
21
- captures: [{
22
- global: true,
23
- matchIndex: 1,
24
- re: /url\(([^)]+)\)/ig
25
- }]
26
- }],
27
- apis: [{
28
- file: path.join(__dirname, './files/app.js'),
29
- captures: [{
30
- global: false,
31
- matchIndex: 1,
32
- re: /xhrPath\s*:\s*(?:'|")([^'"]+)/
33
- }]
34
- }]
35
- },
36
- logger: console.log
37
- }
@@ -1,15 +0,0 @@
1
- {
2
- "manifest": {
3
- "id": 123,
4
- "version": "0.1.0",
5
- "whatever": "string I want"
6
- },
7
- "assets": [
8
- "//fonts.gstatic.com/s/sourcesanspro/v9/ODelI1aHBYDBqgeIAH2zlNV_2ngZ8dMf8fLgjYEouxg.woff2",
9
- "//fonts.gstatic.com/s/sourcesanspro/v9/ODelI1aHBYDBqgeIAH2zlBM0YzuT7MdOe03otPbuUS0.woff",
10
- "//fonts.gstatic.com/s/sourcesanspro/v9/ODelI1aHBYDBqgeIAH2zlEY6Fu39Tt9XkmtSosaMoEA.ttf"
11
- ],
12
- "apis": [
13
- "/_api"
14
- ]
15
- }
@@ -1,50 +0,0 @@
1
- /***
2
- * Copyright (c) 2016 - 2022 Alex Grant (@localnerve), LocalNerve LLC
3
- * Copyrights licensed under the MIT License. See the accompanying LICENSE file
4
- * for terms.
5
- */
6
- /* global before, beforeEach, describe, it */
7
-
8
- const fs = require('fs');
9
- const path = require('path');
10
- const expect = require('chai').expect;
11
- const mkdirp = require('mkdirp').sync;
12
-
13
- describe('cannibalizr', () => {
14
- const inputFixture = require('../fixtures/options');
15
- const outputFixture = require('../fixtures/output.json');
16
- const cannibalizr = require('../../index.js');
17
-
18
- before('cannibalizr', () => {
19
- const outputDir = path.dirname(inputFixture.output.file);
20
- mkdirp(outputDir);
21
- });
22
-
23
- beforeEach(() => {
24
- if (fs.existsSync(inputFixture.output.file)) {
25
- fs.unlinkSync(inputFixture.output.file);
26
- }
27
- });
28
-
29
- it('should produce the expected output', (done) => {
30
- cannibalizr(inputFixture);
31
-
32
- fs.readFile(inputFixture.output.file, {
33
- encoding: 'utf8'
34
- }, (err, data) => {
35
- expect(data).to.eql(JSON.stringify(outputFixture));
36
- done(err);
37
- });
38
- });
39
-
40
- it('should not run if bad input', () => {
41
- const badOptions = JSON.parse(JSON.stringify(inputFixture));
42
- delete badOptions.output.file;
43
-
44
- expect(function () {
45
- cannibalizr(badOptions);
46
- }).to.throw(Error);
47
-
48
- expect(fs.existsSync(inputFixture.output.file)).to.be.false;
49
- });
50
- });