Skip to content

Commit

Permalink
feat: staticresource create command (#235) (#238)
Browse files Browse the repository at this point in the history
@W-8044464@
Co-authored-by: Nathan Totten <ntotten@salesforce.com>
Co-authored-by: lcampos <lcamposguajardo@gmail.com>
  • Loading branch information
Bryan Powell authored Nov 11, 2020
1 parent f253be1 commit 8006edb
Show file tree
Hide file tree
Showing 5 changed files with 345 additions and 8 deletions.
11 changes: 11 additions & 0 deletions packages/plugin-templates/command-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@
"label"
]
},
{
"command": "force:staticresource:create",
"flags": [
"json",
"loglevel",
"outputdir",
"contenttype",
"apiversion",
"resourcename"
]
},
{
"command": "help",
"flags": [
Expand Down
15 changes: 7 additions & 8 deletions packages/plugin-templates/messages/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"Test": "test",
"Component": "component",
"Page": "page",

"ApexClassDescription": "create an Apex class",
"ApexClassLongDescription": "Creates an Apex class in the specified directory or the current working directory. If you don’t explicitly set the API version, it defaults to the current API version. The .cls file and associated metadata file are created.",
"ApexClassNameFlagDescription": "name of the generated Apex class",
Expand All @@ -27,7 +26,6 @@
"ApexTriggerNameFlagLongDescription": "The name of the new Apex trigger. The name can be up to 40 characters and must start with a letter.",
"ApexTriggerSObjectFlagDescription": "sObject to create a trigger on",
"ApexTriggerSObjectFlagLongDescription": "The sObject to create an Apex trigger on.",

"LightningDescription": "create a Lightning %s",
"LightningLongDescription": "Creates a Lightning %s bundle in the specified directory or the current working directory. The bundle consists of multiple files in a folder with the designated name.",
"LightningNameFlagDescription": "name of the generated Lightning %s",
Expand All @@ -41,7 +39,6 @@
"LightningTestDescription": "create a Lightning test",
"LightningTestLongDescription": "Creates a Lightning test in the specified directory or the current working directory. The .resource file and associated metadata file are created.",
"LightningTestNameFlagLongDescription": "The name of the new Lightning test. The name can be up to 40 characters and must start with a letter.",

"ProjectDescription": "create a Salesforce DX project",
"ProjectLongDescription": "Creates a Salesforce DX project in the specified directory or the current working directory. The command creates the necessary configuration files and folders.",
"ProjectNameFlagDescription": "name of the generated project",
Expand All @@ -56,14 +53,12 @@
"ProjectManifestFlagLongDescription": "Generates a default manifest (package.xml) for fetching Apex, Visualforce, Lightning components, and static resources.",
"ProjectLoginUrlDescription": "Salesforce instance login URL",
"ProjectLoginUrlLongDescription": "The login URL for the Salesforce instance being used. Normally defaults to https://login.salesforce.com.",

"VFDescription": "create a Visualforce %s",
"VFLongDescription": "Creates a Visualforce %s in the specified directory or the current working directory. The command creates the .%s file and associated metadata file.",
"VFNameFlagDescription": "name of the generated Visualforce %s",
"VFNameFlagLongDescription": "The Visualforce %s name. The name can be up to 40 characters and must start with a letter.",
"VFLabelFlagDescription": "Visualforce %s label",
"VFLabelFlagLongDescription": "The label saved in the metadata for the Visualforce %s.",

"MissingClassnameFlag": "Missing required flag:\n -n, --classname CLASSNAME name of the generated Apex class\nSee more help with --help\n",
"MissingTriggernameFlag": "Missing required flag:\n -n, --triggername TRIGGERNAME name of the generated Apex trigger\nSee more help with --help\n",
"MissingAuraFolder": "Lightning bundles must have a parent folder named 'aura'.",
Expand All @@ -76,12 +71,16 @@
"MissingComponentnameFlag": "Missing required flag:\n -n, --componentname COMPONENTNAME name of the generated Visualforce component\nSee more help with --help\n",
"MissingPagenameFlag": "Missing required flag:\n -n, --pagename PAGENAME name of the generated Visualforce page\nSee more help with --help\n",
"MissingTestName": "Missing required flag:\n -n, --testname TESTNAME name of the generated Lightning test\nSee more help with --help\n",

"InvalidTemplate": "Expected --template=foo to be one of:",
"StandardReadMe": "Now that you’ve created a Salesforce DX project, what’s next?",

"AnalyticsTemplateDescription": "add an Analytics template to your workspace",
"AnalyticsTemplateLongDescription": "Creates a simple Analytics template in the specified directory. If you don’t explicitly set the API version, it defaults to the current API version. The associated metadata files are created.",
"AnalyticsTemplateNameFlagDescription": "name of the Analytics template",
"AnalyticsTemplateNameFlagLongDescription": "The name of the Analytics template."
"AnalyticsTemplateNameFlagLongDescription": "The name of the Analytics template.",
"StaticResourceDescription": "create a static resource",
"StaticResourceLongDescription": "Creates a static resource in the specified directory or the current working directory. The resource folder and associated metadata file are created.",
"StaticResourceNameFlagDescription": "name of the generated static resource",
"StaticResourceNameFlagLongDescription": "The name of the new static resource. This name can contain only underscores and alphanumeric characters, and must be unique in your org. It must begin with a letter, not include spaces, not end with an underscore, and not contain two consecutive underscores.",
"StaticResourceContentTypeFlagDescription": "content type (mime type) of the generated static resource",
"StaticResourceContentTypeFlagLongDescription": "The content type of the generated static resource. This must be a valid MIME type such as application/json, application/javascript, application/zip, text/plain, text/css, etc."
}
4 changes: 4 additions & 0 deletions packages/plugin-templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@
"visualforce": {
"external": true,
"subtopics": {}
},
"staticresource": {
"external": true,
"subtopics": {}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* 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 { flags } from '@salesforce/command';
import StaticResourceGenerator from '@salesforce/templates/lib/generators/staticResourceGenerator';
import { AnyJson } from '@salesforce/ts-types';
import { MessageUtil, TemplateCommand } from '../../../utils';

export default class StaticResource extends TemplateCommand {
public static description = MessageUtil.buildDescription(
'StaticResourceDescription',
false
);
public static examples = [
'$ sfdx force:staticresource:create -n MyResource',
'$ sfdx force:staticresource:create -n MyResource --contenttype application/json',
'$ sfdx force:staticresource:create -n MyResource -d staticresources'
];
public static help = MessageUtil.buildHelpText(
StaticResource.examples,
false
);
public static longDescription = MessageUtil.get(
'StaticResourceLongDescription'
);

protected static flagsConfig = {
resourcename: flags.string({
char: 'n',
description: MessageUtil.get('StaticResourceNameFlagDescription'),
longDescription: MessageUtil.get('StaticResourceNameFlagLongDescription'),
required: true
}),
contenttype: flags.string({
description: MessageUtil.get('StaticResourceContentTypeFlagDescription'),
longDescription: MessageUtil.get(
'StaticResourceContentTypeFlagLongDescription'
),
default: 'application/zip'
}),
outputdir: flags.string({
char: 'd',
description: MessageUtil.get('OutputDirFlagDescription'),
longDescription: MessageUtil.get('OutputDirFlagLongDescription'),
default: '.'
}),
apiversion: flags.builtin()
};

public async run(): Promise<AnyJson> {
return this.runGenerator(StaticResourceGenerator);
}
}
Loading

0 comments on commit 8006edb

Please sign in to comment.