argot-css 0.0.0-stage → 0.1.0
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/LICENSE.md +20 -0
- package/README.md +38 -2
- package/bin/argot.js +4 -0
- package/dist/cli/ansiColors.d.ts +7 -0
- package/dist/cli/ansiColors.js +8 -0
- package/dist/cli/ansiColors.js.map +1 -0
- package/dist/cli/getConfig.d.ts +11 -0
- package/dist/cli/getConfig.js +37 -0
- package/dist/cli/getConfig.js.map +1 -0
- package/dist/cli/print.d.ts +2 -0
- package/dist/cli/print.js +13 -0
- package/dist/cli/print.js.map +1 -0
- package/dist/cli/run.d.ts +2 -0
- package/dist/cli/run.js +47 -0
- package/dist/cli/run.js.map +1 -0
- package/dist/cli/usage.d.ts +2 -0
- package/dist/cli/usage.js +20 -0
- package/dist/cli/usage.js.map +1 -0
- package/dist/config/getConfig.d.ts +1 -0
- package/dist/config/getConfig.js +38 -0
- package/dist/config/getConfig.js.map +1 -0
- package/dist/config/types.d.ts +31 -0
- package/dist/config/types.js +2 -0
- package/dist/config/types.js.map +1 -0
- package/dist/config/util.d.ts +2 -0
- package/dist/config/util.js +4 -0
- package/dist/config/util.js.map +1 -0
- package/dist/io/safeWrite.d.ts +24 -0
- package/dist/io/safeWrite.js +50 -0
- package/dist/io/safeWrite.js.map +1 -0
- package/dist/lib/writeOutput.d.ts +32 -0
- package/dist/lib/writeOutput.js +88 -0
- package/dist/lib/writeOutput.js.map +1 -0
- package/dist/palette/cli.d.ts +3 -0
- package/dist/palette/cli.js +44 -0
- package/dist/palette/cli.js.map +1 -0
- package/dist/palette/generateName.d.ts +3 -0
- package/dist/palette/generateName.js +65 -0
- package/dist/palette/generateName.js.map +1 -0
- package/dist/palette/generatePalette.d.ts +8 -0
- package/dist/palette/generatePalette.js +96 -0
- package/dist/palette/generatePalette.js.map +1 -0
- package/dist/palette/index.d.ts +6 -0
- package/dist/palette/index.js +6 -0
- package/dist/palette/index.js.map +1 -0
- package/dist/palette/node.d.ts +20 -0
- package/dist/palette/node.js +43 -0
- package/dist/palette/node.js.map +1 -0
- package/dist/palette/parseCssColor.d.ts +7 -0
- package/dist/palette/parseCssColor.js +41 -0
- package/dist/palette/parseCssColor.js.map +1 -0
- package/dist/palette/render.d.ts +9 -0
- package/dist/palette/render.js +52 -0
- package/dist/palette/render.js.map +1 -0
- package/dist/palette/types.d.ts +57 -0
- package/dist/palette/types.js +27 -0
- package/dist/palette/types.js.map +1 -0
- package/dist/palette/validation.d.ts +12 -0
- package/dist/palette/validation.js +122 -0
- package/dist/palette/validation.js.map +1 -0
- package/dist/processor/atImport.d.ts +4 -0
- package/dist/processor/atImport.js +149 -0
- package/dist/processor/atImport.js.map +1 -0
- package/dist/processor/cli.d.ts +2 -0
- package/dist/processor/cli.js +45 -0
- package/dist/processor/cli.js.map +1 -0
- package/dist/processor/index.d.ts +8 -0
- package/dist/processor/index.js +70 -0
- package/dist/processor/index.js.map +1 -0
- package/dist/processor/parseImportParams.d.ts +19 -0
- package/dist/processor/parseImportParams.js +139 -0
- package/dist/processor/parseImportParams.js.map +1 -0
- package/dist/processor/stylelintDefault.d.ts +8 -0
- package/dist/processor/stylelintDefault.js +10 -0
- package/dist/processor/stylelintDefault.js.map +1 -0
- package/dist/scaffold/cli.d.ts +3 -0
- package/dist/scaffold/cli.js +32 -0
- package/dist/scaffold/cli.js.map +1 -0
- package/dist/scaffold/templates.d.ts +6 -0
- package/dist/scaffold/templates.js +57 -0
- package/dist/scaffold/templates.js.map +1 -0
- package/dist/scaffold/writeScaffold.d.ts +12 -0
- package/dist/scaffold/writeScaffold.js +49 -0
- package/dist/scaffold/writeScaffold.js.map +1 -0
- package/dist/semantics/cli.d.ts +3 -0
- package/dist/semantics/cli.js +41 -0
- package/dist/semantics/cli.js.map +1 -0
- package/dist/semantics/generate.d.ts +23 -0
- package/dist/semantics/generate.js +50 -0
- package/dist/semantics/generate.js.map +1 -0
- package/dist/semantics/load-tokens.d.ts +29 -0
- package/dist/semantics/load-tokens.js +74 -0
- package/dist/semantics/load-tokens.js.map +1 -0
- package/dist/semantics/token-index.d.ts +14 -0
- package/dist/semantics/token-index.js +30 -0
- package/dist/semantics/token-index.js.map +1 -0
- package/dist/stylelint/config.d.ts +16 -0
- package/dist/stylelint/config.js +17 -0
- package/dist/stylelint/config.js.map +1 -0
- package/dist/stylelint/index.d.ts +3 -0
- package/dist/stylelint/index.js +4 -0
- package/dist/stylelint/index.js.map +1 -0
- package/dist/stylelint/rules/colorContrast.d.ts +4 -0
- package/dist/stylelint/rules/colorContrast.js +91 -0
- package/dist/stylelint/rules/colorContrast.js.map +1 -0
- package/dist/stylelint/rules/util.d.ts +13 -0
- package/dist/stylelint/rules/util.js +66 -0
- package/dist/stylelint/rules/util.js.map +1 -0
- package/dist/stylelint/rules/valid-token.d.ts +3 -0
- package/dist/stylelint/rules/valid-token.js +32 -0
- package/dist/stylelint/rules/valid-token.js.map +1 -0
- package/package.json +114 -4
- package/templates/base.css +53 -0
- package/templates/modules/index.css +0 -0
- package/templates/semantics-core.css +94 -0
- package/templates/semantics-extended.css +115 -0
- package/templates/styles.css +8 -0
- package/tokens/borders.json +37 -0
- package/tokens/color-bg.json +104 -0
- package/tokens/color-border.json +59 -0
- package/tokens/color-chart.json +40 -0
- package/tokens/color-icon.json +53 -0
- package/tokens/color-text.json +107 -0
- package/tokens/layout.json +66 -0
- package/tokens/misc.json +16 -0
- package/tokens/motion.json +40 -0
- package/tokens/spacing.json +41 -0
- package/tokens/typography.json +107 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Keith J. Grant and contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the “Software”), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,39 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Argot
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A modular CSS toolset for modern CSS: processor, semantic tokens, palette
|
|
4
|
+
generation, optional linting, and a stylesheet scaffold. Published on npm as
|
|
5
|
+
**`argot-css`**; the CLI command is **`argot`**.
|
|
6
|
+
|
|
7
|
+
**Documentation:** [https://argot-css.dev/](https://argot-css.dev/)
|
|
8
|
+
|
|
9
|
+
Argot is in active development. Semantic token names may still change; feedback
|
|
10
|
+
from real projects is welcome.
|
|
11
|
+
|
|
12
|
+
## Quick start
|
|
13
|
+
|
|
14
|
+
Requires **Node.js 22.18+** (native ESM).
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install --save-dev argot-css
|
|
18
|
+
npx argot styles/index.css dist/styles.css
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Other common commands:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npx argot semantics ./styles/vars-semantic.css
|
|
25
|
+
npx argot palette ./palette.json ./styles/vars-primitive.css
|
|
26
|
+
npx argot scaffold
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
See [Getting started](https://argot-css.dev/docs/getting-started/) on the site.
|
|
30
|
+
|
|
31
|
+
## Programmatic API
|
|
32
|
+
|
|
33
|
+
Library entrypoints, options, and return types:
|
|
34
|
+
[JavaScript API](https://argot-css.dev/docs/reference/api/).
|
|
35
|
+
|
|
36
|
+
## Contributing
|
|
37
|
+
|
|
38
|
+
Issues, discussions, and how to work in this repo:
|
|
39
|
+
[`CONTRIBUTING.md`](./CONTRIBUTING.md).
|
package/bin/argot.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const ANSI_RED = "\u001B[31m";
|
|
2
|
+
export declare const ANSI_GREEN = "\u001B[32m";
|
|
3
|
+
export declare const ANSI_YELLOW = "\u001B[33m";
|
|
4
|
+
export declare const ANSI_BLUE = "\u001B[34m";
|
|
5
|
+
export declare const ANSI_MAGENTA = "\u001B[35m";
|
|
6
|
+
export declare const ANSI_CYAN = "\u001B[36m";
|
|
7
|
+
export declare const ANSI_WHITE = "\u001B[37m";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const ANSI_RED = '\x1b[31m';
|
|
2
|
+
export const ANSI_GREEN = '\x1b[32m';
|
|
3
|
+
export const ANSI_YELLOW = '\x1b[33m';
|
|
4
|
+
export const ANSI_BLUE = '\x1b[34m';
|
|
5
|
+
export const ANSI_MAGENTA = '\x1b[35m';
|
|
6
|
+
export const ANSI_CYAN = '\x1b[36m';
|
|
7
|
+
export const ANSI_WHITE = '\x1b[37m';
|
|
8
|
+
//# sourceMappingURL=ansiColors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ansiColors.js","sourceRoot":"","sources":["../../src/cli/ansiColors.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAAC;AACnC,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CAAC;AACrC,MAAM,CAAC,MAAM,WAAW,GAAG,UAAU,CAAC;AACtC,MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,CAAC;AACpC,MAAM,CAAC,MAAM,YAAY,GAAG,UAAU,CAAC;AACvC,MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,CAAC;AACpC,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CAAC","sourcesContent":["export const ANSI_RED = '\\x1b[31m';\nexport const ANSI_GREEN = '\\x1b[32m';\nexport const ANSI_YELLOW = '\\x1b[33m';\nexport const ANSI_BLUE = '\\x1b[34m';\nexport const ANSI_MAGENTA = '\\x1b[35m';\nexport const ANSI_CYAN = '\\x1b[36m';\nexport const ANSI_WHITE = '\\x1b[37m';\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type SeedColor = string | [name: string, color: string];
|
|
2
|
+
export interface ArgotConfig {
|
|
3
|
+
cssSource?: string;
|
|
4
|
+
cssDest?: string;
|
|
5
|
+
lintConfig?: string;
|
|
6
|
+
minify?: boolean | 'both';
|
|
7
|
+
seedColors?: SeedColor[];
|
|
8
|
+
semanticSet?: 'core' | 'extended';
|
|
9
|
+
scaffoldBaseDir?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function getConfig(): Promise<any>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
import { FileSearcher } from 'search-closest';
|
|
3
|
+
const CONFIG_FILES = [
|
|
4
|
+
{
|
|
5
|
+
name: 'package.json',
|
|
6
|
+
async filter({ path }) {
|
|
7
|
+
try {
|
|
8
|
+
return Boolean(await loadConfigFromPackageJson(path));
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
'.argot.json',
|
|
16
|
+
'.argotrc.json',
|
|
17
|
+
'argot.config.json',
|
|
18
|
+
];
|
|
19
|
+
const require = createRequire(import.meta.url);
|
|
20
|
+
async function loadConfigFromPackageJson(path) {
|
|
21
|
+
const json = require(path);
|
|
22
|
+
return !!json.argot;
|
|
23
|
+
}
|
|
24
|
+
export async function getConfig() {
|
|
25
|
+
const searcher = new FileSearcher(CONFIG_FILES);
|
|
26
|
+
const startDirectory = process.cwd();
|
|
27
|
+
const path = await searcher.search(startDirectory);
|
|
28
|
+
if (path === undefined) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
const result = require(path);
|
|
32
|
+
if (path.endsWith('package.json')) {
|
|
33
|
+
return result.argot;
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=getConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getConfig.js","sourceRoot":"","sources":["../../src/cli/getConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,YAAY,EAAwB,MAAM,gBAAgB,CAAC;AAgBpE,MAAM,YAAY,GAAmB;IACnC;QACE,IAAI,EAAE,cAAc;QACpB,KAAK,CAAC,MAAM,CAAC,EAAE,IAAI,EAAoB;YACrC,IAAI,CAAC;gBACH,OAAO,OAAO,CAAC,MAAM,yBAAyB,CAAC,IAAI,CAAC,CAAC,CAAC;YACxD,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;KACF;IACD,aAAa;IACb,eAAe;IACf,mBAAmB;CACpB,CAAC;AAEF,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/C,KAAK,UAAU,yBAAyB,CAAC,IAAY;IACnD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;AACtB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS;IAC7B,MAAM,QAAQ,GAAG,IAAI,YAAY,CAAC,YAAY,CAAC,CAAC;IAEhD,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IACrC,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IAEnD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7B,IAAI,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;QAClC,OAAO,MAAM,CAAC,KAAK,CAAC;IACtB,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { createRequire } from 'module';\nimport { FileSearcher, type SearcherOptions } from 'search-closest';\n\nexport type SeedColor = string | [name: string, color: string];\nexport interface ArgotConfig {\n cssSource?: string;\n cssDest?: string;\n lintConfig?: string;\n minify?: boolean | 'both';\n seedColors?: SeedColor[];\n semanticSet?: 'core' | 'extended';\n scaffoldBaseDir?: string;\n}\n\ntype SearchTarget =\n string | { name: string; filter: SearcherOptions['filter'] };\n\nconst CONFIG_FILES: SearchTarget[] = [\n {\n name: 'package.json',\n async filter({ path }: { path: string }) {\n try {\n return Boolean(await loadConfigFromPackageJson(path));\n } catch {\n return false;\n }\n },\n },\n '.argot.json',\n '.argotrc.json',\n 'argot.config.json',\n];\n\nconst require = createRequire(import.meta.url);\n\nasync function loadConfigFromPackageJson(path: string) {\n const json = require(path);\n return !!json.argot;\n}\n\nexport async function getConfig() {\n const searcher = new FileSearcher(CONFIG_FILES);\n\n const startDirectory = process.cwd();\n const path = await searcher.search(startDirectory);\n\n if (path === undefined) {\n return undefined;\n }\n const result = require(path);\n\n if (path.endsWith('package.json')) {\n return result.argot;\n }\n\n return result;\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ANSI_WHITE, ANSI_RED } from "./ansiColors.js";
|
|
2
|
+
export function print(message, color = ANSI_WHITE) {
|
|
3
|
+
console.log(`${color}${message}${ANSI_WHITE}`);
|
|
4
|
+
}
|
|
5
|
+
export function printError(error) {
|
|
6
|
+
const isError = error instanceof Error;
|
|
7
|
+
const message = isError ? `${error.name}: ${error.message}` : error;
|
|
8
|
+
console.error(`${ANSI_RED}argot: ${message}${ANSI_WHITE}\n`);
|
|
9
|
+
if (isError && process.argv.includes('--verbose')) {
|
|
10
|
+
console.log(error);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=print.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"print.js","sourceRoot":"","sources":["../../src/cli/print.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEvD,MAAM,UAAU,KAAK,CAAC,OAAe,EAAE,QAAgB,UAAU;IAC/D,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,GAAG,OAAO,GAAG,UAAU,EAAE,CAAC,CAAC;AACjD,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC;IACvC,MAAM,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;IAEpE,OAAO,CAAC,KAAK,CAAC,GAAG,QAAQ,UAAU,OAAO,GAAG,UAAU,IAAI,CAAC,CAAC;IAE7D,IAAI,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;QAClD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;AACH,CAAC","sourcesContent":["import { ANSI_WHITE, ANSI_RED } from './ansiColors.ts';\n\nexport function print(message: string, color: string = ANSI_WHITE): void {\n console.log(`${color}${message}${ANSI_WHITE}`);\n}\n\nexport function printError(error: unknown): void {\n const isError = error instanceof Error;\n const message = isError ? `${error.name}: ${error.message}` : error;\n\n console.error(`${ANSI_RED}argot: ${message}${ANSI_WHITE}\\n`);\n\n if (isError && process.argv.includes('--verbose')) {\n console.log(error);\n }\n}\n"]}
|
package/dist/cli/run.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { USAGE } from "./usage.js";
|
|
2
|
+
import { runSemantics } from "../semantics/cli.js";
|
|
3
|
+
import { runPalette } from "../palette/cli.js";
|
|
4
|
+
import { runScaffold } from "../scaffold/cli.js";
|
|
5
|
+
import { runProcessor } from "../processor/cli.js";
|
|
6
|
+
import { printError } from "./print.js";
|
|
7
|
+
import { getConfig } from "../config/getConfig.js";
|
|
8
|
+
async function run() {
|
|
9
|
+
try {
|
|
10
|
+
await routeArgs(process.argv.slice(2));
|
|
11
|
+
}
|
|
12
|
+
catch (e) {
|
|
13
|
+
printError(e);
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async function routeArgs(args) {
|
|
18
|
+
const [command, ...rest] = args;
|
|
19
|
+
const config = await getConfig();
|
|
20
|
+
if (!command && !config) {
|
|
21
|
+
process.stdout.write(USAGE);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (['help', '--help', '-h'].includes(command)) {
|
|
25
|
+
process.stdout.write(USAGE);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (command === 'semantics') {
|
|
29
|
+
return await runSemantics(rest, config);
|
|
30
|
+
}
|
|
31
|
+
if (command === 'palette') {
|
|
32
|
+
return await runPalette(rest, config);
|
|
33
|
+
}
|
|
34
|
+
if (command === 'process') {
|
|
35
|
+
return await runProcessor(rest, config);
|
|
36
|
+
}
|
|
37
|
+
if (command === 'scaffold') {
|
|
38
|
+
return await runScaffold(rest, config);
|
|
39
|
+
}
|
|
40
|
+
if (!command || command.endsWith('.css')) {
|
|
41
|
+
return await runProcessor(args, config);
|
|
42
|
+
}
|
|
43
|
+
printError(`Unknown command: ${command}`);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
export { run };
|
|
47
|
+
//# sourceMappingURL=run.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run.js","sourceRoot":"","sources":["../../src/cli/run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,KAAK,UAAU,GAAG;IAChB,IAAI,CAAC;QACH,MAAM,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,UAAU,CAAC,CAAC,CAAC,CAAC;QACd,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;AACH,CAAC;AAED,KAAK,UAAU,SAAS,CAAC,IAAc;IACrC,MAAM,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC;IAChC,MAAM,MAAM,GAAG,MAAM,SAAS,EAAE,CAAC;IAEjC,IAAI,CAAC,OAAO,IAAI,CAAC,MAAM,EAAE,CAAC;QACxB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC5B,OAAO;IACT,CAAC;IAED,IAAI,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;QAC/C,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC5B,OAAO;IACT,CAAC;IAED,IAAI,OAAO,KAAK,WAAW,EAAE,CAAC;QAC5B,OAAO,MAAM,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC1C,CAAC;IAED,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,OAAO,MAAM,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACxC,CAAC;IAED,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,OAAO,MAAM,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC1C,CAAC;IAED,IAAI,OAAO,KAAK,UAAU,EAAE,CAAC;QAC3B,OAAO,MAAM,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACzC,CAAC;IAED,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QACzC,OAAO,MAAM,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC1C,CAAC;IAED,UAAU,CAAC,oBAAoB,OAAO,EAAE,CAAC,CAAC;IAC1C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,OAAO,EAAE,GAAG,EAAE,CAAC","sourcesContent":["import { USAGE } from './usage.ts';\nimport { runSemantics } from '../semantics/cli.ts';\nimport { runPalette } from '../palette/cli.ts';\nimport { runScaffold } from '../scaffold/cli.ts';\nimport { runProcessor } from '../processor/cli.ts';\nimport { printError } from './print.ts';\nimport { getConfig } from '../config/getConfig.ts';\n\nasync function run() {\n try {\n await routeArgs(process.argv.slice(2));\n } catch (e) {\n printError(e);\n process.exit(1);\n }\n}\n\nasync function routeArgs(args: string[]) {\n const [command, ...rest] = args;\n const config = await getConfig();\n\n if (!command && !config) {\n process.stdout.write(USAGE);\n return;\n }\n\n if (['help', '--help', '-h'].includes(command)) {\n process.stdout.write(USAGE);\n return;\n }\n\n if (command === 'semantics') {\n return await runSemantics(rest, config);\n }\n\n if (command === 'palette') {\n return await runPalette(rest, config);\n }\n\n if (command === 'process') {\n return await runProcessor(rest, config);\n }\n\n if (command === 'scaffold') {\n return await runScaffold(rest, config);\n }\n\n if (!command || command.endsWith('.css')) {\n return await runProcessor(args, config);\n }\n\n printError(`Unknown command: ${command}`);\n process.exit(1);\n}\n\nexport { run };\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
declare const USAGE = "Usage:\n argot [sourceFile.css] [destFile.css] Process CSS\n argot scaffold [--directory \"./path/to/directory\"] [--force] [--dry-run]\n Write new project CSS scaffold\n argot semantics [path] [--extended] [--force] [--dry-run]\n Write semantic CSS template (default: ./vars-semantic.css)\n argot palette [output.css] [--force] [--dry-run]\n Write primitive CSS (default: ./vars-primitive.css)\n argot help Show this help\n\nOptions:\n --extended Include extended-tier tokens (default: core only)\n\nExamples:\n npx argot-css semantics\n npx argot-css semantics --extended\n npx argot-css semantics ./styles/tokens.css --extended\n";
|
|
2
|
+
export { USAGE };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const USAGE = `Usage:
|
|
2
|
+
argot [sourceFile.css] [destFile.css] Process CSS
|
|
3
|
+
argot scaffold [--directory "./path/to/directory"] [--force] [--dry-run]
|
|
4
|
+
Write new project CSS scaffold
|
|
5
|
+
argot semantics [path] [--extended] [--force] [--dry-run]
|
|
6
|
+
Write semantic CSS template (default: ./vars-semantic.css)
|
|
7
|
+
argot palette [output.css] [--force] [--dry-run]
|
|
8
|
+
Write primitive CSS (default: ./vars-primitive.css)
|
|
9
|
+
argot help Show this help
|
|
10
|
+
|
|
11
|
+
Options:
|
|
12
|
+
--extended Include extended-tier tokens (default: core only)
|
|
13
|
+
|
|
14
|
+
Examples:
|
|
15
|
+
npx argot-css semantics
|
|
16
|
+
npx argot-css semantics --extended
|
|
17
|
+
npx argot-css semantics ./styles/tokens.css --extended
|
|
18
|
+
`;
|
|
19
|
+
export { USAGE };
|
|
20
|
+
//# sourceMappingURL=usage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"usage.js","sourceRoot":"","sources":["../../src/cli/usage.ts"],"names":[],"mappings":"AAAA,MAAM,KAAK,GAAG;;;;;;;;;;;;;;;;;CAiBb,CAAC;AAEF,OAAO,EAAE,KAAK,EAAE,CAAC","sourcesContent":["const USAGE = `Usage:\n argot [sourceFile.css] [destFile.css] Process CSS\n argot scaffold [--directory \"./path/to/directory\"] [--force] [--dry-run]\n Write new project CSS scaffold\n argot semantics [path] [--extended] [--force] [--dry-run]\n Write semantic CSS template (default: ./vars-semantic.css)\n argot palette [output.css] [--force] [--dry-run]\n Write primitive CSS (default: ./vars-primitive.css)\n argot help Show this help\n\nOptions:\n --extended Include extended-tier tokens (default: core only)\n\nExamples:\n npx argot-css semantics\n npx argot-css semantics --extended\n npx argot-css semantics ./styles/tokens.css --extended\n`;\n\nexport { USAGE };\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getConfig(): Promise<any>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
import { FileSearcher } from 'search-closest';
|
|
3
|
+
const CONFIG_FILES = [
|
|
4
|
+
{
|
|
5
|
+
name: 'package.json',
|
|
6
|
+
async filter({ path }) {
|
|
7
|
+
try {
|
|
8
|
+
return Boolean(await loadConfigFromPackageJson(path));
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
'.argot.json',
|
|
16
|
+
'argot.json',
|
|
17
|
+
'.argotrc.json',
|
|
18
|
+
'argot.config.json',
|
|
19
|
+
];
|
|
20
|
+
const require = createRequire(import.meta.url);
|
|
21
|
+
async function loadConfigFromPackageJson(path) {
|
|
22
|
+
const json = require(path);
|
|
23
|
+
return !!json.argot;
|
|
24
|
+
}
|
|
25
|
+
export async function getConfig() {
|
|
26
|
+
const searcher = new FileSearcher(CONFIG_FILES);
|
|
27
|
+
const startDirectory = process.cwd();
|
|
28
|
+
const path = await searcher.search(startDirectory);
|
|
29
|
+
if (path === undefined) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
const result = require(path);
|
|
33
|
+
if (path.endsWith('package.json')) {
|
|
34
|
+
return result.argot;
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=getConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getConfig.js","sourceRoot":"","sources":["../../src/config/getConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,EAAE,YAAY,EAAwB,MAAM,gBAAgB,CAAC;AAKpE,MAAM,YAAY,GAAmB;IACnC;QACE,IAAI,EAAE,cAAc;QACpB,KAAK,CAAC,MAAM,CAAC,EAAE,IAAI,EAAoB;YACrC,IAAI,CAAC;gBACH,OAAO,OAAO,CAAC,MAAM,yBAAyB,CAAC,IAAI,CAAC,CAAC,CAAC;YACxD,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;KACF;IACD,aAAa;IACb,YAAY;IACZ,eAAe;IACf,mBAAmB;CACpB,CAAC;AAEF,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/C,KAAK,UAAU,yBAAyB,CAAC,IAAY;IACnD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,OAAO,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC;AACtB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,SAAS;IAC7B,MAAM,QAAQ,GAAG,IAAI,YAAY,CAAC,YAAY,CAAC,CAAC;IAEhD,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IACrC,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IAEnD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACvB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE7B,IAAI,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;QAClC,OAAO,MAAM,CAAC,KAAK,CAAC;IACtB,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { createRequire } from 'module';\nimport { FileSearcher, type SearcherOptions } from 'search-closest';\n\ntype SearchTarget =\n string | { name: string; filter: SearcherOptions['filter'] };\n\nconst CONFIG_FILES: SearchTarget[] = [\n {\n name: 'package.json',\n async filter({ path }: { path: string }) {\n try {\n return Boolean(await loadConfigFromPackageJson(path));\n } catch {\n return false;\n }\n },\n },\n '.argot.json',\n 'argot.json',\n '.argotrc.json',\n 'argot.config.json',\n];\n\nconst require = createRequire(import.meta.url);\n\nasync function loadConfigFromPackageJson(path: string) {\n const json = require(path);\n return !!json.argot;\n}\n\nexport async function getConfig() {\n const searcher = new FileSearcher(CONFIG_FILES);\n\n const startDirectory = process.cwd();\n const path = await searcher.search(startDirectory);\n\n if (path === undefined) {\n return undefined;\n }\n const result = require(path);\n\n if (path.endsWith('package.json')) {\n return result.argot;\n }\n\n return result;\n}\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { LightnessCurveEnum, ChromaCurveEnum, ColorFormatEnum } from '../palette/types.ts';
|
|
2
|
+
export interface ProcessorConfig {
|
|
3
|
+
source?: string;
|
|
4
|
+
destination?: string;
|
|
5
|
+
lintConfig?: string;
|
|
6
|
+
minify?: boolean | 'both';
|
|
7
|
+
}
|
|
8
|
+
export type SeedColor = string | {
|
|
9
|
+
name?: string;
|
|
10
|
+
color: string;
|
|
11
|
+
};
|
|
12
|
+
export interface PaletteDefinition {
|
|
13
|
+
version?: 1;
|
|
14
|
+
seedColors?: readonly SeedColor[];
|
|
15
|
+
lightnessCurve?: LightnessCurveEnum;
|
|
16
|
+
chromaCurve?: ChromaCurveEnum;
|
|
17
|
+
format?: ColorFormatEnum;
|
|
18
|
+
}
|
|
19
|
+
export interface PaletteConfig extends PaletteDefinition {
|
|
20
|
+
output?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface SemanticDefinition {
|
|
23
|
+
output?: string;
|
|
24
|
+
set: 'core' | 'extended';
|
|
25
|
+
}
|
|
26
|
+
export interface ArgotConfig {
|
|
27
|
+
processor?: ProcessorConfig;
|
|
28
|
+
scaffoldDirectory?: string;
|
|
29
|
+
palette?: PaletteConfig;
|
|
30
|
+
semantics?: SemanticDefinition;
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/config/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n LightnessCurveEnum,\n ChromaCurveEnum,\n ColorFormatEnum,\n} from '../palette/types.ts';\n\nexport interface ProcessorConfig {\n source?: string;\n destination?: string;\n lintConfig?: string;\n minify?: boolean | 'both';\n}\n\nexport type SeedColor =\n | string\n | {\n name?: string;\n color: string;\n };\n\nexport interface PaletteDefinition {\n version?: 1;\n seedColors?: readonly SeedColor[];\n lightnessCurve?: LightnessCurveEnum;\n chromaCurve?: ChromaCurveEnum;\n format?: ColorFormatEnum;\n}\n\nexport interface PaletteConfig extends PaletteDefinition {\n output?: string;\n}\n\nexport interface SemanticDefinition {\n output?: string;\n set: 'core' | 'extended';\n}\n\nexport interface ArgotConfig {\n processor?: ProcessorConfig;\n scaffoldDirectory?: string;\n palette?: PaletteConfig;\n semantics?: SemanticDefinition;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/config/util.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,oBAAoB,CAAC,MAAmB;IACtD,OAAO,MAAM,EAAE,iBAAiB,IAAI,QAAQ,CAAC;AAC/C,CAAC","sourcesContent":["import type { ArgotConfig } from './types.ts';\n\nexport function getScaffoldDirectory(config: ArgotConfig) {\n return config?.scaffoldDirectory ?? 'styles';\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type ExistsMessage = (resolved: string) => string;
|
|
2
|
+
export interface WriteOutputOptions {
|
|
3
|
+
force?: boolean;
|
|
4
|
+
dryRun?: boolean;
|
|
5
|
+
/** When true, skip preflight (caller already checked all targets). */
|
|
6
|
+
skipAssert?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface AssertWritableOptions {
|
|
9
|
+
force?: boolean;
|
|
10
|
+
existsMessage?: ExistsMessage;
|
|
11
|
+
}
|
|
12
|
+
export interface WriteOutputResult {
|
|
13
|
+
path: string;
|
|
14
|
+
written: boolean;
|
|
15
|
+
}
|
|
16
|
+
declare function defaultExistsMessage(resolved: string): string;
|
|
17
|
+
declare function assertWritableOutputFile(resolved: string, { force, existsMessage, }?: AssertWritableOptions): void;
|
|
18
|
+
declare function writeOutputFile(resolved: string, contents: string, { force }?: {
|
|
19
|
+
force?: boolean;
|
|
20
|
+
}): void;
|
|
21
|
+
declare function writeOutput(outPath: string, contents: string, { force, dryRun, skipAssert, existsMessage, }?: WriteOutputOptions & {
|
|
22
|
+
existsMessage?: ExistsMessage;
|
|
23
|
+
}): WriteOutputResult;
|
|
24
|
+
export { assertWritableOutputFile, defaultExistsMessage, writeOutput, writeOutputFile, };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
function defaultExistsMessage(resolved) {
|
|
4
|
+
return `Output file already exists: ${resolved}. Use --force to replace it.`;
|
|
5
|
+
}
|
|
6
|
+
function assertWritableOutputFile(resolved, { force = false, existsMessage = defaultExistsMessage, } = {}) {
|
|
7
|
+
let stat;
|
|
8
|
+
try {
|
|
9
|
+
stat = fs.lstatSync(resolved);
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
if (error.code !== 'ENOENT')
|
|
13
|
+
throw error;
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (!stat.isFile() || stat.isSymbolicLink()) {
|
|
17
|
+
throw new Error(`Refusing to overwrite non-regular file: ${resolved}`);
|
|
18
|
+
}
|
|
19
|
+
if (!force) {
|
|
20
|
+
throw new Error(existsMessage(resolved));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function writeOutputFile(resolved, contents, { force = false } = {}) {
|
|
24
|
+
fs.mkdirSync(path.dirname(resolved), { recursive: true });
|
|
25
|
+
const flags = force
|
|
26
|
+
? fs.constants.O_WRONLY |
|
|
27
|
+
fs.constants.O_CREAT |
|
|
28
|
+
fs.constants.O_TRUNC |
|
|
29
|
+
fs.constants.O_NOFOLLOW
|
|
30
|
+
: 'wx';
|
|
31
|
+
const descriptor = fs.openSync(resolved, flags);
|
|
32
|
+
try {
|
|
33
|
+
fs.writeFileSync(descriptor, contents, 'utf8');
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
fs.closeSync(descriptor);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function writeOutput(outPath, contents, { force = false, dryRun = false, skipAssert = false, existsMessage = defaultExistsMessage, } = {}) {
|
|
40
|
+
const resolved = path.resolve(outPath);
|
|
41
|
+
if (!skipAssert) {
|
|
42
|
+
assertWritableOutputFile(resolved, { force, existsMessage });
|
|
43
|
+
}
|
|
44
|
+
if (!dryRun) {
|
|
45
|
+
writeOutputFile(resolved, contents, { force });
|
|
46
|
+
}
|
|
47
|
+
return { path: resolved, written: !dryRun };
|
|
48
|
+
}
|
|
49
|
+
export { assertWritableOutputFile, defaultExistsMessage, writeOutput, writeOutputFile, };
|
|
50
|
+
//# sourceMappingURL=safeWrite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safeWrite.js","sourceRoot":"","sources":["../../src/io/safeWrite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAqB7B,SAAS,oBAAoB,CAAC,QAAgB;IAC5C,OAAO,+BAA+B,QAAQ,8BAA8B,CAAC;AAC/E,CAAC;AAED,SAAS,wBAAwB,CAC/B,QAAgB,EAChB,EACE,KAAK,GAAG,KAAK,EACb,aAAa,GAAG,oBAAoB,MACX,EAAE;IAE7B,IAAI,IAAI,CAAC;IACT,IAAI,CAAC;QACH,IAAI,GAAG,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAK,KAA+B,CAAC,IAAI,KAAK,QAAQ;YAAE,MAAM,KAAK,CAAC;QACpE,OAAO;IACT,CAAC;IACD,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,IAAI,CAAC,cAAc,EAAE,EAAE,CAAC;QAC5C,MAAM,IAAI,KAAK,CAAC,2CAA2C,QAAQ,EAAE,CAAC,CAAC;IACzE,CAAC;IACD,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC;AAED,SAAS,eAAe,CACtB,QAAgB,EAChB,QAAgB,EAChB,EAAE,KAAK,GAAG,KAAK,KAA0B,EAAE;IAE3C,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1D,MAAM,KAAK,GAAG,KAAK;QACjB,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,QAAQ;YACrB,EAAE,CAAC,SAAS,CAAC,OAAO;YACpB,EAAE,CAAC,SAAS,CAAC,OAAO;YACpB,EAAE,CAAC,SAAS,CAAC,UAAU;QACzB,CAAC,CAAC,IAAI,CAAC;IACT,MAAM,UAAU,GAAG,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IAChD,IAAI,CAAC;QACH,EAAE,CAAC,aAAa,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC;IACjD,CAAC;YAAS,CAAC;QACT,EAAE,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;IAC3B,CAAC;AACH,CAAC;AAED,SAAS,WAAW,CAClB,OAAe,EACf,QAAgB,EAChB,EACE,KAAK,GAAG,KAAK,EACb,MAAM,GAAG,KAAK,EACd,UAAU,GAAG,KAAK,EAClB,aAAa,GAAG,oBAAoB,MACsB,EAAE;IAE9D,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IACvC,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,wBAAwB,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC,CAAC;IAC/D,CAAC;IACD,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,eAAe,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;IACjD,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,MAAM,EAAE,CAAC;AAC9C,CAAC;AAED,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,WAAW,EACX,eAAe,GAChB,CAAC","sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nexport type ExistsMessage = (resolved: string) => string;\n\nexport interface WriteOutputOptions {\n force?: boolean;\n dryRun?: boolean;\n /** When true, skip preflight (caller already checked all targets). */\n skipAssert?: boolean;\n}\n\nexport interface AssertWritableOptions {\n force?: boolean;\n existsMessage?: ExistsMessage;\n}\n\nexport interface WriteOutputResult {\n path: string;\n written: boolean;\n}\n\nfunction defaultExistsMessage(resolved: string): string {\n return `Output file already exists: ${resolved}. Use --force to replace it.`;\n}\n\nfunction assertWritableOutputFile(\n resolved: string,\n {\n force = false,\n existsMessage = defaultExistsMessage,\n }: AssertWritableOptions = {},\n): void {\n let stat;\n try {\n stat = fs.lstatSync(resolved);\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error;\n return;\n }\n if (!stat.isFile() || stat.isSymbolicLink()) {\n throw new Error(`Refusing to overwrite non-regular file: ${resolved}`);\n }\n if (!force) {\n throw new Error(existsMessage(resolved));\n }\n}\n\nfunction writeOutputFile(\n resolved: string,\n contents: string,\n { force = false }: { force?: boolean } = {},\n): void {\n fs.mkdirSync(path.dirname(resolved), { recursive: true });\n const flags = force\n ? fs.constants.O_WRONLY |\n fs.constants.O_CREAT |\n fs.constants.O_TRUNC |\n fs.constants.O_NOFOLLOW\n : 'wx';\n const descriptor = fs.openSync(resolved, flags);\n try {\n fs.writeFileSync(descriptor, contents, 'utf8');\n } finally {\n fs.closeSync(descriptor);\n }\n}\n\nfunction writeOutput(\n outPath: string,\n contents: string,\n {\n force = false,\n dryRun = false,\n skipAssert = false,\n existsMessage = defaultExistsMessage,\n }: WriteOutputOptions & { existsMessage?: ExistsMessage } = {},\n): WriteOutputResult {\n const resolved = path.resolve(outPath);\n if (!skipAssert) {\n assertWritableOutputFile(resolved, { force, existsMessage });\n }\n if (!dryRun) {\n writeOutputFile(resolved, contents, { force });\n }\n return { path: resolved, written: !dryRun };\n}\n\nexport {\n assertWritableOutputFile,\n defaultExistsMessage,\n writeOutput,\n writeOutputFile,\n};"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type ExistsMessageGetter = (resolved: string) => string;
|
|
2
|
+
export interface WriteOutputOptions {
|
|
3
|
+
force?: boolean;
|
|
4
|
+
dryRun?: boolean;
|
|
5
|
+
/** When true, skip preflight (caller already checked all targets). */
|
|
6
|
+
skipAssert?: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Directory that output paths must remain inside after resolution.
|
|
9
|
+
* Defaults to `process.cwd()`.
|
|
10
|
+
*/
|
|
11
|
+
root?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface WriteOutputResult {
|
|
14
|
+
path: string;
|
|
15
|
+
written: boolean;
|
|
16
|
+
}
|
|
17
|
+
export interface AssertWritableOptions {
|
|
18
|
+
force?: boolean;
|
|
19
|
+
getExistsMessage?: ExistsMessageGetter;
|
|
20
|
+
root?: string;
|
|
21
|
+
}
|
|
22
|
+
declare function writeOutput(outPath: string, contents: string, { force, dryRun, skipAssert, getExistsMessage, root, }?: WriteOutputOptions & {
|
|
23
|
+
getExistsMessage?: ExistsMessageGetter;
|
|
24
|
+
}): WriteOutputResult;
|
|
25
|
+
declare function getDefaultExistsMessage(resolved: string): string;
|
|
26
|
+
declare function assertPathInsideRoot(resolvedPath: string, root?: string): void;
|
|
27
|
+
declare function assertWritableOutputFile(resolvedPath: string, { force, getExistsMessage, root, }?: AssertWritableOptions): void;
|
|
28
|
+
declare function writeOutputFile(resolvedPath: string, contents: string, { force, root, }?: {
|
|
29
|
+
force?: boolean;
|
|
30
|
+
root?: string;
|
|
31
|
+
}): void;
|
|
32
|
+
export { writeOutput, getDefaultExistsMessage as defaultExistsMessage, assertPathInsideRoot, assertWritableOutputFile, writeOutputFile, };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
function writeOutput(outPath, contents, { force = false, dryRun = false, skipAssert = false, getExistsMessage = getDefaultExistsMessage, root = process.cwd(), } = {}) {
|
|
4
|
+
const resolved = path.resolve(outPath);
|
|
5
|
+
assertPathInsideRoot(resolved, root);
|
|
6
|
+
if (!skipAssert) {
|
|
7
|
+
assertWritableOutputFile(resolved, { force, getExistsMessage, root });
|
|
8
|
+
}
|
|
9
|
+
if (!dryRun) {
|
|
10
|
+
writeOutputFile(resolved, contents, { force, root });
|
|
11
|
+
}
|
|
12
|
+
return { path: resolved, written: !dryRun };
|
|
13
|
+
}
|
|
14
|
+
function getDefaultExistsMessage(resolved) {
|
|
15
|
+
return `Output file already exists: ${resolved}. Use --force to replace it.`;
|
|
16
|
+
}
|
|
17
|
+
function assertPathInsideRoot(resolvedPath, root = process.cwd()) {
|
|
18
|
+
const resolvedRoot = fs.realpathSync(path.resolve(root));
|
|
19
|
+
const canonicalPath = findCanonicalPath(resolvedPath);
|
|
20
|
+
const relative = path.relative(resolvedRoot, canonicalPath);
|
|
21
|
+
if (relative === '..' ||
|
|
22
|
+
relative.startsWith(`..${path.sep}`) ||
|
|
23
|
+
path.isAbsolute(relative)) {
|
|
24
|
+
throw new Error(`Refusing to write outside root: ${resolvedPath}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
// Resolve symlinks on the longest existing prefix of filePath, then put any
|
|
28
|
+
// missing trailing segments back (realpathSync cannot run on paths that do
|
|
29
|
+
// not exist yet).
|
|
30
|
+
function findCanonicalPath(filePath) {
|
|
31
|
+
let cursor = path.resolve(filePath);
|
|
32
|
+
const pending = [];
|
|
33
|
+
for (;;) {
|
|
34
|
+
try {
|
|
35
|
+
const canonical = fs.realpathSync(cursor);
|
|
36
|
+
return pending.length === 0
|
|
37
|
+
? canonical
|
|
38
|
+
: path.join(canonical, ...pending.reverse());
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
if (error.code !== 'ENOENT')
|
|
42
|
+
throw error;
|
|
43
|
+
pending.push(path.basename(cursor));
|
|
44
|
+
const parent = path.dirname(cursor);
|
|
45
|
+
if (parent === cursor) {
|
|
46
|
+
return cursor;
|
|
47
|
+
}
|
|
48
|
+
cursor = parent;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function assertWritableOutputFile(resolvedPath, { force = false, getExistsMessage = getDefaultExistsMessage, root = process.cwd(), } = {}) {
|
|
53
|
+
assertPathInsideRoot(resolvedPath, root);
|
|
54
|
+
let stat;
|
|
55
|
+
try {
|
|
56
|
+
stat = fs.lstatSync(resolvedPath);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
if (error.code !== 'ENOENT')
|
|
60
|
+
throw error;
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (!stat.isFile() || stat.isSymbolicLink()) {
|
|
64
|
+
throw new Error(`Refusing to overwrite non-regular file: ${resolvedPath}`);
|
|
65
|
+
}
|
|
66
|
+
if (!force) {
|
|
67
|
+
throw new Error(getExistsMessage(resolvedPath));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function writeOutputFile(resolvedPath, contents, { force = false, root = process.cwd(), } = {}) {
|
|
71
|
+
assertPathInsideRoot(resolvedPath, root);
|
|
72
|
+
fs.mkdirSync(path.dirname(resolvedPath), { recursive: true });
|
|
73
|
+
const flags = force
|
|
74
|
+
? fs.constants.O_WRONLY |
|
|
75
|
+
fs.constants.O_CREAT |
|
|
76
|
+
fs.constants.O_TRUNC |
|
|
77
|
+
fs.constants.O_NOFOLLOW
|
|
78
|
+
: 'wx';
|
|
79
|
+
const descriptor = fs.openSync(resolvedPath, flags);
|
|
80
|
+
try {
|
|
81
|
+
fs.writeFileSync(descriptor, contents, 'utf8');
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
fs.closeSync(descriptor);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
export { writeOutput, getDefaultExistsMessage as defaultExistsMessage, assertPathInsideRoot, assertWritableOutputFile, writeOutputFile, };
|
|
88
|
+
//# sourceMappingURL=writeOutput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writeOutput.js","sourceRoot":"","sources":["../../src/lib/writeOutput.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AA2B7B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EAC/C,oBAAoB,EACpB,wBAAwB,EACxB,eAAe,GAChB,CAAC","sourcesContent":["import fs from 'node:fs';\nimport path from 'node:path';\n\nexport type ExistsMessageGetter = (resolved: string) => string;\n\nexport interface WriteOutputOptions {\n force?: boolean;\n dryRun?: boolean;\n /** When true, skip preflight (caller already checked all targets). */\n skipAssert?: boolean;\n /**\n * Directory that output paths must remain inside after resolution.\n * Defaults to `process.cwd()`.\n */\n root?: string;\n}\n\nexport interface WriteOutputResult {\n path: string;\n written: boolean;\n}\n\nexport interface AssertWritableOptions {\n force?: boolean;\n getExistsMessage?: ExistsMessageGetter;\n root?: string;\n}\n\nfunction writeOutput(\n outPath: string,\n contents: string,\n {\n force = false,\n dryRun = false,\n skipAssert = false,\n getExistsMessage = getDefaultExistsMessage,\n root = process.cwd(),\n }: WriteOutputOptions & { getExistsMessage?: ExistsMessageGetter } = {},\n): WriteOutputResult {\n const resolved = path.resolve(outPath);\n assertPathInsideRoot(resolved, root);\n\n if (!skipAssert) {\n assertWritableOutputFile(resolved, { force, getExistsMessage, root });\n }\n if (!dryRun) {\n writeOutputFile(resolved, contents, { force, root });\n }\n return { path: resolved, written: !dryRun };\n}\n\nfunction getDefaultExistsMessage(resolved: string): string {\n return `Output file already exists: ${resolved}. Use --force to replace it.`;\n}\n\nfunction assertPathInsideRoot(\n resolvedPath: string,\n root: string = process.cwd(),\n): void {\n const resolvedRoot = fs.realpathSync(path.resolve(root));\n const canonicalPath = findCanonicalPath(resolvedPath);\n const relative = path.relative(resolvedRoot, canonicalPath);\n if (\n relative === '..' ||\n relative.startsWith(`..${path.sep}`) ||\n path.isAbsolute(relative)\n ) {\n throw new Error(`Refusing to write outside root: ${resolvedPath}`);\n }\n}\n\n// Resolve symlinks on the longest existing prefix of filePath, then put any\n// missing trailing segments back (realpathSync cannot run on paths that do\n// not exist yet).\nfunction findCanonicalPath(filePath: string): string {\n let cursor = path.resolve(filePath);\n const pending: string[] = [];\n for (;;) {\n try {\n const canonical = fs.realpathSync(cursor);\n return pending.length === 0\n ? canonical\n : path.join(canonical, ...pending.reverse());\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error;\n pending.push(path.basename(cursor));\n const parent = path.dirname(cursor);\n if (parent === cursor) {\n return cursor;\n }\n cursor = parent;\n }\n }\n}\n\nfunction assertWritableOutputFile(\n resolvedPath: string,\n {\n force = false,\n getExistsMessage = getDefaultExistsMessage,\n root = process.cwd(),\n }: AssertWritableOptions = {},\n): void {\n assertPathInsideRoot(resolvedPath, root);\n\n let stat;\n try {\n stat = fs.lstatSync(resolvedPath);\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error;\n return;\n }\n if (!stat.isFile() || stat.isSymbolicLink()) {\n throw new Error(`Refusing to overwrite non-regular file: ${resolvedPath}`);\n }\n if (!force) {\n throw new Error(getExistsMessage(resolvedPath));\n }\n}\n\nfunction writeOutputFile(\n resolvedPath: string,\n contents: string,\n {\n force = false,\n root = process.cwd(),\n }: { force?: boolean; root?: string } = {},\n): void {\n assertPathInsideRoot(resolvedPath, root);\n fs.mkdirSync(path.dirname(resolvedPath), { recursive: true });\n const flags = force\n ? fs.constants.O_WRONLY |\n fs.constants.O_CREAT |\n fs.constants.O_TRUNC |\n fs.constants.O_NOFOLLOW\n : 'wx';\n const descriptor = fs.openSync(resolvedPath, flags);\n try {\n fs.writeFileSync(descriptor, contents, 'utf8');\n } finally {\n fs.closeSync(descriptor);\n }\n}\n\nexport {\n writeOutput,\n getDefaultExistsMessage as defaultExistsMessage,\n assertPathInsideRoot,\n assertWritableOutputFile,\n writeOutputFile,\n};\n"]}
|