sdtk-design-kit 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.
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ function parseFlags(args, defs = {}) {
4
+ const flags = {};
5
+ const positionals = [];
6
+ const input = Array.isArray(args) ? args : [];
7
+
8
+ for (let index = 0; index < input.length; index += 1) {
9
+ const arg = input[index];
10
+ if (arg === "--") {
11
+ positionals.push(...input.slice(index + 1));
12
+ break;
13
+ }
14
+ if (!arg.startsWith("-") || arg === "-") {
15
+ positionals.push(arg);
16
+ continue;
17
+ }
18
+ const raw = arg.replace(/^-+/, "");
19
+ const [name, inlineValue] = raw.split(/=(.*)/s).filter((part) => part !== undefined);
20
+ const def = defs[name];
21
+ if (!def) {
22
+ positionals.push(arg);
23
+ continue;
24
+ }
25
+ if (def.type === "boolean") {
26
+ flags[name] = inlineValue === undefined ? true : inlineValue !== "false";
27
+ continue;
28
+ }
29
+ if (inlineValue !== undefined) {
30
+ flags[name] = inlineValue;
31
+ continue;
32
+ }
33
+ const value = input[index + 1];
34
+ if (value === undefined || value.startsWith("-")) {
35
+ flags[name] = "";
36
+ continue;
37
+ }
38
+ flags[name] = value;
39
+ index += 1;
40
+ }
41
+
42
+ return { flags, positionals };
43
+ }
44
+
45
+ module.exports = {
46
+ parseFlags,
47
+ };
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+
3
+ const path = require("path");
4
+
5
+ const DESIGN_DOCS_RELATIVE = path.join("docs", "design");
6
+ const DESIGN_WIREFRAMES_RELATIVE = path.join("docs", "design", "wireframes");
7
+ const DESIGN_REVIEWS_RELATIVE = path.join("docs", "design", "reviews");
8
+ const DESIGN_README_RELATIVE = path.join("docs", "design", "README.md");
9
+ const DESIGN_BRIEF_RELATIVE = path.join("docs", "design", "DESIGN_BRIEF.md");
10
+ const DESIGN_SCREEN_MAP_RELATIVE = path.join("docs", "design", "SCREEN_MAP.md");
11
+ const DESIGN_SYSTEM_RELATIVE = path.join("docs", "design", "DESIGN_SYSTEM.md");
12
+ const DESIGN_HANDOFF_RELATIVE = path.join("docs", "design", "DESIGN_HANDOFF.md");
13
+ const DESIGN_STATE_RELATIVE = path.join(".sdtk", "design");
14
+ const DESIGN_MANIFEST_RELATIVE = path.join(".sdtk", "design", "manifest.json");
15
+
16
+ function resolveProjectPath(projectPath) {
17
+ return path.resolve(projectPath || process.cwd());
18
+ }
19
+
20
+ function normalizeComparablePath(targetPath) {
21
+ const resolved = path.resolve(targetPath);
22
+ return process.platform === "win32" ? resolved.toLowerCase() : resolved;
23
+ }
24
+
25
+ function isPathInsideOrEqual(targetPath, rootPath) {
26
+ const comparableTarget = normalizeComparablePath(targetPath);
27
+ const comparableRoot = normalizeComparablePath(rootPath);
28
+ return comparableTarget === comparableRoot || comparableTarget.startsWith(comparableRoot + path.sep);
29
+ }
30
+
31
+ function assertProjectLocalPath(targetPath, projectPath, label = "path") {
32
+ const resolvedProject = resolveProjectPath(projectPath);
33
+ const resolvedTarget = path.resolve(targetPath);
34
+ if (!isPathInsideOrEqual(resolvedTarget, resolvedProject)) {
35
+ throw new Error(`Refusing to access ${label} outside project root: ${resolvedTarget}`);
36
+ }
37
+ return resolvedTarget;
38
+ }
39
+
40
+ function describeDesignPaths(projectPath) {
41
+ const root = resolveProjectPath(projectPath);
42
+ return {
43
+ projectPath: root,
44
+ designDocsPath: path.join(root, DESIGN_DOCS_RELATIVE),
45
+ wireframesPath: path.join(root, DESIGN_WIREFRAMES_RELATIVE),
46
+ reviewsPath: path.join(root, DESIGN_REVIEWS_RELATIVE),
47
+ designReadmePath: path.join(root, DESIGN_README_RELATIVE),
48
+ designBriefPath: path.join(root, DESIGN_BRIEF_RELATIVE),
49
+ screenMapPath: path.join(root, DESIGN_SCREEN_MAP_RELATIVE),
50
+ designSystemPath: path.join(root, DESIGN_SYSTEM_RELATIVE),
51
+ designHandoffPath: path.join(root, DESIGN_HANDOFF_RELATIVE),
52
+ designStatePath: path.join(root, DESIGN_STATE_RELATIVE),
53
+ manifestPath: path.join(root, DESIGN_MANIFEST_RELATIVE),
54
+ };
55
+ }
56
+
57
+ module.exports = {
58
+ DESIGN_BRIEF_RELATIVE,
59
+ DESIGN_DOCS_RELATIVE,
60
+ DESIGN_HANDOFF_RELATIVE,
61
+ DESIGN_MANIFEST_RELATIVE,
62
+ DESIGN_README_RELATIVE,
63
+ DESIGN_REVIEWS_RELATIVE,
64
+ DESIGN_SCREEN_MAP_RELATIVE,
65
+ DESIGN_STATE_RELATIVE,
66
+ DESIGN_SYSTEM_RELATIVE,
67
+ DESIGN_WIREFRAMES_RELATIVE,
68
+ assertProjectLocalPath,
69
+ describeDesignPaths,
70
+ isPathInsideOrEqual,
71
+ resolveProjectPath,
72
+ };
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ class CliError extends Error {
4
+ constructor(message, exitCode = 4) {
5
+ super(message);
6
+ this.name = "CliError";
7
+ this.exitCode = exitCode;
8
+ }
9
+ }
10
+
11
+ class ValidationError extends CliError {
12
+ constructor(message) {
13
+ super(message, 2);
14
+ this.name = "ValidationError";
15
+ }
16
+ }
17
+
18
+ module.exports = {
19
+ CliError,
20
+ ValidationError,
21
+ };