prepare-package 1.0.5 → 1.1.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.js +33 -27
- package/package.json +2 -2
- package/src/index.js +33 -27
package/dist/index.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const thisPackageJSON = require('../package.json');
|
|
7
|
-
const theirPackageJSON = require(path.join(process.cwd(), 'package.json'));
|
|
8
|
-
const isLivePreparation = theirPackageJSON.name !== 'prepare-package';
|
|
9
|
-
// const argv = require('yargs').argv;
|
|
1
|
+
const jetpack = require('fs-jetpack');
|
|
2
|
+
const fetch = require('wonderful-fetch');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const chalk = require('chalk');
|
|
5
|
+
// const argv = require('yargs').argv;
|
|
10
6
|
|
|
7
|
+
module.exports = function (options) {
|
|
8
|
+
// Set the options
|
|
11
9
|
options = options || {};
|
|
12
10
|
options.purge = typeof options.purge === 'undefined' ? true : options.purge;
|
|
11
|
+
options.cwd = options.cwd || process.cwd();
|
|
12
|
+
|
|
13
|
+
const thisPackageJSON = require('../package.json');
|
|
14
|
+
const theirPackageJSON = require(path.join(options.cwd, 'package.json'));
|
|
15
|
+
const isLivePreparation = theirPackageJSON.name !== 'prepare-package';
|
|
13
16
|
|
|
14
17
|
// const options = {
|
|
15
18
|
// purge: argv['--purge'] || argv['-p'],
|
|
@@ -18,16 +21,16 @@ module.exports = function (options) {
|
|
|
18
21
|
// Fix their package.json
|
|
19
22
|
theirPackageJSON.main = theirPackageJSON.main || './dist/index.js';
|
|
20
23
|
theirPackageJSON.preparePackage = theirPackageJSON.preparePackage || {};
|
|
21
|
-
theirPackageJSON.preparePackage.input =
|
|
22
|
-
theirPackageJSON.preparePackage.output =
|
|
24
|
+
theirPackageJSON.preparePackage.input = theirPackageJSON.preparePackage.input || './src';
|
|
25
|
+
theirPackageJSON.preparePackage.output = theirPackageJSON.preparePackage.output || './dist';
|
|
23
26
|
theirPackageJSON.preparePackage.replace = theirPackageJSON.preparePackage.replace || {};
|
|
24
27
|
|
|
25
28
|
// Add script
|
|
26
29
|
theirPackageJSON.scripts = theirPackageJSON.scripts || {};
|
|
27
30
|
theirPackageJSON.scripts.prepare = theirPackageJSON.scripts.prepare
|
|
28
|
-
|| 'node -e
|
|
31
|
+
|| 'node -e \'require(`prepare-package`)()\'';
|
|
29
32
|
theirPackageJSON.scripts['prepare:watch'] = theirPackageJSON.scripts['prepare:watch']
|
|
30
|
-
|| `nodemon -w
|
|
33
|
+
|| `nodemon -w ./src -e '*' --exec 'npm run prepare'`
|
|
31
34
|
|
|
32
35
|
// Log the options
|
|
33
36
|
console.log(chalk.blue(`[prepare-package]: Options... purge=${options.purge}`));
|
|
@@ -37,27 +40,31 @@ module.exports = function (options) {
|
|
|
37
40
|
|
|
38
41
|
// Remove the output folder
|
|
39
42
|
jetpack.remove(
|
|
40
|
-
theirPackageJSON.preparePackage.output,
|
|
43
|
+
path.resolve(options.cwd, theirPackageJSON.preparePackage.output),
|
|
41
44
|
)
|
|
42
45
|
|
|
43
46
|
// Copy the input folder to the output folder
|
|
44
47
|
jetpack.copy(
|
|
45
|
-
theirPackageJSON.preparePackage.input,
|
|
46
|
-
theirPackageJSON.preparePackage.output,
|
|
48
|
+
path.resolve(options.cwd, theirPackageJSON.preparePackage.input),
|
|
49
|
+
path.resolve(options.cwd, theirPackageJSON.preparePackage.output),
|
|
47
50
|
)
|
|
48
51
|
|
|
49
52
|
// Only do this part on the actual package that is using THIS package because we dont't want to replace THIS {version}
|
|
50
53
|
if (isLivePreparation) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
const mainPath = path.resolve(options.cwd, theirPackageJSON.main);
|
|
55
|
+
|
|
56
|
+
// Replace the main file
|
|
57
|
+
jetpack.write(
|
|
58
|
+
mainPath,
|
|
59
|
+
jetpack.read(mainPath)
|
|
60
|
+
.replace(/{version}/igm, theirPackageJSON.version),
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
// Replace the package.json
|
|
57
64
|
jetpack.write(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
)
|
|
65
|
+
path.resolve(options.cwd, 'package.json'),
|
|
66
|
+
JSON.stringify(theirPackageJSON, null, 2)
|
|
67
|
+
);
|
|
61
68
|
}
|
|
62
69
|
|
|
63
70
|
if (options.purge === false) {
|
|
@@ -68,13 +75,12 @@ module.exports = function (options) {
|
|
|
68
75
|
tries: 3,
|
|
69
76
|
})
|
|
70
77
|
.then(result => {
|
|
71
|
-
// console.log(chalk.green(`[prepare-package]: Purged... name=${theirPackageJSON.name}`), result);
|
|
72
78
|
console.log(chalk.green(`[prepare-package]: Purged... ${theirPackageJSON.name}`));
|
|
73
79
|
})
|
|
74
80
|
.catch(e => {
|
|
75
81
|
console.log(chalk.red(`[prepare-package]: Failed to purge... ${theirPackageJSON.name}`, e));
|
|
76
82
|
})
|
|
77
83
|
}
|
|
84
|
+
}
|
|
78
85
|
|
|
79
86
|
|
|
80
|
-
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prepare-package",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Prepare a Node.js package before being published",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"start": "node -e 'require(`./src/index.js`)()'",
|
|
9
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})'"
|
|
12
12
|
},
|
|
13
13
|
"preparePackage": {
|
|
14
14
|
"input": "src",
|
package/src/index.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const thisPackageJSON = require('../package.json');
|
|
7
|
-
const theirPackageJSON = require(path.join(process.cwd(), 'package.json'));
|
|
8
|
-
const isLivePreparation = theirPackageJSON.name !== 'prepare-package';
|
|
9
|
-
// const argv = require('yargs').argv;
|
|
1
|
+
const jetpack = require('fs-jetpack');
|
|
2
|
+
const fetch = require('wonderful-fetch');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const chalk = require('chalk');
|
|
5
|
+
// const argv = require('yargs').argv;
|
|
10
6
|
|
|
7
|
+
module.exports = function (options) {
|
|
8
|
+
// Set the options
|
|
11
9
|
options = options || {};
|
|
12
10
|
options.purge = typeof options.purge === 'undefined' ? true : options.purge;
|
|
11
|
+
options.cwd = options.cwd || process.cwd();
|
|
12
|
+
|
|
13
|
+
const thisPackageJSON = require('../package.json');
|
|
14
|
+
const theirPackageJSON = require(path.join(options.cwd, 'package.json'));
|
|
15
|
+
const isLivePreparation = theirPackageJSON.name !== 'prepare-package';
|
|
13
16
|
|
|
14
17
|
// const options = {
|
|
15
18
|
// purge: argv['--purge'] || argv['-p'],
|
|
@@ -18,16 +21,16 @@ module.exports = function (options) {
|
|
|
18
21
|
// Fix their package.json
|
|
19
22
|
theirPackageJSON.main = theirPackageJSON.main || './dist/index.js';
|
|
20
23
|
theirPackageJSON.preparePackage = theirPackageJSON.preparePackage || {};
|
|
21
|
-
theirPackageJSON.preparePackage.input =
|
|
22
|
-
theirPackageJSON.preparePackage.output =
|
|
24
|
+
theirPackageJSON.preparePackage.input = theirPackageJSON.preparePackage.input || './src';
|
|
25
|
+
theirPackageJSON.preparePackage.output = theirPackageJSON.preparePackage.output || './dist';
|
|
23
26
|
theirPackageJSON.preparePackage.replace = theirPackageJSON.preparePackage.replace || {};
|
|
24
27
|
|
|
25
28
|
// Add script
|
|
26
29
|
theirPackageJSON.scripts = theirPackageJSON.scripts || {};
|
|
27
30
|
theirPackageJSON.scripts.prepare = theirPackageJSON.scripts.prepare
|
|
28
|
-
|| 'node -e
|
|
31
|
+
|| 'node -e \'require(`prepare-package`)()\'';
|
|
29
32
|
theirPackageJSON.scripts['prepare:watch'] = theirPackageJSON.scripts['prepare:watch']
|
|
30
|
-
|| `nodemon -w
|
|
33
|
+
|| `nodemon -w ./src -e '*' --exec 'npm run prepare'`
|
|
31
34
|
|
|
32
35
|
// Log the options
|
|
33
36
|
console.log(chalk.blue(`[prepare-package]: Options... purge=${options.purge}`));
|
|
@@ -37,27 +40,31 @@ module.exports = function (options) {
|
|
|
37
40
|
|
|
38
41
|
// Remove the output folder
|
|
39
42
|
jetpack.remove(
|
|
40
|
-
theirPackageJSON.preparePackage.output,
|
|
43
|
+
path.resolve(options.cwd, theirPackageJSON.preparePackage.output),
|
|
41
44
|
)
|
|
42
45
|
|
|
43
46
|
// Copy the input folder to the output folder
|
|
44
47
|
jetpack.copy(
|
|
45
|
-
theirPackageJSON.preparePackage.input,
|
|
46
|
-
theirPackageJSON.preparePackage.output,
|
|
48
|
+
path.resolve(options.cwd, theirPackageJSON.preparePackage.input),
|
|
49
|
+
path.resolve(options.cwd, theirPackageJSON.preparePackage.output),
|
|
47
50
|
)
|
|
48
51
|
|
|
49
52
|
// Only do this part on the actual package that is using THIS package because we dont't want to replace THIS {version}
|
|
50
53
|
if (isLivePreparation) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
const mainPath = path.resolve(options.cwd, theirPackageJSON.main);
|
|
55
|
+
|
|
56
|
+
// Replace the main file
|
|
57
|
+
jetpack.write(
|
|
58
|
+
mainPath,
|
|
59
|
+
jetpack.read(mainPath)
|
|
60
|
+
.replace(/{version}/igm, theirPackageJSON.version),
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
// Replace the package.json
|
|
57
64
|
jetpack.write(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
)
|
|
65
|
+
path.resolve(options.cwd, 'package.json'),
|
|
66
|
+
JSON.stringify(theirPackageJSON, null, 2)
|
|
67
|
+
);
|
|
61
68
|
}
|
|
62
69
|
|
|
63
70
|
if (options.purge === false) {
|
|
@@ -68,13 +75,12 @@ module.exports = function (options) {
|
|
|
68
75
|
tries: 3,
|
|
69
76
|
})
|
|
70
77
|
.then(result => {
|
|
71
|
-
// console.log(chalk.green(`[prepare-package]: Purged... name=${theirPackageJSON.name}`), result);
|
|
72
78
|
console.log(chalk.green(`[prepare-package]: Purged... ${theirPackageJSON.name}`));
|
|
73
79
|
})
|
|
74
80
|
.catch(e => {
|
|
75
81
|
console.log(chalk.red(`[prepare-package]: Failed to purge... ${theirPackageJSON.name}`, e));
|
|
76
82
|
})
|
|
77
83
|
}
|
|
84
|
+
}
|
|
78
85
|
|
|
79
86
|
|
|
80
|
-
}
|