prepare-package 1.0.3 → 1.0.5
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 +20 -10
- package/package.json +3 -2
- package/src/index.js +20 -10
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ module.exports = function (options) {
|
|
|
7
7
|
const theirPackageJSON = require(path.join(process.cwd(), 'package.json'));
|
|
8
8
|
const isLivePreparation = theirPackageJSON.name !== 'prepare-package';
|
|
9
9
|
// const argv = require('yargs').argv;
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
options = options || {};
|
|
12
12
|
options.purge = typeof options.purge === 'undefined' ? true : options.purge;
|
|
13
13
|
|
|
@@ -15,27 +15,37 @@ module.exports = function (options) {
|
|
|
15
15
|
// purge: argv['--purge'] || argv['-p'],
|
|
16
16
|
// };
|
|
17
17
|
|
|
18
|
-
//
|
|
18
|
+
// Fix their package.json
|
|
19
19
|
theirPackageJSON.main = theirPackageJSON.main || './dist/index.js';
|
|
20
20
|
theirPackageJSON.preparePackage = theirPackageJSON.preparePackage || {};
|
|
21
21
|
theirPackageJSON.preparePackage.input = path.resolve(theirPackageJSON.preparePackage.input || './src');
|
|
22
22
|
theirPackageJSON.preparePackage.output = path.resolve(theirPackageJSON.preparePackage.output || './dist');
|
|
23
23
|
theirPackageJSON.preparePackage.replace = theirPackageJSON.preparePackage.replace || {};
|
|
24
|
-
|
|
24
|
+
|
|
25
|
+
// Add script
|
|
26
|
+
theirPackageJSON.scripts = theirPackageJSON.scripts || {};
|
|
27
|
+
theirPackageJSON.scripts.prepare = theirPackageJSON.scripts.prepare
|
|
28
|
+
|| 'node -e "require(`prepare-package`)()"';
|
|
29
|
+
theirPackageJSON.scripts['prepare:watch'] = theirPackageJSON.scripts['prepare:watch']
|
|
30
|
+
|| `nodemon -w ${theirPackageJSON.preparePackage.input} -e '*' --exec 'npm run prepare'`
|
|
31
|
+
|
|
32
|
+
// Log the options
|
|
25
33
|
console.log(chalk.blue(`[prepare-package]: Options... purge=${options.purge}`));
|
|
26
34
|
console.log(chalk.blue(`[prepare-package]: input=${theirPackageJSON.preparePackage.input}`));
|
|
27
35
|
console.log(chalk.blue(`[prepare-package]: output=${theirPackageJSON.preparePackage.output}`));
|
|
28
36
|
console.log(chalk.blue(`[prepare-package]: main=${theirPackageJSON.main}`));
|
|
29
|
-
|
|
37
|
+
|
|
38
|
+
// Remove the output folder
|
|
30
39
|
jetpack.remove(
|
|
31
40
|
theirPackageJSON.preparePackage.output,
|
|
32
41
|
)
|
|
33
|
-
|
|
42
|
+
|
|
43
|
+
// Copy the input folder to the output folder
|
|
34
44
|
jetpack.copy(
|
|
35
45
|
theirPackageJSON.preparePackage.input,
|
|
36
46
|
theirPackageJSON.preparePackage.output,
|
|
37
47
|
)
|
|
38
|
-
|
|
48
|
+
|
|
39
49
|
// Only do this part on the actual package that is using THIS package because we dont't want to replace THIS {version}
|
|
40
50
|
if (isLivePreparation) {
|
|
41
51
|
function _replaceMain() {
|
|
@@ -49,7 +59,7 @@ module.exports = function (options) {
|
|
|
49
59
|
_replaceMain()
|
|
50
60
|
)
|
|
51
61
|
}
|
|
52
|
-
|
|
62
|
+
|
|
53
63
|
if (options.purge === false) {
|
|
54
64
|
return;
|
|
55
65
|
} else {
|
|
@@ -63,8 +73,8 @@ module.exports = function (options) {
|
|
|
63
73
|
})
|
|
64
74
|
.catch(e => {
|
|
65
75
|
console.log(chalk.red(`[prepare-package]: Failed to purge... ${theirPackageJSON.name}`, e));
|
|
66
|
-
})
|
|
76
|
+
})
|
|
67
77
|
}
|
|
68
|
-
|
|
69
|
-
|
|
78
|
+
|
|
79
|
+
|
|
70
80
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prepare-package",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
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
8
|
"start": "node -e 'require(`./src/index.js`)()'",
|
|
9
9
|
"prepare": "node -e 'require(`./src/index.js`)()'",
|
|
10
|
-
"prepare:watch": "nodemon -w ./src -e '*' --exec 'npm run prepare'"
|
|
10
|
+
"prepare:watch": "nodemon -w ./src -e '*' --exec 'npm run prepare'",
|
|
11
|
+
"postinstall": "node -e 'console.log(`🚀 prepare-package has been installed successfully!`)'"
|
|
11
12
|
},
|
|
12
13
|
"preparePackage": {
|
|
13
14
|
"input": "src",
|
package/src/index.js
CHANGED
|
@@ -7,7 +7,7 @@ module.exports = function (options) {
|
|
|
7
7
|
const theirPackageJSON = require(path.join(process.cwd(), 'package.json'));
|
|
8
8
|
const isLivePreparation = theirPackageJSON.name !== 'prepare-package';
|
|
9
9
|
// const argv = require('yargs').argv;
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
options = options || {};
|
|
12
12
|
options.purge = typeof options.purge === 'undefined' ? true : options.purge;
|
|
13
13
|
|
|
@@ -15,27 +15,37 @@ module.exports = function (options) {
|
|
|
15
15
|
// purge: argv['--purge'] || argv['-p'],
|
|
16
16
|
// };
|
|
17
17
|
|
|
18
|
-
//
|
|
18
|
+
// Fix their package.json
|
|
19
19
|
theirPackageJSON.main = theirPackageJSON.main || './dist/index.js';
|
|
20
20
|
theirPackageJSON.preparePackage = theirPackageJSON.preparePackage || {};
|
|
21
21
|
theirPackageJSON.preparePackage.input = path.resolve(theirPackageJSON.preparePackage.input || './src');
|
|
22
22
|
theirPackageJSON.preparePackage.output = path.resolve(theirPackageJSON.preparePackage.output || './dist');
|
|
23
23
|
theirPackageJSON.preparePackage.replace = theirPackageJSON.preparePackage.replace || {};
|
|
24
|
-
|
|
24
|
+
|
|
25
|
+
// Add script
|
|
26
|
+
theirPackageJSON.scripts = theirPackageJSON.scripts || {};
|
|
27
|
+
theirPackageJSON.scripts.prepare = theirPackageJSON.scripts.prepare
|
|
28
|
+
|| 'node -e "require(`prepare-package`)()"';
|
|
29
|
+
theirPackageJSON.scripts['prepare:watch'] = theirPackageJSON.scripts['prepare:watch']
|
|
30
|
+
|| `nodemon -w ${theirPackageJSON.preparePackage.input} -e '*' --exec 'npm run prepare'`
|
|
31
|
+
|
|
32
|
+
// Log the options
|
|
25
33
|
console.log(chalk.blue(`[prepare-package]: Options... purge=${options.purge}`));
|
|
26
34
|
console.log(chalk.blue(`[prepare-package]: input=${theirPackageJSON.preparePackage.input}`));
|
|
27
35
|
console.log(chalk.blue(`[prepare-package]: output=${theirPackageJSON.preparePackage.output}`));
|
|
28
36
|
console.log(chalk.blue(`[prepare-package]: main=${theirPackageJSON.main}`));
|
|
29
|
-
|
|
37
|
+
|
|
38
|
+
// Remove the output folder
|
|
30
39
|
jetpack.remove(
|
|
31
40
|
theirPackageJSON.preparePackage.output,
|
|
32
41
|
)
|
|
33
|
-
|
|
42
|
+
|
|
43
|
+
// Copy the input folder to the output folder
|
|
34
44
|
jetpack.copy(
|
|
35
45
|
theirPackageJSON.preparePackage.input,
|
|
36
46
|
theirPackageJSON.preparePackage.output,
|
|
37
47
|
)
|
|
38
|
-
|
|
48
|
+
|
|
39
49
|
// Only do this part on the actual package that is using THIS package because we dont't want to replace THIS {version}
|
|
40
50
|
if (isLivePreparation) {
|
|
41
51
|
function _replaceMain() {
|
|
@@ -49,7 +59,7 @@ module.exports = function (options) {
|
|
|
49
59
|
_replaceMain()
|
|
50
60
|
)
|
|
51
61
|
}
|
|
52
|
-
|
|
62
|
+
|
|
53
63
|
if (options.purge === false) {
|
|
54
64
|
return;
|
|
55
65
|
} else {
|
|
@@ -63,8 +73,8 @@ module.exports = function (options) {
|
|
|
63
73
|
})
|
|
64
74
|
.catch(e => {
|
|
65
75
|
console.log(chalk.red(`[prepare-package]: Failed to purge... ${theirPackageJSON.name}`, e));
|
|
66
|
-
})
|
|
76
|
+
})
|
|
67
77
|
}
|
|
68
|
-
|
|
69
|
-
|
|
78
|
+
|
|
79
|
+
|
|
70
80
|
}
|