Skip to content

Commit 56c946e

Browse files
committed
fix: use unique id
1 parent 8514515 commit 56c946e

12 files changed

+47
-31
lines changed

src/ditamap/ditamap.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ const debug = debugCreator('commandreference');
1515

1616
hb.registerHelper('toUpperCase', (str) => str.toUpperCase());
1717
hb.registerHelper('join', (array) => array.join(', '));
18+
hb.registerHelper('xmlFile', (...strings) => {
19+
const parts = strings.filter((s) => typeof s === 'string');
20+
return Ditamap.file(parts.join('_'), 'xml');
21+
});
22+
hb.registerHelper('uniqueId', (...strings) => {
23+
const parts = strings.filter((s) => typeof s === 'string');
24+
return Ditamap.file(parts.join('_'), 'xml').replace('.xml', '');
25+
});
1826

1927
/*
2028
* Returns true if the string should be formatted as code block in docs

src/ditamap/help-reference.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2018, salesforce.com, inc.
3+
* All rights reserved.
4+
* Licensed under the BSD 3-Clause license.
5+
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
8+
import { Ditamap } from './ditamap';
9+
10+
export class HelpReference extends Ditamap {
11+
public constructor() {
12+
// Set the data of topic and filenames
13+
const filename = Ditamap.file('cli_reference_help', 'xml');
14+
super(filename, {
15+
id: filename.replace('.xml', ''),
16+
});
17+
}
18+
19+
public getTemplateFileName(): string {
20+
return 'cli_reference_help.hbs';
21+
}
22+
}

src/docs.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
66
*/
77

