Skip to content
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

Merged

Conversation

hugomontero
Copy link
Contributor

@hugomontero hugomontero commented Nov 23, 2023

Description

This PR will add logic create function, that will generate a list of files with all necessary things for logic functions development

How to Test

  1. Pull down the branch: git pull && git checkout feature/sc-123395/implement-create-command
  2. Install dependencies: npm i
  3. Run unit tests: npm run test:unit
  4. Attempt to create a new logic function: npm start -- logic-function create ${path}

Outcome

  • Tests should pass
  • On creating logic function it will prompt you to put a name and description
  • A dir will be created with your slugged logic function name
  • Files with be created:
    • @types/
    • ${slug-logic-function-name}.js
    • ${slug-logic-function-name}.logic.json
  • UI will match with PRD document 👉 here

Related Issues / Discussions

Story details: https://app.shortcut.com/particle/story/123396/implement-execute-command-with-eventdata

Completeness

  • User is totes amazing for contributing!
  • Contributor has signed CLA
  • Problem and solution clearly stated
  • Tests have been provided
  • Docs have been updated
  • CI is passing

@hugomontero hugomontero force-pushed the feature/sc-123395/implement-create-command branch 2 times, most recently from b7aa50c to 1e74fb4 Compare November 23, 2023 23:08
@hugomontero hugomontero force-pushed the feature/sc-123395/implement-create-command branch from 1e74fb4 to 0ba07aa Compare November 23, 2023 23:13
@hugomontero hugomontero changed the title Feature/sc 123395/implement create command feature/sc-123395/implement-create-command Nov 24, 2023
}

/** Recursively copy and replace template files */
async _copyAndReplaceLogicFunction({ logicFunctionName, logicFunctionSlugName, description, templatePath, destinationPath }){
Copy link
Contributor Author

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

@hugomontero hugomontero marked this pull request as ready for review December 4, 2023 16:01
// TODO (hmontero): request for a getLogicFunctionByName() method in the API
let existingLogicFunction;
try {
const logicFunctionsResponse = await api.getLogicFunctionList({ org });
Copy link
Contributor

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

};
const result = await this.ui.prompt([question]);
const description = result.description;
const slugName = name.toLowerCase().replace(/\s/g, '-');
Copy link
Member

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;
	},

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done here! 👉 348a583

Copy link
Member

@monkbroc monkbroc left a 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.

@hugomontero hugomontero merged commit f02a17e into feature/logic-function Dec 5, 2023
6 checks passed
@hugomontero hugomontero deleted the feature/sc-123395/implement-create-command branch December 5, 2023 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants