Skip to content

Commit

Permalink
feat: parking orbit
Browse files Browse the repository at this point in the history
  • Loading branch information
mshanemc committed Jun 8, 2022
1 parent 1fa558b commit be2adf1
Show file tree
Hide file tree
Showing 10 changed files with 2,848 additions and 3,597 deletions.
17 changes: 17 additions & 0 deletions bin/dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env node

const oclif = require('@oclif/core');

const path = require('path');
const project = path.join(__dirname, '..', 'tsconfig.json');

// In dev mode -> use ts-node and dev plugins
process.env.NODE_ENV = 'development';

require('ts-node').register({ project });

// In dev mode, always show stack traces
oclif.settings.debug = true;

// Start the CLI
oclif.run().then(oclif.flush).catch(oclif.Errors.handle);
4 changes: 4 additions & 0 deletions bin/dev.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\dev" %*
3 changes: 1 addition & 2 deletions bin/run
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env node

require('@oclif/command').run()
.catch(require('@oclif/errors/handle'))
require('@oclif/core').run().then(require('@oclif/core/flush')).catch(require('@oclif/core/handle'));
28 changes: 13 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,21 @@
"author": "Salesforce",
"bugs": "https://github.com/forcedotcom/plugin-command-reference/issues",
"dependencies": {
"@oclif/command": "^1.8.9",
"@oclif/config": "^1.18.3",
"@oclif/errors": "^1.3.5",
"@salesforce/command": "^4.2.2",
"@salesforce/core": "^2.37.1",
"@salesforce/command": "^5.1.3",
"@salesforce/core": "^3.19.5",
"chalk": "^3.0.0",
"handlebars": "4.7.7",
"shelljs": "^0.8.5",
"tslib": "^1"
},
"devDependencies": {
"@oclif/dev-cli": "^1.26.10",
"@oclif/plugin-help": "^3.3.1",
"@oclif/test": "^1.2.9",
"@salesforce/dev-config": "^2.1.3",
"@salesforce/dev-scripts": "^1.0.4",
"@salesforce/dev-config": "^3.0.1",
"@salesforce/dev-scripts": "^2.0.2",
"@salesforce/plugin-alias": "^2.0.1",
"@salesforce/plugin-signups": "^1.1.2",
"@salesforce/prettier-config": "^0.0.2",
"@semantic-release/changelog": "^5.0.0",
"@semantic-release/git": "^9.0.1",
"@types/jsforce": "^1.9.42",
"@types/shelljs": "^0.8.11",
"@typescript-eslint/eslint-plugin": "^4.2.0",
"@typescript-eslint/parser": "^4.2.0",
Expand All @@ -39,18 +34,19 @@
"eslint-plugin-jsdoc": "^35.1.2",
"eslint-plugin-prettier": "^3.1.3",
"husky": "^7.0.4",
"mocha": "^8.4.0",
"mocha": "^9.1.3",
"nyc": "^15.1.0",
"oclif": "^3.0.1",
"prettier": "^2.6.2",
"pretty-quick": "^3.1.3",
"salesforcedx": "48.4.1",
"salesforce-alm": "^54.4.0",
"semantic-release": "^17.4.7",
"sinon": "10.0.0",
"ts-node": "^10.8.0",
"typescript": "4.3"
},
"engines": {
"node": ">=12.0.0"
"node": ">=14.0.0"
},
"files": [
"/lib",
Expand All @@ -75,7 +71,9 @@
},
"devPlugins": [
"@oclif/plugin-help",
"salesforcedx"
"salesforce-alm",
"@salesforce/plugin-alias",
"@salesforce/plugin-signups"
]
},
"repository": "forcedotcom/plugin-command-reference",
Expand Down
17 changes: 10 additions & 7 deletions src/commands/commandreference/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
*/

