@upstatement/twix 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -5
- package/bin/twix.js +60 -0
- package/package.json +19 -11
- package/bin/twix +0 -23
package/README.md
CHANGED
|
@@ -59,12 +59,12 @@ Create a `.twixrc.json` or `twix.config.json` file in your project root:
|
|
|
59
59
|
**Block tags** (have a body and `{% end* %}` tag):
|
|
60
60
|
|
|
61
61
|
- Standard Twig: `if`, `for`, `block`, `set`, `apply`, `autoescape`, `embed`, `filter`, `macro`, `sandbox`, `verbatim`, `with`
|
|
62
|
-
- Craft CMS: `switch`, `cache`, `js`, `css`, `nav`, `
|
|
62
|
+
- Craft CMS: `switch`, `cache`, `js`, `css`, `nav`, `tag`
|
|
63
63
|
|
|
64
64
|
**Inline tags** (self-closing):
|
|
65
65
|
|
|
66
66
|
- Standard Twig: `extends`, `include`, `use`, `import`, `from`, `do`, `flush`, `deprecated`
|
|
67
|
-
- Craft CMS: `exit`, `header`, `redirect`, `requireLogin`, `requireAdmin`, `requireGuest`, `requirePermission`
|
|
67
|
+
- Craft CMS: `exit`, `header`, `paginate`, `redirect`, `requireLogin`, `requireAdmin`, `requireGuest`, `requirePermission`
|
|
68
68
|
|
|
69
69
|
**Intermediate tags** (appear within blocks):
|
|
70
70
|
|
|
@@ -83,9 +83,20 @@ Create a `.twixrc.json` or `twix.config.json` file in your project root:
|
|
|
83
83
|
### Twig Formatting
|
|
84
84
|
|
|
85
85
|
- Block tags are indented with their content
|
|
86
|
-
- Expressions (`{{ }}`) preserve their content
|
|
87
86
|
- Whitespace control modifiers (`{%- -%}`, `{{- -}}`) are preserved
|
|
88
|
-
- Comments (`{# #}`) are preserved
|
|
87
|
+
- Comments (`{# #}`) are preserved exactly as-is (content inside comments is not formatted)
|
|
88
|
+
|
|
89
|
+
### Expression Formatting
|
|
90
|
+
|
|
91
|
+
Twix parses and formats Twig expressions inside `{{ }}` and `{% %}` tags:
|
|
92
|
+
|
|
93
|
+
- Spaces around binary operators (`a + b`), after commas, inside hashes (`{ key: value }`)
|
|
94
|
+
- No spaces around pipes (`value|filter|another`)
|
|
95
|
+
- Strings normalized to double quotes (except when containing unescaped double quotes)
|
|
96
|
+
- Long method chains break with `.` at the start of each line
|
|
97
|
+
- Long function/method calls break arguments onto separate lines with trailing commas
|
|
98
|
+
- Hashes and arrays break onto multiple lines when they exceed `printWidth`
|
|
99
|
+
- Expressions inside string interpolation (`#{...}`) are formatted
|
|
89
100
|
|
|
90
101
|
### Twig Inside HTML Attributes
|
|
91
102
|
|
|
@@ -124,10 +135,10 @@ Skip formatting for specific sections using ignore directives:
|
|
|
124
135
|
|
|
125
136
|
### Not Supported
|
|
126
137
|
|
|
127
|
-
- **Twig expressions are not parsed** - Content inside `{{ }}` and `{% %}` is preserved as-is, not reformatted
|
|
128
138
|
- **No HTML entity handling** - Entities like ` ` are passed through unchanged
|
|
129
139
|
- **No CSS/JS formatting** - Content inside `<style>` and `<script>` tags is not formatted
|
|
130
140
|
- **Windows line endings** - Output uses Unix line endings (`\n`)
|
|
141
|
+
- **Complex Twig edge cases** - Some advanced Twig syntax may fall back to preserving original formatting
|
|
131
142
|
|
|
132
143
|
## Editor Integration
|
|
133
144
|
|
package/bin/twix.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { execFileSync } = require("child_process");
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const os = require("os");
|
|
6
|
+
|
|
7
|
+
const platform = os.platform();
|
|
8
|
+
const arch = os.arch();
|
|
9
|
+
|
|
10
|
+
const PLATFORMS = {
|
|
11
|
+
"darwin-arm64": "@upstatement/twix-darwin-arm64",
|
|
12
|
+
"darwin-x64": "@upstatement/twix-darwin-x64",
|
|
13
|
+
"linux-arm64": "@upstatement/twix-linux-arm64",
|
|
14
|
+
"linux-x64": "@upstatement/twix-linux-x64",
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const platformKey = `${platform}-${arch}`;
|
|
18
|
+
const packageName = PLATFORMS[platformKey];
|
|
19
|
+
|
|
20
|
+
if (!packageName) {
|
|
21
|
+
console.error(`Unsupported platform: ${platform}-${arch}`);
|
|
22
|
+
console.error(
|
|
23
|
+
`twix currently supports: darwin-arm64, darwin-x64, linux-arm64, linux-x64`,
|
|
24
|
+
);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let binaryPath;
|
|
29
|
+
try {
|
|
30
|
+
// Use require.resolve to find the binary in node_modules
|
|
31
|
+
// This works correctly with npm, pnpm, yarn, and monorepos
|
|
32
|
+
const packagePath = require.resolve(`${packageName}/package.json`);
|
|
33
|
+
binaryPath = path.join(path.dirname(packagePath), "bin", "twix");
|
|
34
|
+
} catch (e) {
|
|
35
|
+
console.error(
|
|
36
|
+
`Could not find the twix binary for your platform (${platformKey}).`,
|
|
37
|
+
);
|
|
38
|
+
console.error(`The package ${packageName} does not appear to be installed.`);
|
|
39
|
+
console.error("");
|
|
40
|
+
console.error("This can happen if:");
|
|
41
|
+
console.error(" 1. Your platform is not supported");
|
|
42
|
+
console.error(
|
|
43
|
+
" 2. Optional dependencies were not installed (try: npm install --include=optional)",
|
|
44
|
+
);
|
|
45
|
+
console.error(
|
|
46
|
+
" 3. You're using a package manager that doesn't install optional dependencies by default",
|
|
47
|
+
);
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
execFileSync(binaryPath, process.argv.slice(2), { stdio: "inherit" });
|
|
53
|
+
} catch (e) {
|
|
54
|
+
if (e.status !== undefined) {
|
|
55
|
+
process.exit(e.status);
|
|
56
|
+
}
|
|
57
|
+
// If we get here, it's an actual error (not just a non-zero exit code)
|
|
58
|
+
console.error(`Failed to execute twix: ${e.message}`);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
package/package.json
CHANGED
|
@@ -1,17 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@upstatement/twix",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.6",
|
|
4
|
+
"description": "An opinionated formatter for Twig templating engine",
|
|
5
|
+
"bin": {
|
|
6
|
+
"twix": "bin/twix.js"
|
|
7
|
+
},
|
|
8
|
+
"files": [
|
|
9
|
+
"bin/",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
12
|
+
"optionalDependencies": {
|
|
13
|
+
"@upstatement/twix-darwin-arm64": "0.1.6",
|
|
14
|
+
"@upstatement/twix-darwin-x64": "0.1.6",
|
|
15
|
+
"@upstatement/twix-linux-arm64": "0.1.6",
|
|
16
|
+
"@upstatement/twix-linux-x64": "0.1.6"
|
|
17
|
+
},
|
|
5
18
|
"repository": {
|
|
6
19
|
"type": "git",
|
|
7
20
|
"url": "git+https://github.com/Upstatement/twix.git"
|
|
8
21
|
},
|
|
9
|
-
"optionalDependencies": {
|
|
10
|
-
"@upstatement/twix-darwin-arm64": "0.1.4",
|
|
11
|
-
"@upstatement/twix-darwin-x64": "0.1.4",
|
|
12
|
-
"@upstatement/twix-linux-arm64": "0.1.4",
|
|
13
|
-
"@upstatement/twix-linux-x64": "0.1.4"
|
|
14
|
-
},
|
|
15
22
|
"keywords": [
|
|
16
23
|
"twig",
|
|
17
24
|
"formatter",
|
|
@@ -21,7 +28,8 @@
|
|
|
21
28
|
],
|
|
22
29
|
"author": "Upstatement",
|
|
23
30
|
"license": "MIT",
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
}
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/Upstatement/twix/issues"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://github.com/Upstatement/twix#readme"
|
|
27
35
|
}
|
package/bin/twix
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
# Resolve the real path of this script (following symlinks)
|
|
3
|
-
# This is needed because npm creates a symlink in node_modules/.bin/
|
|
4
|
-
SCRIPT="$0"
|
|
5
|
-
while [ -h "$SCRIPT" ]; do
|
|
6
|
-
SCRIPTDIR="$(cd -P "$(dirname "$SCRIPT")" && pwd)"
|
|
7
|
-
SCRIPT="$(readlink "$SCRIPT")"
|
|
8
|
-
case "$SCRIPT" in
|
|
9
|
-
/*) ;;
|
|
10
|
-
*) SCRIPT="$SCRIPTDIR/$SCRIPT" ;;
|
|
11
|
-
esac
|
|
12
|
-
done
|
|
13
|
-
SCRIPTDIR="$(cd -P "$(dirname "$SCRIPT")" && pwd)"
|
|
14
|
-
|
|
15
|
-
# SCRIPTDIR is now the real bin/ directory inside @upstatement/twix
|
|
16
|
-
# Go up two levels to @upstatement/, then into the platform package
|
|
17
|
-
case "$(uname -s)-$(uname -m)" in
|
|
18
|
-
Darwin-arm64) exec "$SCRIPTDIR/../../twix-darwin-arm64/bin/twix" "$@" ;;
|
|
19
|
-
Darwin-x86_64) exec "$SCRIPTDIR/../../twix-darwin-x64/bin/twix" "$@" ;;
|
|
20
|
-
Linux-aarch64) exec "$SCRIPTDIR/../../twix-linux-arm64/bin/twix" "$@" ;;
|
|
21
|
-
Linux-x86_64) exec "$SCRIPTDIR/../../twix-linux-x64/bin/twix" "$@" ;;
|
|
22
|
-
*) echo "Unsupported platform: $(uname -s)-$(uname -m)" >&2; exit 1 ;;
|
|
23
|
-
esac
|