prepare-package 0.0.14 → 0.0.15
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 +1 -1
- package/dist/index.js +66 -60
- package/package.json +5 -6
- package/src/index.js +66 -60
package/README.md
CHANGED
|
@@ -43,7 +43,7 @@ After installing via npm, simply put this in your `package.json`
|
|
|
43
43
|
...
|
|
44
44
|
"main": "dist/index.js",
|
|
45
45
|
"scripts": {
|
|
46
|
-
"prepare": "node -e 'require(`prepare-package`)'"
|
|
46
|
+
"prepare": "node -e 'require(`prepare-package`)()'"
|
|
47
47
|
},
|
|
48
48
|
"preparePackage": {
|
|
49
49
|
"input": "src",
|
package/dist/index.js
CHANGED
|
@@ -1,64 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
1
|
+
module.exports = function (options) {
|
|
2
|
+
const jetpack = require('fs-jetpack');
|
|
3
|
+
const fetch = require('wonderful-fetch');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const chalk = require('chalk');
|
|
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;
|
|
10
|
+
|
|
11
|
+
options = options || {};
|
|
12
|
+
options.purge = typeof options.purge === 'undefined' ? true : options.purge;
|
|
9
13
|
|
|
10
|
-
const options = {
|
|
11
|
-
|
|
12
|
-
};
|
|
14
|
+
// const options = {
|
|
15
|
+
// purge: argv['--purge'] || argv['-p'],
|
|
16
|
+
// };
|
|
13
17
|
|
|
14
|
-
// fix
|
|
15
|
-
theirPackageJSON.main = theirPackageJSON.main || './dist/index.js';
|
|
16
|
-
theirPackageJSON.preparePackage = theirPackageJSON.preparePackage || {};
|
|
17
|
-
theirPackageJSON.preparePackage.input = path.resolve(theirPackageJSON.preparePackage.input || './src');
|
|
18
|
-
theirPackageJSON.preparePackage.output = path.resolve(theirPackageJSON.preparePackage.output || './dist');
|
|
19
|
-
theirPackageJSON.preparePackage.replace = theirPackageJSON.preparePackage.replace || {};
|
|
20
|
-
|
|
21
|
-
console.log(chalk.blue(`[prepare-package]: Preparing...`));
|
|
22
|
-
console.log(chalk.blue(`[prepare-package]: ${theirPackageJSON.preparePackage.input}`));
|
|
23
|
-
console.log(chalk.blue(`[prepare-package]: ${theirPackageJSON.preparePackage.output}`));
|
|
24
|
-
console.log(chalk.blue(`[prepare-package]: ${theirPackageJSON.main}`));
|
|
25
|
-
|
|
26
|
-
jetpack.remove(
|
|
27
|
-
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
jetpack.copy(
|
|
31
|
-
theirPackageJSON.preparePackage.input,
|
|
32
|
-
theirPackageJSON.preparePackage.output,
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
// Only do this part on the actual package that is using THIS package because we dont't want to replace THIS {version}
|
|
36
|
-
if (isLivePreparation) {
|
|
37
|
-
function _replaceMain() {
|
|
38
|
-
let content = jetpack.read(theirPackageJSON.main)
|
|
39
|
-
// .replace(/{version}/igm, package.version)
|
|
40
|
-
.replace(/{version}/igm, theirPackageJSON.version)
|
|
41
|
-
return content;
|
|
42
|
-
}
|
|
43
|
-
jetpack.write(
|
|
44
|
-
theirPackageJSON.main,
|
|
45
|
-
_replaceMain()
|
|
18
|
+
// fix
|
|
19
|
+
theirPackageJSON.main = theirPackageJSON.main || './dist/index.js';
|
|
20
|
+
theirPackageJSON.preparePackage = theirPackageJSON.preparePackage || {};
|
|
21
|
+
theirPackageJSON.preparePackage.input = path.resolve(theirPackageJSON.preparePackage.input || './src');
|
|
22
|
+
theirPackageJSON.preparePackage.output = path.resolve(theirPackageJSON.preparePackage.output || './dist');
|
|
23
|
+
theirPackageJSON.preparePackage.replace = theirPackageJSON.preparePackage.replace || {};
|
|
24
|
+
|
|
25
|
+
console.log(chalk.blue(`[prepare-package]: Preparing purge=${options.purge}...`));
|
|
26
|
+
console.log(chalk.blue(`[prepare-package]: ${theirPackageJSON.preparePackage.input}`));
|
|
27
|
+
console.log(chalk.blue(`[prepare-package]: ${theirPackageJSON.preparePackage.output}`));
|
|
28
|
+
console.log(chalk.blue(`[prepare-package]: ${theirPackageJSON.main}`));
|
|
29
|
+
|
|
30
|
+
jetpack.remove(
|
|
31
|
+
theirPackageJSON.preparePackage.output,
|
|
46
32
|
)
|
|
33
|
+
|
|
34
|
+
jetpack.copy(
|
|
35
|
+
theirPackageJSON.preparePackage.input,
|
|
36
|
+
theirPackageJSON.preparePackage.output,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
// Only do this part on the actual package that is using THIS package because we dont't want to replace THIS {version}
|
|
40
|
+
if (isLivePreparation) {
|
|
41
|
+
function _replaceMain() {
|
|
42
|
+
let content = jetpack.read(theirPackageJSON.main)
|
|
43
|
+
// .replace(/{version}/igm, package.version)
|
|
44
|
+
.replace(/{version}/igm, theirPackageJSON.version)
|
|
45
|
+
return content;
|
|
46
|
+
}
|
|
47
|
+
jetpack.write(
|
|
48
|
+
theirPackageJSON.main,
|
|
49
|
+
_replaceMain()
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (options.purge === false) {
|
|
54
|
+
return;
|
|
55
|
+
} else {
|
|
56
|
+
return fetch(`https://purge.jsdelivr.net/npm/${theirPackageJSON.name}@latest`, {
|
|
57
|
+
response: 'json',
|
|
58
|
+
tries: 3,
|
|
59
|
+
})
|
|
60
|
+
.then(result => {
|
|
61
|
+
// console.log(chalk.green(`[prepare-package]: Purged... name=${theirPackageJSON.name}`), result);
|
|
62
|
+
console.log(chalk.green(`[prepare-package]: Purged... ${theirPackageJSON.name}`));
|
|
63
|
+
})
|
|
64
|
+
.catch(e => {
|
|
65
|
+
console.log(chalk.red(`[prepare-package]: Failed to purge... ${theirPackageJSON.name}`, e));
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
47
70
|
}
|
|
48
|
-
|
|
49
|
-
if (options.prepare === 'false') {
|
|
50
|
-
return;
|
|
51
|
-
} else {
|
|
52
|
-
return fetch(`https://purge.jsdelivr.net/npm/${theirPackageJSON.name}@latest`, {
|
|
53
|
-
response: 'json',
|
|
54
|
-
tries: 3,
|
|
55
|
-
})
|
|
56
|
-
.then(result => {
|
|
57
|
-
// console.log(chalk.green(`[prepare-package]: Purged... name=${theirPackageJSON.name}`), result);
|
|
58
|
-
console.log(chalk.green(`[prepare-package]: Purged... ${theirPackageJSON.name}`));
|
|
59
|
-
})
|
|
60
|
-
.catch(e => {
|
|
61
|
-
console.log(chalk.red(`[prepare-package]: Failed to purge... ${theirPackageJSON.name}`, e));
|
|
62
|
-
})
|
|
63
|
-
}
|
|
64
|
-
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "prepare-package",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15",
|
|
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
|
|
9
|
-
"prepare": "node
|
|
8
|
+
"start": "node -e 'require(`./src/index.js`)()'",
|
|
9
|
+
"prepare": "node -e 'require(`./src/index.js`)()'"
|
|
10
10
|
},
|
|
11
11
|
"preparePackage": {
|
|
12
12
|
"input": "src",
|
|
@@ -35,10 +35,9 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"chalk": "^4.1.2",
|
|
37
37
|
"fs-jetpack": "^4.3.1",
|
|
38
|
-
"wonderful-fetch": "^0.0.14"
|
|
39
|
-
"yargs": "^17.5.1"
|
|
38
|
+
"wonderful-fetch": "^0.0.14"
|
|
40
39
|
},
|
|
41
40
|
"devDependencies": {
|
|
42
41
|
"mocha": "^8.4.0"
|
|
43
42
|
}
|
|
44
|
-
}
|
|
43
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,64 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
1
|
+
module.exports = function (options) {
|
|
2
|
+
const jetpack = require('fs-jetpack');
|
|
3
|
+
const fetch = require('wonderful-fetch');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const chalk = require('chalk');
|
|
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;
|
|
10
|
+
|
|
11
|
+
options = options || {};
|
|
12
|
+
options.purge = typeof options.purge === 'undefined' ? true : options.purge;
|
|
9
13
|
|
|
10
|
-
const options = {
|
|
11
|
-
|
|
12
|
-
};
|
|
14
|
+
// const options = {
|
|
15
|
+
// purge: argv['--purge'] || argv['-p'],
|
|
16
|
+
// };
|
|
13
17
|
|
|
14
|
-
// fix
|
|
15
|
-
theirPackageJSON.main = theirPackageJSON.main || './dist/index.js';
|
|
16
|
-
theirPackageJSON.preparePackage = theirPackageJSON.preparePackage || {};
|
|
17
|
-
theirPackageJSON.preparePackage.input = path.resolve(theirPackageJSON.preparePackage.input || './src');
|
|
18
|
-
theirPackageJSON.preparePackage.output = path.resolve(theirPackageJSON.preparePackage.output || './dist');
|
|
19
|
-
theirPackageJSON.preparePackage.replace = theirPackageJSON.preparePackage.replace || {};
|
|
20
|
-
|
|
21
|
-
console.log(chalk.blue(`[prepare-package]: Preparing...`));
|
|
22
|
-
console.log(chalk.blue(`[prepare-package]: ${theirPackageJSON.preparePackage.input}`));
|
|
23
|
-
console.log(chalk.blue(`[prepare-package]: ${theirPackageJSON.preparePackage.output}`));
|
|
24
|
-
console.log(chalk.blue(`[prepare-package]: ${theirPackageJSON.main}`));
|
|
25
|
-
|
|
26
|
-
jetpack.remove(
|
|
27
|
-
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
jetpack.copy(
|
|
31
|
-
theirPackageJSON.preparePackage.input,
|
|
32
|
-
theirPackageJSON.preparePackage.output,
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
// Only do this part on the actual package that is using THIS package because we dont't want to replace THIS {version}
|
|
36
|
-
if (isLivePreparation) {
|
|
37
|
-
function _replaceMain() {
|
|
38
|
-
let content = jetpack.read(theirPackageJSON.main)
|
|
39
|
-
// .replace(/{version}/igm, package.version)
|
|
40
|
-
.replace(/{version}/igm, theirPackageJSON.version)
|
|
41
|
-
return content;
|
|
42
|
-
}
|
|
43
|
-
jetpack.write(
|
|
44
|
-
theirPackageJSON.main,
|
|
45
|
-
_replaceMain()
|
|
18
|
+
// fix
|
|
19
|
+
theirPackageJSON.main = theirPackageJSON.main || './dist/index.js';
|
|
20
|
+
theirPackageJSON.preparePackage = theirPackageJSON.preparePackage || {};
|
|
21
|
+
theirPackageJSON.preparePackage.input = path.resolve(theirPackageJSON.preparePackage.input || './src');
|
|
22
|
+
theirPackageJSON.preparePackage.output = path.resolve(theirPackageJSON.preparePackage.output || './dist');
|
|
23
|
+
theirPackageJSON.preparePackage.replace = theirPackageJSON.preparePackage.replace || {};
|
|
24
|
+
|
|
25
|
+
console.log(chalk.blue(`[prepare-package]: Preparing purge=${options.purge}...`));
|
|
26
|
+
console.log(chalk.blue(`[prepare-package]: ${theirPackageJSON.preparePackage.input}`));
|
|
27
|
+
console.log(chalk.blue(`[prepare-package]: ${theirPackageJSON.preparePackage.output}`));
|
|
28
|
+
console.log(chalk.blue(`[prepare-package]: ${theirPackageJSON.main}`));
|
|
29
|
+
|
|
30
|
+
jetpack.remove(
|
|
31
|
+
theirPackageJSON.preparePackage.output,
|
|
46
32
|
)
|
|
33
|
+
|
|
34
|
+
jetpack.copy(
|
|
35
|
+
theirPackageJSON.preparePackage.input,
|
|
36
|
+
theirPackageJSON.preparePackage.output,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
// Only do this part on the actual package that is using THIS package because we dont't want to replace THIS {version}
|
|
40
|
+
if (isLivePreparation) {
|
|
41
|
+
function _replaceMain() {
|
|
42
|
+
let content = jetpack.read(theirPackageJSON.main)
|
|
43
|
+
// .replace(/{version}/igm, package.version)
|
|
44
|
+
.replace(/{version}/igm, theirPackageJSON.version)
|
|
45
|
+
return content;
|
|
46
|
+
}
|
|
47
|
+
jetpack.write(
|
|
48
|
+
theirPackageJSON.main,
|
|
49
|
+
_replaceMain()
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (options.purge === false) {
|
|
54
|
+
return;
|
|
55
|
+
} else {
|
|
56
|
+
return fetch(`https://purge.jsdelivr.net/npm/${theirPackageJSON.name}@latest`, {
|
|
57
|
+
response: 'json',
|
|
58
|
+
tries: 3,
|
|
59
|
+
})
|
|
60
|
+
.then(result => {
|
|
61
|
+
// console.log(chalk.green(`[prepare-package]: Purged... name=${theirPackageJSON.name}`), result);
|
|
62
|
+
console.log(chalk.green(`[prepare-package]: Purged... ${theirPackageJSON.name}`));
|
|
63
|
+
})
|
|
64
|
+
.catch(e => {
|
|
65
|
+
console.log(chalk.red(`[prepare-package]: Failed to purge... ${theirPackageJSON.name}`, e));
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
47
70
|
}
|
|
48
|
-
|
|
49
|
-
if (options.prepare === 'false') {
|
|
50
|
-
return;
|
|
51
|
-
} else {
|
|
52
|
-
return fetch(`https://purge.jsdelivr.net/npm/${theirPackageJSON.name}@latest`, {
|
|
53
|
-
response: 'json',
|
|
54
|
-
tries: 3,
|
|
55
|
-
})
|
|
56
|
-
.then(result => {
|
|
57
|
-
// console.log(chalk.green(`[prepare-package]: Purged... name=${theirPackageJSON.name}`), result);
|
|
58
|
-
console.log(chalk.green(`[prepare-package]: Purged... ${theirPackageJSON.name}`));
|
|
59
|
-
})
|
|
60
|
-
.catch(e => {
|
|
61
|
-
console.log(chalk.red(`[prepare-package]: Failed to purge... ${theirPackageJSON.name}`, e));
|
|
62
|
-
})
|
|
63
|
-
}
|
|
64
|
-
|