That said, there is no safety net to protect you from yourself. Once you verify that the source code for each Hook is safe, you can manually re-enable them by checking the box pictured. When this happens, you'll see an alert and the app will automatically disable the new/changed Hooks. CodeKit automatically detects when a Hook's source code has changed since you last saw it. Are you about to delete your Documents folder next time you save? Your co-worker commits his changes, you pull, and CodeKit syncs the project. Imagine that you have a shared CodeKit project and an evil co-worker adds this Hook: rm -rf ~/Documents. Additionally, your script must be able to run under the privileges of the current user- sudo is prohibited. That is, your script cannot have prompts that require human input. Note: You can also use CodeKit's Scripting API to log something at any time. If your Hook exits with code 0, CodeKit will log whatever it writes to StdOut. If your Hook exits with a non-zero code, the entry will be marked as an error and CodeKit will log whatever your Hook writes to StdErr. Hook output appears in CodeKit's log entry for the affected file, just like output from CodeKit's built-in processing steps. $CK_PROJECT_ROOT/node_modules/myModule doStuff -optionA (In CodeKit 3.0.5 and above.)įor example, if you've installed custom NPM packages in your project and want to call one of them in a Hook, you might write: You can use the environment variable $CK_PROJECT_ROOT to get the project's root folder. (Unless you have enabled an output file for child.scss, in which case CodeKit would compile both files and run any matching Hook twice.) For example, if parent.scss imports child.scss and you save child.scss in your editor, CodeKit will compile parent.scss and that's the path you'll find in the environment variables. The paths in these variables may not be those of the file that was actually saved. In this Hook, handlebars is called to compile the changed file at $CK_INPUT_PATH and it's told to write the output to $CK_OUTPUT_PATH. The screenshot above shows these variables in action. $CK_OUTPUT_PATH will be the full output path, as specified in CodeKit.$CK_INPUT_PATH will be the input path of the changed file.If your Hook is a Bash script, you can use two special environment variables to determine which file triggered the Hook: If your Hook targets a type of file that is not one of CodeKit's built-in languages, you should read Adding Custom Languages To CodeKit. For details, see Setting Output Paths & Actions. If the Output Action is set to Copy or Ignore, Hooks do not run. Your Hook will run only on files that have their Output Action set to Process/Compile. If your Hook targets filetypes for which CodeKit has built-in processing, your Hook always runs after CodeKit's built-in steps complete. Drag Hooks up or down in Project Settings to change that order. If a file triggers more than one Hook, the Hooks are run in top-down order. Likewise, if you use the Is operator, you must provide a full, matching string. If you use Begins With, keep in mind that input and output paths start with a leading slash. RegEx is slower than other matching operators and should be used only as a last resort. Invalid RegEx will cause your Hook to fail. Wildcards are not supported in any operator other than Matches RegEx. Macintosh HD/Users/john/documents/project/scripts/file.jsĪssuming "project" is the folder you've added to CodeKit, then the "Path From Project Root" would be:Īll matching operators are case-insensitive and ignore diacritic marks ( é and e are the same.) The "Path From Disk Root" option refers to a file's full input path, starting at the root of your drive: Use the Rule Editor to tell CodeKit which files should trigger this Hook. Customize the name, choose the type of script your Hook will run (AppleScript or Bash), then define the rules for file-matching. Open the Project Settings area, then choose the Hooks category:Ĭlick the button to add a Hook. Your command becomes another processing step for files of that type. You provide a custom command in either Bash or AppleScript, then tell CodeKit which files should trigger that command. Hooks let you extend CodeKit to handle any kind of file.
0 Comments
Leave a Reply. |