-
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/sc-123395/implement-create-command #691
feature/sc-123395/implement-create-command #691
Conversation
b7aa50c
to
1e74fb4
Compare
1e74fb4
to
0ba07aa
Compare
} | ||
|
||
/** Recursively copy and replace template files */ | ||
async _copyAndReplaceLogicFunction({ logicFunctionName, logicFunctionSlugName, description, templatePath, destinationPath }){ |
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.
This can be refactored. I'll do that in further branches
// TODO (hmontero): request for a getLogicFunctionByName() method in the API | ||
let existingLogicFunction; | ||
try { | ||
const logicFunctionsResponse = await api.getLogicFunctionList({ org }); |
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.
IMO, This can directly use the list
method from this class.
Until we may have an API to get the name and id separately, I added this internal function to fetch the full list of the logic functions, and obtain the name
if id
is given and vice versa. @hugomontero raised a concern about downloading a potentially large list of logic functions and how that could impact the behavior or performance.
I made the above changes in the future branch: https://github.com/particle-iot/particle-cli/tree/feature/logic-function-get
src/cmd/logic-function.js
Outdated
}; | ||
const result = await this.ui.prompt([question]); | ||
const description = result.description; | ||
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.
This is the slugify function from api-service. Can you use that? Copy it to a helper
/**
* Converts a string to the slug version by replacing
* spaces and underscores with dashes, changing
* to lowercase, and removing anything other than
* numbers, letters, and dashes
* @param {String} str string to slugify
* @return {String} slugified version of str
*/
slugify(str) {
const slug = str.trim().toLowerCase()
// replace every group of spaces and underscores with a single hyphen
.replace(/[ _]+/g, '-')
// delete everything other than letters, numbers and hyphens
.replace(/[^a-z0-9-]/g, '');
return slug;
},
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.
Done here! 👉 348a583
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 move ahead with these commands and review the behavior after all this functionality is. Changes will be done as another story.
Description
This PR will add logic create function, that will generate a list of files with all necessary things for
logic functions
developmentHow to Test
git pull && git checkout feature/sc-123395/implement-create-command
npm i
npm run test:unit
logic function
:npm start -- logic-function create ${path}
Outcome
Related Issues / Discussions
Story details: https://app.shortcut.com/particle/story/123396/implement-execute-command-with-eventdata
Completeness