Skip to content

Commit

Permalink
update to version 3.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Trapfether committed Feb 2, 2024
1 parent 772dd62 commit c73fe6e
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 6 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Forked from [heybourn/headwind] to [Trapfether/tailwind-raw-reorder] to continue development. Old repo is inactive.
* Initial rework of the extension to use the same approach as the [Prettier Tailwind plugin]
* Updated the html and php regexes to only select class attributes proceeded by a space
* Added Sort Selection command to sort the selected classes
* Added Sort Selection command to sort the selected classes
#### 3.2.0
* Added Option to ignore tailwind config not found error (thanks to [@kyaruwo](https://github.com/kyaruwo)) in [#11]
* Added Option to change default tailwind config path
* Added Output Channel to log errors and info
* Added startup check for workspace folder. If no workspace folder is found, the extension will not activate
* Added runtime check for workspace folder based on the active file. If the active file is not in the workspace folder, the extension will not run. This is to prevent the extension from running on files outside the workspace folder
* If either of the above checks fail, the extension will log an error message to it's output channel
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ Tailwind Raw Reorder will run on save by default (if a `tailwind.config.*` file

`"tailwind-raw-reorder.runOnSave": false`

### `tailwind-raw-reorder.tailwindConfigPath`:

Tailwind Raw Reorder will look for a `tailwind.config.*` file within your working directory by default. This can be customized to look for a `tailwind.config.*` file in a different location. You can use a relative path from the workspace root or an absolute path. You will need to reload the window after changing this setting.

`"tailwind-raw-reorder.tailwindConfigPath": "path/to/tailwind.config.js"`

## Contributing

Tailwind Raw Reorder is open-source and contributions are always welcome. If you're interested in submitting a pull request, please take a moment to review [CONTRIBUTING.md](.github/CONTRIBUTING.md).
Expand Down
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"color": "#f1f5f8"
},
"icon": "tailwind-raw-reorder-icon.gif",
"version": "3.1.0",
"version": "3.2.0",
"publisher": "Trapfether",
"license": "MIT",
"author": "Andrew Trefethen <[email protected]>",
Expand Down Expand Up @@ -123,7 +123,13 @@
"default": true,
"description": "A flag that controls whether or not Tailwind Raw Reorder will sort your Tailwind CSS classes on save.",
"scope": "window"
}
},
"tailwind-raw-reorder.tailwindConfigPath": {
"type": ["string", "null"],
"default": null,
"description": "The path to your tailwind.config.js file. This is used to determine the order of your classes.",
"scope": "window"
}
}
}
]
Expand Down
39 changes: 36 additions & 3 deletions src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { getTextMatch, buildMatchers } from './utils.mjs';
import { spawn } from 'child_process';
import { rustyWindPath } from 'rustywind';
import { getTailwindConfig } from './config.mjs';
import { sortClasses } from './sorting.mjs'
import { sortClasses } from './sorting.mjs';
// import resolve from 'path' and rename it to resolvePath
import { resolve as resolvePath, isAbsolute as isPathAbsolute } from 'path';

/**
* @typedef {import('vscode').ExtensionContext} ExtensionContext
Expand All @@ -16,31 +18,61 @@ import { sortClasses } from './sorting.mjs'
* @typedef {string | string[] | { regex?: string | string[]; separator?: string; replacement?: string } | undefined} LangConfig
*/

/**
* @param {import('vscode').WorkspaceFolder} workspaceFolder
* @param {string} path
*/
function expandRelativePath(workspaceFolder, path) {
return isPathAbsolute(path) ? path : resolvePath(workspaceFolder.uri.fsPath, path);
}

const config = workspace.getConfiguration();
/** @type {{ [key: string]: LangConfig | LangConfig[] }} */
const langConfig =
config.get('tailwind-raw-reorder.classRegex') || {};
/** @type {{ string: boolean } | undefined} */
const IgnoreConfigNotFound =
config.get('tailwind-raw-reorder.IgnoreConfigNotFound');
/** @type {import('vscode').WorkspaceFolder | undefined} */
const workspaceFolder = (workspace.workspaceFolders || [])[0];
/** @type {string | undefined} */
const rawTailwindConfigPath = config.get('tailwind-raw-reorder.tailwindConfigPath') ?? undefined;
const tailwindConfigPath =
(workspaceFolder && rawTailwindConfigPath && expandRelativePath(workspaceFolder, rawTailwindConfigPath));
const outputLogChannel = window.createOutputChannel('Tailwind Raw Reorder');

/**
* @param {ExtensionContext} context
*/
export function activate(context) {
if (!workspaceFolder) { // if we don't have a workspace folder, we should not run the extension
// log that no workspace was found
const message = 'No workspace found';
outputLogChannel.appendLine(message);
return;
}

let disposable = commands.registerTextEditorCommand(
'tailwind-raw-reorder.sortTailwindClasses',
function (editor, edit) {
const editorText = editor.document.getText();
const editorLangId = editor.document.languageId;
const editorFilePath = editor.document.fileName;
const editorWorkspace = workspace.getWorkspaceFolder(editor.document.uri);
if (!editorWorkspace) {
// log that no workspace was found for file
const message = `No workspace found for file: ${editorFilePath}`;
outputLogChannel.appendLine(message);
return;
}

const matchers = buildMatchers(
langConfig[editorLangId] || langConfig['html']
);

const tailwindConfig = getTailwindConfig({
filepath: editorFilePath
filepath: editorFilePath,
tailwindConfig: tailwindConfigPath
});

if (!tailwindConfig) {
Expand Down Expand Up @@ -124,7 +156,8 @@ export function activate(context) {
);

const tailwindConfig = getTailwindConfig({
filepath: editorFilePath
filepath: editorFilePath,
tailwindConfig: tailwindConfigPath
});

if (!tailwindConfig) {
Expand Down

0 comments on commit c73fe6e

Please sign in to comment.