The path.extname() method returns the extension of the path, from the last occurrence of the . (period) character to end of string in the last portion of the path. If there is no . in the last portion of the path, or if there are no . characters other than the first character of the basename of path (see path.basename()) , an empty string is returned.
Depending on the tailwindConfigExtension and config.tailwind.cssVariables, tailwindConfigTemplate is set to a value using templates. Templates is imported from utils/templates and contains some variables initialised with values related to tailwind config
// Use the "interpolate" delimiter to create a compiled template.var compiled = _.template('hello <%= user %>!');compiled({ 'user': 'fred' });// => 'hello fred!'
This explains why there is %extension% in utils/templates.ts
After checking the directories exist (explained in the part 2.11), there are few more operations performed before writing tailwind config as shown in the below code.
extension — This extension is used in later parts of code that deal with writing cn file.
tailwindConfigExtension — The path.extname() method returns the extension of the path, from the last occurrence of the . (period) character to end of string in the last portion of the path.
Depending on the tailwindConfigExtension and config.tailwind.cssVariables, tailwindConfigTemplate is set to a value using templates. Templates is imported from utils/templates and contains some variables initialised with values related to tailwind config
Write to tailwind config file — using fs.writeFile, tailwindConfig is updated but there is a catch. template from lodash.template is used to perform some replacements before writing to the file.
An example usage of lodash.template from the docs:
// Use the "interpolate" delimiter to create a compiled template.var compiled = _.template('hello <%= user %>!');compiled({ 'user': 'fred' });// => 'hello fred!'
Want to learn how to build shadcn-ui/ui from scratch? Check outbuild-from-scratch
Hey, my name is Ramu Narasinga. I study large open-source projects and create content about their codebase architecture and best practices, sharing it through articles, videos.