prepare-package 0.0.1

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) 2020 ITW Creative Works
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,82 @@
1
+ <p align="center">
2
+ <a href="https://cdn.itwcreativeworks.com/assets/itw-creative-works/images/logo/itw-creative-works-brandmark-black-x.svg">
3
+ <img src="https://cdn.itwcreativeworks.com/assets/itw-creative-works/images/logo/itw-creative-works-brandmark-black-x.svg" width="100px">
4
+ </a>
5
+ </p>
6
+
7
+ <p align="center">
8
+ <img src="https://img.shields.io/github/package-json/v/itw-creative-works/promo-server.svg">
9
+ <br>
10
+ <img src="https://img.shields.io/david/itw-creative-works/promo-server.svg">
11
+ <img src="https://img.shields.io/david/dev/itw-creative-works/promo-server.svg">
12
+ <img src="https://img.shields.io/bundlephobia/min/promo-server.svg">
13
+ <img src="https://img.shields.io/codeclimate/maintainability-percentage/itw-creative-works/promo-server.svg">
14
+ <img src="https://img.shields.io/npm/dm/promo-server.svg">
15
+ <img src="https://img.shields.io/node/v/promo-server.svg">
16
+ <img src="https://img.shields.io/website/https/itwcreativeworks.com.svg">
17
+ <img src="https://img.shields.io/github/license/itw-creative-works/promo-server.svg">
18
+ <img src="https://img.shields.io/github/contributors/itw-creative-works/promo-server.svg">
19
+ <img src="https://img.shields.io/github/last-commit/itw-creative-works/promo-server.svg">
20
+ <br>
21
+ <br>
22
+ <a href="https://itwcreativeworks.com">Site</a> | <a href="https://www.npmjs.com/package/promo-server">NPM Module</a> | <a href="https://github.com/itw-creative-works/promo-server">GitHub Repo</a>
23
+ <br>
24
+ <br>
25
+ <strong>Promo Server</strong> is an NPM module for backend and frontend developers that exposes promotion utilities for ITW Creative Works.
26
+ </p>
27
+
28
+ ## Install Promo Server
29
+ ### Install via npm
30
+ Install with npm if you plan to use **Promo Server** in a Node.js project or in the browser.
31
+ ```shell
32
+ npm install promo-server
33
+ ```
34
+ If you plan to use `promo-server` in a browser environment, you will probably need to use [Webpack](https://www.npmjs.com/package/webpack), [Browserify](https://www.npmjs.com/package/browserify), or a similar service to compile it.
35
+
36
+ ```js
37
+ const promoserver = new (require('promo-server'))();
38
+ ```
39
+
40
+ ### Install via CDN
41
+ Install with CDN if you plan to use **Promo Server** only in a browser environment.
42
+ ```html
43
+ <script src="https://cdn.jsdelivr.net/npm/promo-server@latest/dist/index.min.js"></script>
44
+ <script type="text/javascript">
45
+ var promoserver = new PromoServer(); // The script above exposes the global variable 'PromoServer'
46
+ </script>
47
+ ```
48
+
49
+ ## Features
50
+ * Useful **promo management** for ITW Creative Works
51
+
52
+ ## Example Setup
53
+ After installing via npm, simply `require` the library and begin enjoying the promo handler.
54
+ ```js
55
+ const promoserver = new (require('promo-server'))({
56
+ app: 'example', // <any string>
57
+ platform: 'web', // web | electron | extension
58
+ log: true, // true | false
59
+ firebase: firebase // reference to firebase (one will be implied if not provided)
60
+ });
61
+ ```
62
+ ## Usage
63
+ ### promoserver.handle(fn)
64
+
65
+ Set up a handler for new promo updates that will call `fn` when there is a promo update
66
+ ```js
67
+ promoserver.handle(function (payload) {
68
+ console.log('Payload', payload);
69
+ });
70
+ ```
71
+
72
+ ### promoserver.setUser(user)
73
+
74
+ Set the current user so things like `user.plan.id` can be considered for the handler
75
+ ```js
76
+ promoserver.setUser({});
77
+ ```
78
+
79
+ ## Final Words
80
+ If you are still having difficulty, we would love for you to post a question to [the Promo Server issues page](https://github.com/itw-creative-works/promo-server/issues). It is much easier to answer questions that include your code and relevant files! So if you can provide them, we'd be extremely grateful (and more likely to help you find the answer!)
81
+
82
+ Ask us to have your project listed! :)
package/dist/index.js ADDED
@@ -0,0 +1,52 @@
1
+ const jetpack = require('fs-jetpack');
2
+ const fetch = require('wonderful-fetch');
3
+ const path = require('path');
4
+ const chalk = require('chalk');
5
+ const thisPackageJSON = require('../package.json');
6
+ const theirPackageJSON = require(path.join(process.cwd(), 'package.json'));
7
+ const isLivePreparation = theirPackageJSON.name !== 'prepare-package';
8
+
9
+ // fix
10
+ theirPackageJSON.main = theirPackageJSON.main || './dist/index.js';
11
+ theirPackageJSON.preparePackage = theirPackageJSON.preparePackage || {};
12
+ theirPackageJSON.preparePackage.input = path.resolve(theirPackageJSON.preparePackage.input || './src');
13
+ theirPackageJSON.preparePackage.output = path.resolve(theirPackageJSON.preparePackage.output || './dist');
14
+ theirPackageJSON.preparePackage.replace = theirPackageJSON.preparePackage.replace || {};
15
+
16
+ console.log(chalk.blue(`[prepare-package]: Preparing...`));
17
+ console.log(chalk.blue(`[prepare-package]: ${theirPackageJSON.preparePackage.input}`));
18
+ console.log(chalk.blue(`[prepare-package]: ${theirPackageJSON.preparePackage.output}`));
19
+ console.log(chalk.blue(`[prepare-package]: ${theirPackageJSON.main}`));
20
+
21
+ jetpack.remove(
22
+ theirPackageJSON.preparePackage.output,
23
+ )
24
+
25
+ jetpack.copy(
26
+ theirPackageJSON.preparePackage.input,
27
+ theirPackageJSON.preparePackage.output,
28
+ )
29
+
30
+ // Only do this part on the actual package that is using THIS package because we dont't want to replace THIS {version}
31
+ if (isLivePreparation) {
32
+ function _replaceMain() {
33
+ let content = jetpack.read(theirPackageJSON.main)
34
+ // .replace(/{version}/igm, package.version)
35
+ .replace(/{version}/igm, package.version)
36
+ }
37
+ jetpack.write(
38
+ theirPackageJSON.main,
39
+ _replaceMain()
40
+ )
41
+ }
42
+
43
+ fetch(`https://purge.jsdelivr.net/npm/${theirPackageJSON.name}@latest`, {
44
+ json: true,
45
+ tries: 3,
46
+ })
47
+ .then(result => {
48
+ console.log(chalk.green(`[prepare-package]: Purged... name=${theirPackageJSON.name}`), result);
49
+ })
50
+ .catch(e => {
51
+ console.log(chalk.red(`[prepare-package]: Failed to purge... name=${theirPackageJSON.name}`, e));
52
+ })
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "prepare-package",
3
+ "version": "0.0.1",
4
+ "description": "Prepare a Node.js package before being published",
5
+ "main": "dist/index.js",
6
+ "scripts": {
7
+ "test": "./node_modules/mocha/bin/mocha test/ --recursive --timeout=10000",
8
+ "start": "node ./src/index.js"
9
+ },
10
+ "preparePackage": {
11
+ "input": "src",
12
+ "output": "dist",
13
+ "replace": {}
14
+ },
15
+ "engines": {
16
+ "node": ">=6.0.0"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/itw-creative-works/prepare-package.git"
21
+ },
22
+ "keywords": [
23
+ "management",
24
+ "backend",
25
+ "frontend",
26
+ "productivity"
27
+ ],
28
+ "author": "ITW Creative Works",
29
+ "license": "ISC",
30
+ "bugs": {
31
+ "url": "https://github.com/itw-creative-works/prepare-package/issues"
32
+ },
33
+ "homepage": "https://itwcreativeworks.com",
34
+ "dependencies": {
35
+ "chalk": "^4.1.2",
36
+ "fs-jetpack": "^4.3.1",
37
+ "wonderful-fetch": "^0.0.5"
38
+ },
39
+ "devDependencies": {
40
+ "fs-jetpack": "^4.3.1",
41
+ "mocha": "^8.0.1"
42
+ }
43
+ }
package/src/index.js ADDED
@@ -0,0 +1,53 @@
1
+ const jetpack = require('fs-jetpack');
2
+ const fetch = require('wonderful-fetch');
3
+ const path = require('path');
4
+ const chalk = require('chalk');
5
+ const thisPackageJSON = require('../package.json');
6
+ const theirPackageJSON = require(path.join(process.cwd(), 'package.json'));
7
+ const isLivePreparation = theirPackageJSON.name !== 'prepare-package';
8
+
9
+ // fix
10
+ theirPackageJSON.main = theirPackageJSON.main || './dist/index.js';
11
+ theirPackageJSON.preparePackage = theirPackageJSON.preparePackage || {};
12
+ theirPackageJSON.preparePackage.input = path.resolve(theirPackageJSON.preparePackage.input || './src');
13
+ theirPackageJSON.preparePackage.output = path.resolve(theirPackageJSON.preparePackage.output || './dist');
14
+ theirPackageJSON.preparePackage.replace = theirPackageJSON.preparePackage.replace || {};
15
+
16
+ console.log(chalk.blue(`[prepare-package]: Preparing...`));
17
+ console.log(chalk.blue(`[prepare-package]: ${theirPackageJSON.preparePackage.input}`));
18
+ console.log(chalk.blue(`[prepare-package]: ${theirPackageJSON.preparePackage.output}`));
19
+ console.log(chalk.blue(`[prepare-package]: ${theirPackageJSON.main}`));
20
+
21
+ jetpack.remove(
22
+ theirPackageJSON.preparePackage.output,
23
+ )
24
+
25
+ jetpack.copy(
26
+ theirPackageJSON.preparePackage.input,
27
+ theirPackageJSON.preparePackage.output,
28
+ )
29
+
30
+ // Only do this part on the actual package that is using THIS package because we dont't want to replace THIS {version}
31
+ if (isLivePreparation) {
32
+ function _replaceMain() {
33
+ let content = jetpack.read(theirPackageJSON.main)
34
+ // .replace(/{version}/igm, package.version)
35
+ .replace(/{version}/igm, package.version)
36
+ }
37
+ jetpack.write(
38
+ theirPackageJSON.main,
39
+ _replaceMain()
40
+ )
41
+ }
42
+
43
+ fetch(`https://purge.jsdelivr.net/npm/${theirPackageJSON.name}@latest`, {
44
+ json: true,
45
+ tries: 3,
46
+ })
47
+ .then(result => {
48
+ // console.log(chalk.green(`[prepare-package]: Purged... name=${theirPackageJSON.name}`), result);
49
+ console.log(chalk.green(`[prepare-package]: Purged... ${theirPackageJSON.name}`));
50
+ })
51
+ .catch(e => {
52
+ console.log(chalk.red(`[prepare-package]: Failed to purge... ${theirPackageJSON.name}`, e));
53
+ })