-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/logic function get #696
Conversation
d0f20e4
to
af7e3d4
Compare
fa201f4
to
1312a53
Compare
76600b8
to
b67f13d
Compare
src/cmd/logic-function.js
Outdated
// 3. Download it to files. Take care of formatting | ||
const api = createAPI(); | ||
({ name, id } = await this._getLogicFunctionIdAndName(org, name, id)); | ||
const slugName = name.toLowerCase().replace(/\s/g, '-'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's change it with slugify
from utils
src/cmd/logic-function.test.js
Outdated
|
||
await logicFunctionCommands.get({ name: 'LF1' }); | ||
|
||
expect(fs.existsSync(path.join(process.cwd(), 'LF1', 'LF1.js'))).to.be.true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure that's making linux tests fail.
I'd rather use fixtures/__root__/...
folder for creation. Let's try to repro the test error in a linux machine.
the only thing that came to my mind now is lf1
dir and files should be in lower case since we're converting the name with slugify
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah that's a good point - that these might be in lower case!
src/cmd/logic-function.test.js
Outdated
}); | ||
|
||
describe('get', async () => { | ||
beforeEach(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use afterEach
to return everything to normal after your test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say let's merge it since we agree to change the dir creation in other story as well the list
function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keerthy and I reviewed this PR over Zoom. Keerthy has some notes on things to improve.
@hugomontero @monkbroc I made the improvements we discussed yday. Hugo, I modified the helpers a bit, but didn't make many changes to the Please let me know if I am missing something. Hope the functionality is clearer now when reading the code. |
choices : list, | ||
nonInteractiveError: 'Provide name for the logic function' | ||
}); | ||
return answer.logic_function; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@monkbroc I know we discussed to return name and id here. I didn't make that change to keep the _getLogicFunctionIdAndName
look consistent in the way it calls the _getXFromY
methods - Kindly let me know if this should have been different.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Retest the get and create functions after the latest changes and once they work, go ahead and merge
src/cmd/logic-function.js
Outdated
_printListHelperOutput() { | ||
this.ui.stdout.write(`No Logic Functions currently deployed in your ${getOrgName(this.org)}.${os.EOL}`); | ||
this.ui.stdout.write(`${os.EOL}`); | ||
this.ui.stdout.write('To create a Logic Function, see ' + this.ui.chalk.yellow('\'particle logic-function create\'.') + `${os.EOL}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest you don't include the quote for commands inside of chalk.yellow. It makes it harder to copy paste. Also make sure the period at the end of the line is not in yellow.
this.ui.stdout.write('To create a Logic Function, see ' + this.ui.chalk.yellow('\'particle logic-function create\'.') + `${os.EOL}`); | |
this.ui.stdout.write(`To create a Logic Function, see ${this.ui.chalk.yellow('particle logic-function create')}.${os.EOL}`); |
src/cmd/logic-function.js
Outdated
this.ui.stdout.write(` - ID: ${item.id}${os.EOL}`); | ||
this.ui.stdout.write(` - ${item.logic_triggers[0].type} based trigger ${os.EOL}`); | ||
}); | ||
this.ui.stdout.write(`${os.EOL}To view a Logic Function's code, see \`particle logic-function get.\`${os.EOL}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Format the command in yellow
src/cmd/logic-function.js
Outdated
|
||
const { dirPath, jsonPath, jsPath } = await this._generateFiles({ logicFunctionConfigData, logicFunctionCode, name }); | ||
|
||
this._printGetFilesOutput({ dirPath, jsonPath, jsPath }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get this._printGetFilesOutput is not a function
when I call particle logic-function get
src/cmd/logic-function.js
Outdated
existingLogicFunction = existingLogicFunctions.find((item) => item.name === name); | ||
} catch (error) { | ||
const logicFuncNameExists = this.logicFuncList.find((item) => item.name === name); | ||
if (!logicFuncNameExists) { | ||
this.ui.stdout.write(this.ui.chalk.yellow(`Warn: We were unable to check if a Logic Function with name ${name} already exists.${os.EOL}`)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get this message when I create a LF
? What would you like to call your Function? local test
? Please provide a short description of your Function:
Creating Logic Function local test for Sandbox...
Warn: We were unable to check if a Logic Function with name local test already exists.
Successfully created local test in .
Files created:
- local-test/@types/particle_core.d.ts
- local-test/@types/particle_encoding.d.ts
- local-test/local-test.js
- local-test/local-test.logic.json
Guidelines for creating your Logic Function can be found <TBD>.
Once you have written your Logic Function, run
- 'particle logic-function execute' to run your Function
- 'particle logic-function deploy' to deploy your new changes
src/cmd/logic-function.js
Outdated
} | ||
|
||
_printGetOutput({ dirPath, jsonPath, jsPath }) { | ||
if (dirPath || jsonPath || jsPath) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this if
for?
src/cmd/logic-function.js
Outdated
} | ||
|
||
_printListOutput({ logicFunctionsList }) { | ||
this.ui.stdout.write(`Logic Functions currently deployed in your ${getOrgName(this.org)}:${os.EOL}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General comment for another PR: make getOrgName
return "your Sandbox" or the name of the org so that the messages print like this:
Logic Functions currently deployed in your Sandbox
Logic Functions currently deployed in Particle
instead of currently which would show
Logic Functions currently deployed in your Particle
Description
This PR points to the execute command PR .
This PR does the following:
get
command which downloads a logic function. The logic function can be specified using the--name
or--id
parameter on the CLI. Or it can be selected from the list of available logic functionslist
to get thename
andid
mapping to obtain one from the otherdisplay
to thelist
method which controls whether to return the list for other helper methods or display it to the UI for the usercreate
command if there are spaces (This will change as the specs change)help
(compare with the other PR)How to Test
npm start -- logic-function get
and tinker with it using options--name
,--id
,--org
Related Issues / Discussions
Completeness