8-
import { join } from 'path';
98
import { Plugin } from '@oclif/config';
109
import { fs } from '@salesforce/core';
1110
import {
@@ -26,9 +25,8 @@ import { Command } from './ditamap/command';
2625
import { MainTopicIntro } from './ditamap/main-topic-intro';
2726
import { TopicCommands } from './ditamap/topic-commands';
2827
import { TopicDitamap } from './ditamap/topic-ditamap';
29-
import { copyStaticFile, events, punctuate } from './utils';
30-
31-
const templatesDir = join(__dirname, '..', 'templates');
28+
import { events, punctuate } from './utils';
29+
import { HelpReference } from './ditamap/help-reference';
3230

3331
export class Docs {
3432
public constructor(
@@ -189,7 +187,7 @@ export class Docs {
189187
const topicsAndSubtopics = this.groupTopicsAndSubtopics(commands);
190188

191189
await new CLIReference().write();
192-
await copyStaticFile(this.outputDir, templatesDir, 'cli_reference_help.xml');
190+
await new HelpReference().write();
193191

194192
const topics = Object.keys(topicsAndSubtopics);
195193

src/utils.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,11 @@
66
*/
77

88
import { EventEmitter } from 'events';
9-
import { copyFileSync } from 'fs';
109
import { EOL } from 'os';
11-
import { join } from 'path';
1210
import { Dictionary, isObject } from '@salesforce/ts-types';
13-
import { fs } from '@salesforce/core';
14-
import { Ditamap } from './ditamap/ditamap';
1511

1612
export const events = new EventEmitter();
1713

18-
export async function copyStaticFile(outputDir: string, fileDir: string, fileName: string): Promise<void> {
19-
const source = join(fileDir, fileName);
20-
const [name, ext] = fileName.split('.');
21-
const dest = join(outputDir, Ditamap.file(name, ext));
22-
await fs.mkdirp(outputDir);
23-
copyFileSync(source, dest);
24-
}
25-
2614
export function mergeDeep(target: Dictionary, source: Dictionary): Dictionary {
2715
Object.keys(source).forEach((key) => {
2816
if (isObject(target[key]) && isObject(source[key])) {

templates/base_ditamap.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ IF YOU WANT TO CHANGE THIS CONTENT, CONTACT juliet.shackell@salesforce.com FOR D
1414
<shortdesc>An alphabetized list of CLI commands that you use with Salesforce DX to create
1515
and manage applications on the Lightning Platform.</shortdesc>
1616
</topicmeta>
17-
<topicref href="cli_reference.xml" type="reference" format="dita" scope="local">
17+
<topicref href="{{xmlFile 'cli_reference'}}" type="reference" format="dita" scope="local">
1818
{{#each namespaceDitamapFiles}}
1919
{{#if []}}<topicref href="{{[]}}" format="ditamap" scope="local"/>{{/if}}
2020
{{/each}}
21-
<topicref href="cli_reference_help.xml" type="concept" format="dita" scope="local"/>
21+
<topicref href="{{xmlFile 'cli_reference_help'}}" type="concept" format="dita" scope="local"/>
2222
<topicref href="../../sfdx_dev/workspace_setup/sfdx_dev_cli_deprecation.xml" type="concept"
2323
format="dita" scope="local"/>
2424
<topicref href="../../sfdx_setup/sfdx_setup_other_plugins.xml" type="concept"

templates/cli_reference_help.xml renamed to templates/cli_reference_help.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN"
33
"concept.dtd">
4-
<concept id="cli_reference_help" xml:lang="en-us">
4+
<concept id="{{id}}" xml:lang="en-us">
55
<!--
66
77
NOTE TO WRITERS:

templates/cli_reference_topic.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN"
33
"concept.dtd">
4-
<concept id="cli_reference_{{topic}}" xml:lang="en-us">
4+
<concept id="{{uniqueId 'cli_reference' topic}}" xml:lang="en-us">
55
<!--
66
77
NOTE TO WRITERS:

templates/cli_reference_topic_commands.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN"
33
"concept.dtd">
4-
<concept id="cli_reference_{{name}}_commands" xml:lang="en-us">
4+
<concept id="{{uniqueId 'cli_reference' name 'commands'}}" xml:lang="en-us">
55
<!--
66
77
NOTE TO WRITERS:

templates/cli_reference_xml.hbs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE reference PUBLIC "-//OASIS//DTD DITA Reference//EN"
33
"reference.dtd">
4-
<reference id="cli_reference" xml:lang="en-us">
4+
<reference id="{{uniqueId 'cli_reference'}}" xml:lang="en-us">
55
<!--
66
77
NOTE TO WRITERS:
@@ -24,17 +24,17 @@ IF YOU WANT TO CHANGE THIS CONTENT, CONTACT juliet.shackell@salesforce.com FOR D
2424
</prolog>
2525
<refbody>
2626
<section>
27-
<p>This version of the command reference includes details about version
27+
<p>This version of the command reference includes details about version
2828
{{cliVersion}} of Salesforce CLI and the following plug-in versions:</p>
2929
<ul>
3030
{{#each pluginVersions}}
3131
<li><codeph otherprops="nolang">{{name}}</codeph> version {{version}}</li>
3232
{{/each}}
3333
</ul>
34-
<p>For information about installing Salesforce CLI, see the <cite><xref
35-
href="https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_install_cli.htm"
34+
<p>For information about installing Salesforce CLI, see the <cite><xref
35+
href="https://developer.salesforce.com/docs/atlas.en-us.sfdx_setup.meta/sfdx_setup/sfdx_setup_install_cli.htm"
3636
type="new-window:HTML" format="html" scope="external">Salesforce CLI Setup Guide</xref></cite>.</p>
37-
<p>For information about Salesforce CLI changes, see the <cite><xref
37+
<p>For information about Salesforce CLI changes, see the <cite><xref
3838
href="https://github.com/forcedotcom/cli/blob/main/releasenotes/README.md"
3939
type="new-window:HTML" format="html" scope="external">Salesforce CLI Release Notes</xref></cite>.</p>
4040
</section>

templates/command.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE reference PUBLIC "-//OASIS//DTD DITA Reference//EN" "reference.dtd">
3-
<reference id="cli_reference_{{commandWithUnderscores}}" xml:lang="en-us">
3+
<reference id="{{uniqueId 'cli_reference' commandWithUnderscores}}" xml:lang="en-us">
44
<!--
55
66
NOTE TO WRITERS:

templates/main_topic_intro.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
3-
<concept id="cli_reference_force_{{topic}}" xml:lang="en-us">
3+
<concept id="{{uniqueId 'cli_reference' topic}}" xml:lang="en-us">
44
<!--
55
66
NOTE TO WRITERS:

templates/topic_ditamap.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ IF YOU WANT TO CHANGE THIS CONTENT, CONTACT juliet.shackell@salesforce.com FOR D
99
1010
-->
1111
<title><codeph otherprops="nolang">{{topic}}</codeph> Namespace</title>
12-
<topicref href="cli_reference_{{topic}}_commands.xml" type="concept" format="dita" scope="local" chunk="to-content" collection-type="unordered">
12+
<topicref href="{{xmlFile 'cli_reference' topic 'commands'}}" type="concept" format="dita" scope="local" chunk="to-content" collection-type="unordered">
1313
{{#each commands}}
14-
<topicref href="cli_reference_{{command}}.xml" type="reference" format="dita" scope="local"/>
14+
<topicref href="{{xmlFile 'cli_reference' command}}" type="reference" format="dita" scope="local"/>
1515
{{/each}}
1616
</topicref>
1717
</map>

0 commit comments

Comments
 (0)