@@ -4,65 +4,46 @@ const { execSync } = require('child_process');
44const fs = require ( 'fs' ) ;
55const path = require ( 'path' ) ;
66
7+ // Import the products configuration
8+ const { PRODUCTS , generatePluginId, generateDocPath, generateRouteBasePath } = require ( '../src/config/products.js' ) ;
9+
710// Parse command line arguments
811const args = process . argv . slice ( 2 ) ;
912if ( args . length === 0 ) {
10- console . error ( 'Usage: npm run start <productname> or npm run start <productname>/<version>' ) ;
13+ console . error ( 'Usage: npm run build:single <productname> or npm run build:single <productname>/<version>' ) ;
1114 process . exit ( 1 ) ;
1215}
1316
1417const input = args [ 0 ] ;
1518const [ productName , version ] = input . includes ( '/' ) ? input . split ( '/' ) : [ input , null ] ;
1619
17- // Products that don't have versions (use product name directly)
18- const versionlessProducts = [
19- '1secure' ,
20- 'endpointpolicymanager' ,
21- 'pingcastle' ,
22- 'platgovnetsuite' ,
23- 'platgovsalesforce' ,
24- 'platgovnetsuiteflashlight' ,
25- 'platgovsalesforceflashlight' ,
26- ] ;
27-
28- // Special case for identitymanager/saas
29- const specialCases = {
30- 'identitymanager/saas' : 'identitymanager_saas' ,
31- } ;
32-
3320// Function to get plugin ID based on product and version
3421function getPluginId ( product , version ) {
35- // Handle special cases first
36- const specialKey = version ? `${ product } /${ version } ` : product ;
37- if ( specialCases [ specialKey ] ) {
38- return specialCases [ specialKey ] ;
39- }
40-
41- // Handle versionless products
42- if ( versionlessProducts . includes ( product ) && ! version ) {
43- return product ;
22+ const productConfig = PRODUCTS . find ( ( p ) => p . id === product ) ;
23+ if ( ! productConfig ) {
24+ return null ;
4425 }
4526
46- // Handle versioned products
47- if ( version ) {
48- // Convert version dots to underscores (e.g., "12.0" -> "12_0")
49- const versionFormatted = version . replace ( / \. / g, '_' ) ;
50- return `${ product } ${ versionFormatted } ` ;
27+ // If no version provided, use the default version
28+ let targetVersion = version ;
29+ if ( ! targetVersion ) {
30+ // For products with only 'current' version, use 'current'
31+ if ( productConfig . versions . length === 1 && productConfig . versions [ 0 ] . version === 'current' ) {
32+ targetVersion = 'current' ;
33+ } else if ( productConfig . defaultVersion ) {
34+ targetVersion = productConfig . defaultVersion ;
35+ } else {
36+ // Find the latest version
37+ const latestVersion = productConfig . versions . find ( ( v ) => v . isLatest ) ;
38+ targetVersion = latestVersion ? latestVersion . version : productConfig . versions [ 0 ] . version ;
39+ }
5140 }
5241
53- // If no version provided for a versioned product, error
54- console . error ( `Product "${ product } " requires a version number.` ) ;
55- console . error ( 'Available versions can be found in the docs directory structure.' ) ;
56- process . exit ( 1 ) ;
42+ return generatePluginId ( product , targetVersion ) ;
5743}
5844
59- // Function to check if plugin exists in docusaurus config
60- function validatePlugin ( pluginId , product , version ) {
61- // Import the products configuration to validate against actual product definitions
62- const productsPath = path . join ( __dirname , '..' , 'src' , 'config' , 'products.js' ) ;
63- const { PRODUCTS } = require ( productsPath ) ;
64-
65- // Find the product
45+ // Function to validate product and version
46+ function validatePlugin ( product , version ) {
6647 const productConfig = PRODUCTS . find ( ( p ) => p . id === product ) ;
6748 if ( ! productConfig ) {
6849 console . error ( `Product "${ product } " not found in products configuration.` ) ;
@@ -78,52 +59,35 @@ function validatePlugin(pluginId, product, version) {
7859 console . error ( `Available versions: ${ productConfig . versions . map ( ( v ) => v . version ) . join ( ', ' ) } ` ) ;
7960 process . exit ( 1 ) ;
8061 }
81- } else if ( ! versionlessProducts . includes ( product ) ) {
82- // If no version provided for a versioned product, error
83- console . error ( `Product "${ product } " requires a version number.` ) ;
84- console . error ( `Available versions: ${ productConfig . versions . map ( ( v ) => v . version ) . join ( ', ' ) } ` ) ;
85- process . exit ( 1 ) ;
8662 }
63+
64+ return productConfig ;
8765}
8866
8967// Create temporary config file for single product build
90- function createTempConfig ( pluginId , product , version ) {
68+ function createTempConfig ( pluginId , product , version , productConfig ) {
9169 const tempConfigPath = path . join ( __dirname , '..' , 'docusaurus.single.config.js' ) ;
9270
93- // Import the products configuration to get the correct paths
94- const productsPath = path . join ( __dirname , '..' , 'src' , 'config' , 'products.js' ) ;
95- const { PRODUCTS } = require ( productsPath ) ;
96-
97- // Find the product configuration
98- const productConfig = PRODUCTS . find ( ( p ) => p . id === product ) ;
99-
100- // Get the path and sidebar for this specific product
101- let docPath , routeBasePath , sidebarPath ;
102-
103- if ( version ) {
104- docPath = `docs/${ product } /${ version } ` ;
105- routeBasePath = '/' ; // Serve at root for single product builds
106-
107- // Find the version configuration to get the sidebar path
108- const versionConfig = productConfig . versions . find ( ( v ) => v . version === version ) ;
109- sidebarPath = versionConfig . sidebarFile ;
110- } else {
111- // Handle special cases
112- if ( pluginId === 'identitymanager_saas' ) {
113- docPath = 'docs/identitymanager/saas' ;
114- routeBasePath = '/' ; // Serve at root for single product builds
115- const versionConfig = productConfig . versions . find ( ( v ) => v . version === 'saas' ) ;
116- sidebarPath = versionConfig . sidebarFile ;
71+ // Get the version config
72+ let targetVersion = version ;
73+ if ( ! targetVersion ) {
74+ // For products with only 'current' version, use 'current'
75+ if ( productConfig . versions . length === 1 && productConfig . versions [ 0 ] . version === 'current' ) {
76+ targetVersion = 'current' ;
77+ } else if ( productConfig . defaultVersion ) {
78+ targetVersion = productConfig . defaultVersion ;
11779 } else {
118- docPath = `docs/${ product } ` ;
119- routeBasePath = '/' ; // Serve at root for single product builds
120-
121- // For versionless products, get the sidebar from the 'current' version
122- const versionConfig = productConfig . versions . find ( ( v ) => v . version === 'current' ) ;
123- sidebarPath = versionConfig . sidebarFile ;
80+ // Find the latest version
81+ const latestVersion = productConfig . versions . find ( ( v ) => v . isLatest ) ;
82+ targetVersion = latestVersion ? latestVersion . version : productConfig . versions [ 0 ] . version ;
12483 }
12584 }
12685
86+ const versionConfig = productConfig . versions . find ( ( v ) => v . version === targetVersion ) ;
87+ const docPath = generateDocPath ( productConfig . path , targetVersion ) ;
88+ const routeBasePath = '/' ; // Serve at root for single product builds
89+ const sidebarPath = versionConfig . sidebarFile ;
90+
12791 // Create minimal config with just the single plugin
12892 const configContent = `// @ts-check
12993import { themes as prismThemes } from 'prism-react-renderer';
@@ -187,7 +151,7 @@ const config = {
187151 exclude: ['**/CLAUDE.md'],
188152 versions: {
189153 current: {
190- label: '${ version || 'Current' } ',
154+ label: '${ versionConfig . label } ',
191155 },
192156 },
193157 },
@@ -254,12 +218,11 @@ function cleanup() {
254218// Main execution
255219console . log ( `Building single product: ${ productName } ${ version ? `/${ version } ` : '' } ` ) ;
256220
221+ const productConfig = validatePlugin ( productName , version ) ;
257222const pluginId = getPluginId ( productName , version ) ;
258223console . log ( `Using plugin ID: ${ pluginId } ` ) ;
259224
260- validatePlugin ( pluginId , productName , version ) ;
261-
262- const tempConfigPath = createTempConfig ( pluginId , productName , version ) ;
225+ const tempConfigPath = createTempConfig ( pluginId , productName , version , productConfig ) ;
263226
264227try {
265228 // Run docusaurus build with the temporary config
0 commit comments