|
1 | 1 | const ngPackage = require('ng-packagr');
|
2 | 2 | const path = require('path');
|
3 | 3 | const fs = require('fs-extra');
|
| 4 | +const { serializeJson, parseJson } = require('@nx/devkit'); |
4 | 5 |
|
5 | 6 | const rootDir = path.resolve(path.join(__dirname, '..', '..'));
|
6 | 7 | const nxConfigPath = path.resolve(path.join(rootDir, 'nx.json'));
|
@@ -44,9 +45,31 @@ function copyAngularDist() {
|
44 | 45 | .catch((err) => console.error(err));
|
45 | 46 | }
|
46 | 47 |
|
| 48 | +function cleanPackage() { |
| 49 | + // helps remove unwanted properties which may be added by other tooling |
| 50 | + const packageJsonPath = path.resolve(rootDir, 'dist', 'packages', packageName, 'package.json'); |
| 51 | + let packageJson = fs.readFileSync(packageJsonPath, { encoding: 'utf-8' }); |
| 52 | + if (packageJson) { |
| 53 | + packageJson = parseJson(packageJson); |
| 54 | + // we don't need module or type properties at the moment |
| 55 | + delete packageJson['module']; |
| 56 | + delete packageJson['type']; |
| 57 | + fs.writeFileSync(packageJsonPath, serializeJson(packageJson)); |
| 58 | + |
| 59 | + const angularNpmIgnorePath = path.resolve(rootDir, 'dist', 'packages', packageName, 'angular', '.npmignore'); |
| 60 | + // remove .npmignore as we don't need it in angular folder if found |
| 61 | + if (fs.existsSync(angularNpmIgnorePath)) { |
| 62 | + fs.unlinkSync(angularNpmIgnorePath); |
| 63 | + } |
| 64 | + } |
| 65 | +} |
| 66 | + |
47 | 67 | function finishPreparation() {
|
48 | 68 | fs.copy(path.join('tools', 'assets', 'publishing'), path.join('dist', 'packages', packageName))
|
49 |
| - .then(() => console.log(`${npmPackageName} ready to publish.`)) |
| 69 | + .then(() => { |
| 70 | + cleanPackage(); |
| 71 | + console.log(`${npmPackageName} ready to publish.`); |
| 72 | + }) |
50 | 73 | .catch((err) => console.error(err));
|
51 | 74 | }
|
52 | 75 |
|
|
0 commit comments