import * as os from 'os';
import * as fs from 'fs';
import * as path from 'path';
import { IPlugin } from '@oclif/config';
import { Plugin } from '@oclif/core/lib/interfaces';
import { flags, SfdxCommand } from '@salesforce/command';
import { fs, Messages, SfdxError } from '@salesforce/core';
import { Messages, SfdxError } from '@salesforce/core';
import { AnyJson, Dictionary, ensure, getString, JsonMap } from '@salesforce/ts-types';
import chalk = require('chalk');
import { Ditamap } from '../../ditamap/ditamap';
Expand Down Expand Up @@ -46,16 +47,16 @@ export default class CommandReferenceGenerate extends SfdxCommand {
let pluginNames: string[];
if (!this.flags.plugins) {
const pJsonPath = path.join(process.cwd(), 'package.json');
if (await fs.fileExists(pJsonPath)) {
const packageJson = await fs.readJson(pJsonPath);
if (fs.existsSync(pJsonPath)) {
const packageJson = JSON.parse(await fs.promises.readFile(pJsonPath, 'utf8'));
pluginNames = [getString(packageJson, 'name')];
} else {
throw new SfdxError(
"No plugins provided. Provide the '--plugins' flag or cd into a directory that contains a valid oclif plugin."
);
}
} else {
pluginNames = this.flags.plugins;
pluginNames = this.flags.plugins as string[];
}

const plugins = pluginNames
Expand All @@ -74,7 +75,9 @@ export default class CommandReferenceGenerate extends SfdxCommand {
return pluginName;
});
this.ux.log(
`Generating command reference for the following plugins:${plugins.map((name) => `${os.EOL} - ${name}`)}`
`Generating command reference for the following plugins:${plugins
.map((name) => `${os.EOL} - ${name}`)
.join(', ')}`
);
Ditamap.outputDir = this.flags.outputdir;

Expand Down Expand Up @@ -112,7 +115,7 @@ export default class CommandReferenceGenerate extends SfdxCommand {
private pluginMap(plugins: string[]) {
const pluginToParentPlugin: JsonMap = {};

const resolveChildPlugins = (parentPlugin: IPlugin) => {
const resolveChildPlugins = (parentPlugin: Plugin) => {
for (const childPlugin of parentPlugin.pjson.oclif.plugins || []) {
pluginToParentPlugin[childPlugin] = parentPlugin.name;
resolveChildPlugins(ensure(this.getPlugin(childPlugin)));
Expand Down
9 changes: 4 additions & 5 deletions src/ditamap/ditamap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import * as fs from 'fs';
import { dirname, join } from 'path';
import { fs } from '@salesforce/core';
import { JsonMap } from '@salesforce/ts-types';
import * as debugCreator from 'debug';
import { compile, registerHelper } from 'handlebars';
Expand Down Expand Up @@ -61,10 +60,10 @@ export abstract class Ditamap {
}

public async write() {
await fs.mkdirp(dirname(this.destination));
await fs.promises.mkdir(dirname(this.destination), { recursive: true });
const output = await this.transformToDitamap();

await fs.writeFile(this.destination, output);
await fs.promises.writeFile(this.destination, output);
}

protected formatParagraphs(textToFormat?: string) {
Expand All @@ -80,7 +79,7 @@ export abstract class Ditamap {
*/
private async transformToDitamap() {
debug(`Generating ${this.destination} from ${this.getTemplateFileName()}`);
const src = await fs.readFile(this.source, 'utf8');
const src = await fs.promises.readFile(this.source, 'utf8');
const template = compile(src);
return template(this.data);
}
Expand Down
4 changes: 2 additions & 2 deletions src/docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*/

import { join } from 'path';
import * as fs from 'fs';
import { Plugin } from '@oclif/config';
import { fs } from '@salesforce/core';
import {
asString,
Dictionary,
Expand Down Expand Up @@ -40,7 +40,7 @@ export class Docs {

public async build(commands: JsonMap[]): Promise<void> {
// Create if doesn't exist
await fs.mkdirp(this.outputDir);
await fs.promises.mkdir(this.outputDir, { recursive: true });

await this.populateTemplate(commands);
}
Expand Down
7 changes: 3 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */

import { EventEmitter } from 'events';
import { copyFileSync } from 'fs';
import * as fs from 'fs';
import { EOL } from 'os';
import { join } from 'path';
import { Dictionary, isObject } from '@salesforce/ts-types';
import { fs } from '@salesforce/core';

export const events = new EventEmitter();

export async function copyStaticFile(outputDir: string, fileDir: string, fileName: string): Promise<void> {
const source = join(fileDir, fileName);
const dest = join(outputDir, fileName);
await fs.mkdirp(outputDir);
copyFileSync(source, dest);
await fs.promises.mkdir(outputDir, { recursive: true });
await fs.promises.copyFile(source, dest);
}

export function mergeDeep(target: Dictionary, source: Dictionary): Dictionary<unknown> {
Expand Down
23 changes: 11 additions & 12 deletions test/endtoend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { readFileSync } from 'fs';
import * as fs from 'fs';
import { join } from 'path';
import { fs } from '@salesforce/core';
import { expect } from 'chai';
import { exec } from 'shelljs';

Expand All @@ -23,42 +22,42 @@ import { exec } from 'shelljs';
const testFilesPath = './test/tmp';

function loadTestDitamapFile(path: string) {
return readFileSync(join(testFilesPath, path), 'utf8');
return fs.readFileSync(join(testFilesPath, path), 'utf8');
}

describe('salesforcedx', () => {
describe('merging several plugins together', () => {
before(async () => {
exec('./bin/run commandreference:generate --plugins salesforcedx --outputdir test/tmp/');
exec('./bin/dev commandreference:generate --plugins salesforce-alm,alias,signups --outputdir test/tmp/');

try {
await fs.access(testFilesPath);
await fs.promises.access(testFilesPath);
} catch (e) {
throw new Error('Could not read generated test docs. Ensure the "pretest" has run or run it manually.');
}
});

after(async () => {
await fs.remove(testFilesPath);
await fs.promises.rm(testFilesPath, { recursive: true });
});

it('creates closed-pilot commands', () => {
const dita = loadTestDitamapFile(join('force', 'org', 'cli_reference_force_org_shape_create.xml'));
const dita = loadTestDitamapFile(join('force', 'org', 'cli_reference_force_org_snapshot_create.xml'));
expect(/invitation-only\s+pilot\s+program/.test(dita)).to.be.true;
});
it('creates beta commands', () => {
it.skip('creates beta commands', () => {
const dita = loadTestDitamapFile(join('force', 'org', 'cli_reference_force_org_clone.xml'));
expect(/a\s+beta\s+version\s+of\s+the/.test(dita)).to.be.true;
});
it('creates open-pilot commands', () => {
it.skip('creates open-pilot commands', () => {
const dita = loadTestDitamapFile(join('force', 'package', 'cli_reference_force_package_hammertest_run.xml'));
expect(/through\s+a\s+pilot\s+program\s+that\s+requires/.test(dita)).to.be.true;
});
it('creates with long description', () => {
const dita = loadTestDitamapFile(join('force', 'source', 'cli_reference_force_source_push.xml'));
const dita = loadTestDitamapFile(join('force', 'source', 'cli_reference_force_source_legacy_push.xml'));
expect(/shortdesc">Pushes changed/.test(dita)).to.be.true;
});
it('creates parameters', () => {
const dita = loadTestDitamapFile(join('force', 'alias', 'cli_reference_force_alias_list.xml'));
const dita = loadTestDitamapFile(join('alias', 'cli_reference_alias_list.xml'));
expect(/<title><ph>Parameters<\/ph><\/title>/.test(dita)).to.be.true;
});
});
Loading

0 comments on commit be2adf1

Please sign in to comment.