prepare-package 1.1.8 → 1.1.9
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/README.md +7 -7
- package/dist/index.js +6 -4
- package/package.json +5 -5
- package/src/index.js +0 -111
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<a href="https://
|
|
2
|
+
<a href="https://itwcreativeworks.com">
|
|
3
3
|
<img src="https://cdn.itwcreativeworks.com/assets/itw-creative-works/images/logo/itw-creative-works-brandmark-black-x.svg" width="100px">
|
|
4
4
|
</a>
|
|
5
5
|
</p>
|
|
@@ -24,19 +24,19 @@
|
|
|
24
24
|
<strong>Prepare Package</strong> is a helpful NPM module that prepares your package before distribution.
|
|
25
25
|
</p>
|
|
26
26
|
|
|
27
|
-
## Install Prepare Package
|
|
28
|
-
### Install via npm
|
|
27
|
+
## 📦 Install Prepare Package
|
|
28
|
+
### Option 1: Install via npm
|
|
29
29
|
Install with npm if you plan to use **Prepare Package** in a Node.js project.
|
|
30
30
|
```shell
|
|
31
31
|
npm install prepare-package --save-dev
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
## Features
|
|
34
|
+
## 🦄 Features
|
|
35
35
|
* Copy files from `src` to `dist`
|
|
36
36
|
* Replace tags in your main file, `index.js`
|
|
37
37
|
* `{version}` => `package.version`
|
|
38
38
|
|
|
39
|
-
## Example Setup
|
|
39
|
+
## 📘 Example Setup
|
|
40
40
|
After installing via npm, simply put this in your `package.json`
|
|
41
41
|
```json
|
|
42
42
|
...
|
|
@@ -57,7 +57,7 @@ After installing via npm, simply put this in your `package.json`
|
|
|
57
57
|
* `preparePackage.out`: The dir to copy **to**.
|
|
58
58
|
* `main`: The file to copy and use as your main file. Tags like `{version}` are replaced in this file.
|
|
59
59
|
|
|
60
|
-
## Usage
|
|
60
|
+
## ⚡️ Usage
|
|
61
61
|
### Run Prepare Package
|
|
62
62
|
```shell
|
|
63
63
|
# Run once
|
|
@@ -67,5 +67,5 @@ npm run prepare
|
|
|
67
67
|
npm run prepare:watch
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
## Final Words
|
|
70
|
+
## 🗨️ Final Words
|
|
71
71
|
If you are still having difficulty, we would love for you to post a question to [the Prepare Package issues page](https://github.com/itw-creative-works/prepare-package/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!)
|
package/dist/index.js
CHANGED
|
@@ -34,10 +34,12 @@ module.exports = async function (options) {
|
|
|
34
34
|
|
|
35
35
|
// Add script
|
|
36
36
|
theirPackageJSON.scripts = theirPackageJSON.scripts || {};
|
|
37
|
-
theirPackageJSON.scripts.prepare = theirPackageJSON.scripts.prepare
|
|
38
|
-
|
|
39
|
-
theirPackageJSON.scripts['prepare:watch'] = theirPackageJSON.scripts['prepare:watch']
|
|
40
|
-
|
|
37
|
+
// theirPackageJSON.scripts.prepare = theirPackageJSON.scripts.prepare
|
|
38
|
+
// || 'node -e \'require(`prepare-package`)()\'';
|
|
39
|
+
// theirPackageJSON.scripts['prepare:watch'] = theirPackageJSON.scripts['prepare:watch']
|
|
40
|
+
// || `nodemon -w ./src -e '*' --exec 'npm run prepare'`
|
|
41
|
+
theirPackageJSON.scripts.prepare = `node -e \\"require('prepare-package')()\\"`;
|
|
42
|
+
theirPackageJSON.scripts['prepare:watch'] = `nodemon -w ./src -e '*' --exec 'npm run prepare'`
|
|
41
43
|
|
|
42
44
|
// Log the options
|
|
43
45
|
console.log(chalk.blue(`[prepare-package]: Options purge=${options.purge}`));
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prepare-package",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.9",
|
|
4
4
|
"description": "Prepare a Node.js package before being published",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "./node_modules/mocha/bin/mocha test/ --recursive --timeout=10000",
|
|
8
|
-
"start": "node -e
|
|
9
|
-
"prepare": "node -e
|
|
8
|
+
"start": "node -e \"require('./src/index.js')()\"",
|
|
9
|
+
"prepare": "node -e \"require('./src/index.js')()\"",
|
|
10
10
|
"prepare:watch": "nodemon -w ./src -e '*' --exec 'npm run prepare'",
|
|
11
|
-
"postinstall": "node -e
|
|
11
|
+
"postinstall": "node -e \"require('./dist/index.js')({cwd: process.env.INIT_CWD, isPostInstall: true})\""
|
|
12
12
|
},
|
|
13
13
|
"preparePackage": {
|
|
14
14
|
"input": "src",
|
|
@@ -42,4 +42,4 @@
|
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"mocha": "^8.4.0"
|
|
44
44
|
}
|
|
45
|
-
}
|
|
45
|
+
}
|
package/src/index.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
const jetpack = require('fs-jetpack');
|
|
2
|
-
const fetch = require('wonderful-fetch');
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const chalk = require('chalk');
|
|
5
|
-
|
|
6
|
-
// const argv = require('yargs').argv;
|
|
7
|
-
|
|
8
|
-
module.exports = async function (options) {
|
|
9
|
-
// Set the options
|
|
10
|
-
options = options || {};
|
|
11
|
-
options.purge = typeof options.purge === 'undefined' ? true : options.purge;
|
|
12
|
-
options.cwd = options.cwd || process.cwd();
|
|
13
|
-
options.isPostInstall = typeof options.isPostInstall === 'undefined' ? false : options.isPostInstall;
|
|
14
|
-
|
|
15
|
-
// Set the paths
|
|
16
|
-
const theirPackageJSONPath = path.resolve(options.cwd, 'package.json');
|
|
17
|
-
const theirPackageJSONExists = jetpack.exists(theirPackageJSONPath);
|
|
18
|
-
|
|
19
|
-
// Get the package.json files
|
|
20
|
-
const thisPackageJSON = require('../package.json');
|
|
21
|
-
const theirPackageJSON = theirPackageJSONExists ? require(theirPackageJSONPath) : {};
|
|
22
|
-
const isLivePreparation = theirPackageJSON.name !== 'prepare-package';
|
|
23
|
-
|
|
24
|
-
// const options = {
|
|
25
|
-
// purge: argv['--purge'] || argv['-p'],
|
|
26
|
-
// };
|
|
27
|
-
|
|
28
|
-
// Fix their package.json
|
|
29
|
-
theirPackageJSON.main = theirPackageJSON.main || './dist/index.js';
|
|
30
|
-
theirPackageJSON.preparePackage = theirPackageJSON.preparePackage || {};
|
|
31
|
-
theirPackageJSON.preparePackage.input = theirPackageJSON.preparePackage.input || './src';
|
|
32
|
-
theirPackageJSON.preparePackage.output = theirPackageJSON.preparePackage.output || './dist';
|
|
33
|
-
theirPackageJSON.preparePackage.replace = theirPackageJSON.preparePackage.replace || {};
|
|
34
|
-
|
|
35
|
-
// Add script
|
|
36
|
-
theirPackageJSON.scripts = theirPackageJSON.scripts || {};
|
|
37
|
-
theirPackageJSON.scripts.prepare = theirPackageJSON.scripts.prepare
|
|
38
|
-
|| 'node -e \'require(`prepare-package`)()\'';
|
|
39
|
-
theirPackageJSON.scripts['prepare:watch'] = theirPackageJSON.scripts['prepare:watch']
|
|
40
|
-
|| `nodemon -w ./src -e '*' --exec 'npm run prepare'`
|
|
41
|
-
|
|
42
|
-
// Log the options
|
|
43
|
-
console.log(chalk.blue(`[prepare-package]: Options purge=${options.purge}`));
|
|
44
|
-
console.log(chalk.blue(`[prepare-package]: input=${theirPackageJSON.preparePackage.input}`));
|
|
45
|
-
console.log(chalk.blue(`[prepare-package]: output=${theirPackageJSON.preparePackage.output}`));
|
|
46
|
-
console.log(chalk.blue(`[prepare-package]: main=${theirPackageJSON.main}`));
|
|
47
|
-
|
|
48
|
-
// Set the paths relative to the cwd
|
|
49
|
-
const mainPath = path.resolve(options.cwd, theirPackageJSON.main);
|
|
50
|
-
const outputPath = path.resolve(options.cwd, theirPackageJSON.preparePackage.output);
|
|
51
|
-
const inputPath = path.resolve(options.cwd, theirPackageJSON.preparePackage.input);
|
|
52
|
-
|
|
53
|
-
// Check if paths exist
|
|
54
|
-
const mainPathExists = jetpack.exists(mainPath);
|
|
55
|
-
const outputPathExists = jetpack.exists(outputPath);
|
|
56
|
-
const inputPathExists = jetpack.exists(inputPath);
|
|
57
|
-
|
|
58
|
-
// Remove the output folder if it exists (input must exist too)
|
|
59
|
-
if (outputPathExists && inputPathExists) {
|
|
60
|
-
jetpack.remove(outputPath);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// Copy the input folder to the output folder if it exists
|
|
64
|
-
if (inputPathExists) {
|
|
65
|
-
jetpack.copy(inputPath, outputPath);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Only do this part on the actual package that is using THIS package because we dont't want to replace THIS {version}
|
|
69
|
-
if (isLivePreparation) {
|
|
70
|
-
// Replace the main file
|
|
71
|
-
if (mainPathExists) {
|
|
72
|
-
jetpack.write(
|
|
73
|
-
mainPath,
|
|
74
|
-
jetpack.read(mainPath)
|
|
75
|
-
.replace(/{version}/igm, theirPackageJSON.version),
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// Replace the package.json
|
|
80
|
-
if (theirPackageJSONExists) {
|
|
81
|
-
jetpack.write(
|
|
82
|
-
theirPackageJSONPath,
|
|
83
|
-
JSON.stringify(theirPackageJSON, null, 2)
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Handle post install
|
|
89
|
-
if (options.isPostInstall) {
|
|
90
|
-
// Send analytics
|
|
91
|
-
// ... moveed to another package
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// If purge is disabled, then return
|
|
95
|
-
if (options.purge === false) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Purge the CDN
|
|
100
|
-
return fetch(`https://purge.jsdelivr.net/npm/${theirPackageJSON.name}@latest`, {
|
|
101
|
-
response: 'json',
|
|
102
|
-
tries: 3,
|
|
103
|
-
})
|
|
104
|
-
.then(result => {
|
|
105
|
-
console.log(chalk.green(`[prepare-package]: Purged ${theirPackageJSON.name}`));
|
|
106
|
-
})
|
|
107
|
-
.catch(e => {
|
|
108
|
-
console.log(chalk.red(`[prepare-package]: Failed to purge ${theirPackageJSON.name}`, e));
|
|
109
|
-
})
|
|
110
|
-
}
|
|
111
|
-
|