Skip to content

Commit a832a7a

Browse files
committed
XWIKI-23610: Allow xwiki build to publish npm artifacts
1 parent b0fd0b8 commit a832a7a

File tree

4 files changed

+38
-25
lines changed

4 files changed

+38
-25
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
<oracle.version>21.20.0.0</oracle.version>
127127

128128
<!-- npm registries configuration -->
129-
<xwiki.npm.snapshot.registry>https://npm.snapshot.xwiki.org</xwiki.npm.snapshot.registry>
129+
<xwiki.npm.snapshot.registry>https://nexus-snapshots.xwiki.org/repository/npmhosted/</xwiki.npm.snapshot.registry>
130130
<xwiki.npm.release.registry>https://registry.npmjs.org</xwiki.npm.release.registry>
131131
</properties>
132132
<scm>

xwiki-platform-core/xwiki-platform-node/pom.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
<goal>pnpm</goal>
125125
</goals>
126126
<configuration>
127-
<arguments>run deploy</arguments>
127+
<arguments>run deploy -- ${xwiki.npm.snapshot.registry} ${xwiki.npm.release.registry} ${basedir}/src/main/node</arguments>
128128
<workingDirectory>${basedir}/src/main/node</workingDirectory>
129129
<installDirectory>${basedir}/target</installDirectory>
130130
<environmentVariables>
@@ -135,6 +135,13 @@
135135
</execution>
136136
</executions>
137137
</plugin>
138+
<plugin>
139+
<groupId>org.apache.maven.plugins</groupId>
140+
<artifactId>maven-deploy-plugin</artifactId>
141+
<configuration>
142+
<skip>true</skip>
143+
</configuration>
144+
</plugin>
138145
</plugins>
139146
</build>
140147
</project>

xwiki-platform-core/xwiki-platform-node/src/main/node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"type": "module",
55
"scripts": {
66
"build": "nx run-many -t build -p \"xwiki-platform-core/xwiki-platform-node/src/main/node/*/**\"",
7-
"deploy": "node scripts/deploy.js $NPM_SNAPSHOT_REGISTRY $NPM_RELEASE_REGISTRY",
7+
"deploy": "node scripts/deploy.js",
88
"lint": "nx run-many -t lint -p \"xwiki-platform-core/xwiki-platform-node/src/main/node/*/**\"",
99
"test:unit": "nx run-many -t test -p \"xwiki-platform-core/xwiki-platform-node/src/main/node/*/**\""
1010
},

xwiki-platform-core/xwiki-platform-node/src/main/node/scripts/deploy.js

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env node
22

3-
const fs = require('fs');
4-
const { execSync } = require('child_process');
5-
const path = require('path');
3+
import fs from 'fs';
4+
import {execSync} from 'child_process';
5+
import path from 'path';
66

77
/**
88
* Script to conditionally publish npm packages based on version type (SNAPSHOT vs release)
@@ -51,19 +51,11 @@ function findPackageJsonFiles(dir, fileList = []) {
5151
/**
5252
* Update version in a package.json file
5353
* @param {string} packageJsonPath - Path to package.json
54+
* @param {Object} packageJson - Parsed package.json content
5455
* @param {string} timestamp - Timestamp to replace SNAPSHOT with
5556
* @returns {Object} - {success, originalVersion, newVersion, packageName, isSnapshot}
5657
*/
57-
function updatePackageVersion(packageJsonPath, timestamp) {
58-
let packageJson;
59-
60-
try {
61-
packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
62-
} catch (error) {
63-
console.error(`Error reading ${packageJsonPath}: ${error.message}`);
64-
return { success: false };
65-
}
66-
58+
function updatePackageVersion(packageJsonPath, packageJson, timestamp) {
6759
const originalVersion = packageJson.version;
6860
const packageName = packageJson.name;
6961
const isSnapshot = originalVersion.includes('SNAPSHOT');
@@ -110,24 +102,40 @@ if (packageJsonFiles.length === 0) {
110102
}
111103

112104
// Generate a common timestamp for all packages.
113-
const timestamp = Math.floor(Date.now() / 1000);
105+
const timestamp = Math.floor(Date.now() / 1000).toString();
114106

115107
// Determine if we're dealing with SNAPSHOT or release versions
116108
// Check the first package.json to determine the mode
117109
let isSnapshotMode = false;
118110
try {
119-
const firstPackage = JSON.parse(fs.readFileSync(packageJsonFiles[0], 'utf8'));
120-
isSnapshotMode = firstPackage.version.includes('SNAPSHOT');
111+
// Look for the first package.json file with a version.
112+
const firstVersion = packageJsonFiles.map(packageJsonPath => JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')))
113+
.filter(packageJson => packageJson.version)
114+
.map(packageJson => packageJson.version)[0];
115+
isSnapshotMode = firstVersion.includes('SNAPSHOT');
121116
} catch (error) {
122117
console.error('Error determining version mode');
123118
process.exit(1);
124119
}
125120

126-
127121
// Step 1: Update all package.json versions
128-
const updates = packageJsonFiles.map(packageJsonPath => {
129-
const result = updatePackageVersion(packageJsonPath, timestamp.toString());
130-
return { ...result, path: packageJsonPath };
122+
const updates = packageJsonFiles
123+
.map(packageJsonPath => {
124+
let packageJson;
125+
126+
try {
127+
packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
128+
} catch (error) {
129+
console.error(`Error reading ${packageJsonPath}: ${error.message}`);
130+
return {success: false};
131+
}
132+
133+
return {packageJsonPath, packageJson, success: true}
134+
})
135+
.filter(({packageJsonPath, packageJson, success}) => success && packageJson.version)
136+
.map(({packageJsonPath, packageJson}) => {
137+
const result = updatePackageVersion(packageJsonPath, packageJson, timestamp);
138+
return {...result, path: packageJsonPath};
131139
});
132140

133141
const failedUpdates = updates.filter(u => !u.success);
@@ -137,8 +145,6 @@ if (failedUpdates.length > 0) {
137145
process.exit(1);
138146
}
139147

140-
141-
142148
try {
143149
if (isSnapshotMode) {
144150
execSync(

0 commit comments

Comments
 (0)