Skip to content

Commit 5a4b881

Browse files
committed
add prepublish script
1 parent d2e0d4e commit 5a4b881

File tree

4 files changed

+48
-18
lines changed

4 files changed

+48
-18
lines changed

.npmignore

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
1-
tmp
2-
test/
3-
dist/test/**
4-
.*
5-
Makefile
6-
*.map
7-
*.bat
8-
*.pem
9-
tslint.json
10-
*.tgz
11-
notes.md
12-
tsconfig.json
13-
/lib
14-
*.tsbuildinfo
15-
certificates
16-
# !*.map
1+
# Ignore all .map files, wherever they are
2+
**/*.map
3+
**/**/*.map
4+
**/**/**/*.map
5+
6+
# You can also ignore other build artifacts
7+
*.tsbuildinfo

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6868
> 24 September 2024
6969
7070
- update packages , use node-opcua-crypto@4.10.0 [`a63eaae`](https://github.com/node-opcua/node-opcua-pki/commit/a63eaae1dbe26afae81986fbc2de084b24a47e6d)
71-
- update chodikar [`176d4db`](https://github.com/node-opcua/node-opcua-pki/commit/176d4dbd49fa99ee0eddc958476d1dcfe417b01e)
71+
- update chokidar [`176d4db`](https://github.com/node-opcua/node-opcua-pki/commit/176d4dbd49fa99ee0eddc958476d1dcfe417b01e)
7272
- Release 4.14.0 [`c8ec128`](https://github.com/node-opcua/node-opcua-pki/commit/c8ec128a356b246fe7e0e2aab7079320bf229137)
7373

7474
#### [4.13.1](https://github.com/node-opcua/node-opcua-pki/compare/4.13.0...4.13.1)

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,17 @@
1818
"tslint": "npx tslint -c tslint.json lib/**/*.ts",
1919
"postinstall2": "opencollective-postinstall",
2020
"postinstall3": "github-sponsors",
21-
"makelinks": "npx tsx ../make-links/makelinks.ts"
21+
"makelinks": "npx tsx ../make-links/makelinks.ts",
22+
"prepublishOnly": "node scripts/prepare-publish.cjs clean",
23+
"postpublish": "node scripts/prepare-publish.cjs restore",
24+
"pack:clean": "node scripts/prepare-publish.cjs clean && npm pack && node scripts/prepare-publish.cjs restore"
2225
},
26+
"files": [
27+
"dist/**/*.js",
28+
"dist/**/*.d.ts",
29+
"bin/**/*.js",
30+
"bin/**/*.d.ts"
31+
],
2332
"repository": {
2433
"type": "git",
2534
"url": "https://github.com/node-opcua/node-opcua-pki.git"

scripts/prepare-publish.cjs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const packageJsonPath = path.join(__dirname, '..', 'package.json');
5+
const backupPath = path.join(__dirname, '..', 'package.json.bak');
6+
7+
const command = process.argv[2]; // 'clean' or 'restore'
8+
9+
console.log(`Running prepare-publish script with command: ${command}`);
10+
11+
if (command === 'clean') {
12+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
13+
14+
// Create a backup of the original file
15+
fs.copyFileSync(packageJsonPath, backupPath);
16+
console.log('Created backup of package.json.');
17+
18+
// Remove the sections you don't want to publish
19+
delete packageJson.devDependencies;
20+
delete packageJson.scripts;
21+
22+
// Overwrite the package.json with the cleaned version
23+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n');
24+
console.log('Cleaned package.json for publishing.');
25+
26+
} else if (command === 'restore') {
27+
// Restore the original package.json from backup
28+
fs.renameSync(backupPath, packageJsonPath);
29+
console.log('Restored original package.json.');
30+
}

0 commit comments

Comments
 (0)