@figma/code-connect 0.1.1 → 0.2.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.
Files changed (118) hide show
  1. package/README.md +123 -25
  2. package/dist/cli.js +7 -0
  3. package/dist/cli.js.map +1 -1
  4. package/dist/commands/connect.d.ts +15 -0
  5. package/dist/commands/connect.d.ts.map +1 -1
  6. package/dist/commands/connect.js +140 -79
  7. package/dist/commands/connect.js.map +1 -1
  8. package/dist/common/__test__/project.test.d.ts +2 -0
  9. package/dist/common/__test__/project.test.d.ts.map +1 -0
  10. package/dist/common/__test__/project.test.js +14 -0
  11. package/dist/common/__test__/project.test.js.map +1 -0
  12. package/dist/common/api.d.ts +77 -5
  13. package/dist/common/api.d.ts.map +1 -1
  14. package/dist/common/external.d.ts +7 -3
  15. package/dist/common/external.d.ts.map +1 -1
  16. package/dist/common/external.js +13 -1
  17. package/dist/common/external.js.map +1 -1
  18. package/dist/common/figma_connect.d.ts +12 -10
  19. package/dist/common/figma_connect.d.ts.map +1 -1
  20. package/dist/common/intrinsics.d.ts +39 -7
  21. package/dist/common/intrinsics.d.ts.map +1 -1
  22. package/dist/common/intrinsics.js +166 -30
  23. package/dist/common/intrinsics.js.map +1 -1
  24. package/dist/common/logging.d.ts +9 -0
  25. package/dist/common/logging.d.ts.map +1 -1
  26. package/dist/common/logging.js +21 -1
  27. package/dist/common/logging.js.map +1 -1
  28. package/dist/common/updates.d.ts +4 -0
  29. package/dist/common/updates.d.ts.map +1 -0
  30. package/dist/common/updates.js +87 -0
  31. package/dist/common/updates.js.map +1 -0
  32. package/dist/connect/create.d.ts +5 -1
  33. package/dist/connect/create.d.ts.map +1 -1
  34. package/dist/connect/create.js +55 -69
  35. package/dist/connect/create.js.map +1 -1
  36. package/dist/connect/delete_docs.d.ts.map +1 -1
  37. package/dist/connect/delete_docs.js +1 -4
  38. package/dist/connect/delete_docs.js.map +1 -1
  39. package/dist/connect/figma_rest_api.d.ts +5 -0
  40. package/dist/connect/figma_rest_api.d.ts.map +1 -1
  41. package/dist/connect/figma_rest_api.js +10 -1
  42. package/dist/connect/figma_rest_api.js.map +1 -1
  43. package/dist/connect/helpers.d.ts +1 -1
  44. package/dist/connect/helpers.d.ts.map +1 -1
  45. package/dist/connect/helpers.js +6 -5
  46. package/dist/connect/helpers.js.map +1 -1
  47. package/dist/connect/parser_executable_types.d.ts +298 -0
  48. package/dist/connect/parser_executable_types.d.ts.map +1 -0
  49. package/dist/connect/parser_executable_types.js +108 -0
  50. package/dist/connect/parser_executable_types.js.map +1 -0
  51. package/dist/connect/parser_executables.d.ts +8 -0
  52. package/dist/connect/parser_executables.d.ts.map +1 -0
  53. package/dist/connect/parser_executables.js +132 -0
  54. package/dist/connect/parser_executables.js.map +1 -0
  55. package/dist/connect/project.d.ts +137 -0
  56. package/dist/connect/project.d.ts.map +1 -0
  57. package/dist/connect/project.js +411 -0
  58. package/dist/connect/project.js.map +1 -0
  59. package/dist/connect/upload.d.ts.map +1 -1
  60. package/dist/connect/upload.js +2 -5
  61. package/dist/connect/upload.js.map +1 -1
  62. package/dist/connect/validation.d.ts +6 -1
  63. package/dist/connect/validation.d.ts.map +1 -1
  64. package/dist/connect/validation.js +12 -12
  65. package/dist/connect/validation.js.map +1 -1
  66. package/dist/connect/wizard/helpers.d.ts +7 -0
  67. package/dist/connect/wizard/helpers.d.ts.map +1 -0
  68. package/dist/connect/wizard/helpers.js +55 -0
  69. package/dist/connect/wizard/helpers.js.map +1 -0
  70. package/dist/connect/wizard/run_wizard.d.ts +3 -0
  71. package/dist/connect/wizard/run_wizard.d.ts.map +1 -0
  72. package/dist/connect/wizard/run_wizard.js +479 -0
  73. package/dist/connect/wizard/run_wizard.js.map +1 -0
  74. package/dist/parser_scripts/get_file_if_exists.d.ts +2 -0
  75. package/dist/parser_scripts/get_file_if_exists.d.ts.map +1 -0
  76. package/dist/parser_scripts/get_file_if_exists.js +10 -0
  77. package/dist/parser_scripts/get_file_if_exists.js.map +1 -0
  78. package/dist/parser_scripts/get_gradlew_path.d.ts +3 -0
  79. package/dist/parser_scripts/get_gradlew_path.d.ts.map +1 -0
  80. package/dist/parser_scripts/get_gradlew_path.js +24 -0
  81. package/dist/parser_scripts/get_gradlew_path.js.map +1 -0
  82. package/dist/parser_scripts/get_swift_parser_dir.d.ts +2 -0
  83. package/dist/parser_scripts/get_swift_parser_dir.d.ts.map +1 -0
  84. package/dist/parser_scripts/get_swift_parser_dir.js +93 -0
  85. package/dist/parser_scripts/get_swift_parser_dir.js.map +1 -0
  86. package/dist/react/create.d.ts +4 -0
  87. package/dist/react/create.d.ts.map +1 -0
  88. package/dist/react/create.js +132 -0
  89. package/dist/react/create.js.map +1 -0
  90. package/dist/{common → react}/parser.d.ts +6 -15
  91. package/dist/react/parser.d.ts.map +1 -0
  92. package/dist/{common → react}/parser.js +223 -172
  93. package/dist/react/parser.js.map +1 -0
  94. package/dist/react/parser_template_helpers.d.ts +23 -0
  95. package/dist/react/parser_template_helpers.d.ts.map +1 -0
  96. package/dist/react/parser_template_helpers.js +126 -0
  97. package/dist/react/parser_template_helpers.js.map +1 -0
  98. package/dist/storybook/convert.d.ts +2 -2
  99. package/dist/storybook/convert.d.ts.map +1 -1
  100. package/dist/storybook/convert.js +11 -7
  101. package/dist/storybook/convert.js.map +1 -1
  102. package/dist/{common → typescript}/compiler.d.ts +1 -1
  103. package/dist/typescript/compiler.d.ts.map +1 -0
  104. package/dist/{common → typescript}/compiler.js +21 -2
  105. package/dist/typescript/compiler.js.map +1 -0
  106. package/package.json +36 -11
  107. package/dist/common/compiler.d.ts.map +0 -1
  108. package/dist/common/compiler.js.map +0 -1
  109. package/dist/common/parser.d.ts.map +0 -1
  110. package/dist/common/parser.js.map +0 -1
  111. package/dist/common/parser_template_helpers.d.ts +0 -2
  112. package/dist/common/parser_template_helpers.d.ts.map +0 -1
  113. package/dist/common/parser_template_helpers.js +0 -58
  114. package/dist/common/parser_template_helpers.js.map +0 -1
  115. package/dist/common/project.d.ts +0 -84
  116. package/dist/common/project.d.ts.map +0 -1
  117. package/dist/common/project.js +0 -179
  118. package/dist/common/project.js.map +0 -1
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CreateResponsePayload = exports.ParseResponsePayload = exports.ParserExecutableMessages = void 0;
4
+ const zod_1 = require("zod");
5
+ const FigmaConnectLink = zod_1.z.object({
6
+ name: zod_1.z.string(),
7
+ url: zod_1.z.string(),
8
+ });
9
+ exports.ParserExecutableMessages = zod_1.z.array(zod_1.z.object({
10
+ // DEBUG and INFO messages should be output to console by the CLI for the
11
+ // user to read, according to the current log level setting.
12
+ //
13
+ // If any WARNING or ERROR messages are returned, the CLI can determine
14
+ // whether it should proceed with publishing or not based on configuration
15
+ // and the return code should be zero or non-zero as appropriate.
16
+ //
17
+ // There's no need for a "result" field as we can infer this from the
18
+ // messages.
19
+ level: zod_1.z.union([zod_1.z.literal('DEBUG'), zod_1.z.literal('INFO'), zod_1.z.literal('WARN'), zod_1.z.literal('ERROR')]),
20
+ // Optional type of message which can be displayed highlighted in the output
21
+ type: zod_1.z.string().optional(),
22
+ message: zod_1.z.string(),
23
+ // Optional source location which can be displayed in a standardised form
24
+ sourceLocation: zod_1.z
25
+ .object({
26
+ file: zod_1.z.string(),
27
+ line: zod_1.z.number().optional(),
28
+ })
29
+ .optional(),
30
+ }));
31
+ // Zod type modelling the response from a Code Connect parser. Zod allows us to
32
+ // easily validate the response.
33
+ //
34
+ // This type somewhat duplicates the `CodeConnectJSON` type from
35
+ // `figma_connect.ts`, but as Zod doesn't allow us to fully express recursive
36
+ // types such as Intrinsic, we keep this explicit type as well. The `satisfies`
37
+ // should ensure the two types stay in sync.
38
+ exports.ParseResponsePayload = zod_1.z.object({
39
+ // Array of Code Connect docs parsed from the input files
40
+ docs: zod_1.z.array(zod_1.z.object({
41
+ // The Figma node URL the doc links to
42
+ figmaNode: zod_1.z.string(),
43
+ // Optional component name. This is only used for display purposes
44
+ // so can be omitted if it's not relevant to the language/framework
45
+ component: zod_1.z.string().optional(),
46
+ // Variant restrictions keyed by Figma property name e.g. `{ 'With icon': true }`
47
+ variant: zod_1.z.record(zod_1.z.any()).optional(),
48
+ // Optional source path/URL, which can either be a path on disk, which
49
+ // we'll show as a SCM link, or a URL (e.g. for a Storybook parser which
50
+ // wants to link to the story in Storybook rather than the file in Github)
51
+ source: zod_1.z.string().optional(),
52
+ // Optional source location containing line number information.
53
+ sourceLocation: zod_1.z
54
+ .object({
55
+ // Optional line number to link to. This is only used if type === 'PATH',
56
+ // to generate a link to the correct line
57
+ line: zod_1.z.number(),
58
+ })
59
+ .optional(),
60
+ // The JS template function to use for this doc
61
+ template: zod_1.z.string(),
62
+ templateData: zod_1.z.object({
63
+ // Map of information describing the props used by the template. This is
64
+ // used by the CLI to validate props before publishing.
65
+ //
66
+ // TODO this Zod type is a bit loose - couldn't work out how to model it exactly
67
+ //
68
+ // TODO We could look to extract this from the template somehow instead,
69
+ // (e.g. run it with figma.properties.* stubbed to record accesses) to
70
+ // avoid needing this duplication.
71
+ props: zod_1.z.record(zod_1.z.object({ kind: zod_1.z.string(), args: zod_1.z.any() })),
72
+ // Optional array of imports for this component. These are prepended
73
+ // to the example code, but it's useful to keep them separate e.g. if
74
+ // we ever want to auto-insert imports in VS Code. If more control
75
+ // over imports is required, they can be output directly by the template
76
+ // function. Currently they'd have to be output in the code directly, but
77
+ // the original spec does propose templates being able to return import
78
+ // sections separately (not implemented as there's no UI for this)
79
+ //
80
+ // Right now, there's no way to handle gathering imports from children and
81
+ // post-processing them (e.g. combining multiple imports from the same file
82
+ // into a single import). We could consider some way for templates to do this
83
+ // in future.
84
+ imports: zod_1.z.array(zod_1.z.string()).optional(),
85
+ // Whether the example should be rendered inline if it's a nested instance
86
+ nestable: zod_1.z.boolean().optional(),
87
+ }),
88
+ // The language to use for syntax highlighting
89
+ language: zod_1.z.string(),
90
+ // Label to be used for the example in the UI
91
+ label: zod_1.z.string(),
92
+ // Optional array of links to be displayed in the UI.
93
+ // TODO Not implemented in UI yet
94
+ links: zod_1.z.array(FigmaConnectLink).optional(),
95
+ })),
96
+ // Any info, warning or error messages generated during parsing.
97
+ messages: exports.ParserExecutableMessages,
98
+ });
99
+ exports.CreateResponsePayload = zod_1.z.object({
100
+ // A list of files created, which can be output to the console
101
+ createdFiles: zod_1.z.array(zod_1.z.object({
102
+ // The absolute path of the created file
103
+ filePath: zod_1.z.string(),
104
+ })),
105
+ // Any info, warning or error messages generated during creation.
106
+ messages: exports.ParserExecutableMessages,
107
+ });
108
+ //# sourceMappingURL=parser_executable_types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser_executable_types.js","sourceRoot":"","sources":["../../src/connect/parser_executable_types.ts"],"names":[],"mappings":";;;AAAA,6BAAuB;AAevB,MAAM,gBAAgB,GAAG,OAAC,CAAC,MAAM,CAAC;IAChC,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;IAChB,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE;CAChB,CAAC,CAAA;AAEW,QAAA,wBAAwB,GAAG,OAAC,CAAC,KAAK,CAC7C,OAAC,CAAC,MAAM,CAAC;IACP,yEAAyE;IACzE,4DAA4D;IAC5D,EAAE;IACF,uEAAuE;IACvE,0EAA0E;IAC1E,iEAAiE;IACjE,EAAE;IACF,qEAAqE;IACrE,YAAY;IACZ,KAAK,EAAE,OAAC,CAAC,KAAK,CAAC,CAAC,OAAC,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,OAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,OAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,OAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IAC9F,4EAA4E;IAC5E,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC3B,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE;IACnB,yEAAyE;IACzE,cAAc,EAAE,OAAC;SAC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,EAAE,IAAI,EAAE,OAAC,CAAC,GAAG,EAAE,EAAE,CAA6B,CAAC;YAC1F,oEAAoE;YACpE,qEAAqE;YACrE,kEAAkE;YAClE,wEAAwE;YACxE,yEAAyE;YACzE,uEAAuE;YACvE,kEAAkE;YAClE,EAAE;YACF,0EAA0E;YAC1E,2EAA2E;YAC3E,6EAA6E;YAC7E,aAAa;YACb,OAAO,EAAE,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;YACvC,0EAA0E;YAC1E,QAAQ,EAAE,OAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;SACjC,CAAC;QACF,8CAA8C;QAC9C,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE;QACpB,6CAA6C;QAC7C,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE;QACjB,qDAAqD;QACrD,iCAAiC;QACjC,KAAK,EAAE,OAAC,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,QAAQ,EAAE;KAC5C,CAA4C,CAC9C;IACD,gEAAgE;IAChE,QAAQ,EAAE,gCAAwB;CACnC,CAAC,CAAA;AA8CW,QAAA,qBAAqB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC5C,8DAA8D;IAC9D,YAAY,EAAE,OAAC,CAAC,KAAK,CACnB,OAAC,CAAC,MAAM,CAAC;QACP,wCAAwC;QACxC,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE;KACrB,CAAC,CACH;IACD,iEAAiE;IACjE,QAAQ,EAAE,gCAAwB;CACnC,CAAC,CAAA"}
@@ -0,0 +1,8 @@
1
+ import { z } from 'zod';
2
+ import { CodeConnectExecutableParserConfig } from './project';
3
+ import { ParserExecutableMessages, ParserRequestPayload } from './parser_executable_types';
4
+ export declare function callParser(config: CodeConnectExecutableParserConfig, payload: ParserRequestPayload, cwd: string): Promise<object>;
5
+ export declare function handleMessages(messages: z.infer<typeof ParserExecutableMessages>): {
6
+ hasErrors: boolean;
7
+ };
8
+ //# sourceMappingURL=parser_executables.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser_executables.d.ts","sourceRoot":"","sources":["../../src/connect/parser_executables.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,iCAAiC,EAA8B,MAAM,WAAW,CAAA;AACzF,OAAO,EAEL,wBAAwB,EACxB,oBAAoB,EACrB,MAAM,2BAA2B,CAAA;AAwDlC,wBAAsB,UAAU,CAC9B,MAAM,EAAE,iCAAiC,EACzC,OAAO,EAAE,oBAAoB,EAC7B,GAAG,EAAE,MAAM,mBAqEZ;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC;;EAqBhF"}
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.handleMessages = exports.callParser = void 0;
7
+ const logging_1 = require("../common/logging");
8
+ const cross_spawn_1 = require("cross-spawn");
9
+ const get_swift_parser_dir_1 = require("../parser_scripts/get_swift_parser_dir");
10
+ const fs_1 = __importDefault(require("fs"));
11
+ const path_1 = __importDefault(require("path"));
12
+ const get_gradlew_path_1 = require("../parser_scripts/get_gradlew_path");
13
+ const temporaryInputFilePath = 'tmp/figma-code-connect-parser-input.json.tmp';
14
+ const FIRST_PARTY_PARSERS = {
15
+ swift: {
16
+ command: async (cwd, config, mode) => {
17
+ return `swift run --package-path ${await (0, get_swift_parser_dir_1.getSwiftParserDir)(cwd, config.xcodeprojPath)} figma-swift`;
18
+ },
19
+ },
20
+ compose: {
21
+ command: async (cwd, config, mode) => {
22
+ const gradlewPath = await (0, get_gradlew_path_1.getGradleWrapperPath)(cwd, config.gradleWrapperPath);
23
+ const gradleExecutableInvocation = (0, get_gradlew_path_1.getGradleWrapperExecutablePath)(gradlewPath);
24
+ if (mode === 'CREATE') {
25
+ return `${gradleExecutableInvocation} -p ${gradlewPath} createCodeConnect -PfilePath=${temporaryInputFilePath} -q`;
26
+ }
27
+ else {
28
+ return `${gradleExecutableInvocation} -p ${gradlewPath} parseCodeConnect -PfilePath=${temporaryInputFilePath} -q`;
29
+ }
30
+ },
31
+ temporaryInputFilePath: temporaryInputFilePath,
32
+ },
33
+ __unit_test__: {
34
+ command: async () => 'node parser/unit_test_parser.js',
35
+ },
36
+ };
37
+ function getParser(config) {
38
+ const parser = FIRST_PARTY_PARSERS[config.parser];
39
+ if (!parser) {
40
+ (0, logging_1.exitWithError)(`Invalid parser specified: "${config.parser}". Valid parsers are: ${Object.keys(FIRST_PARTY_PARSERS).join(', ')}.`);
41
+ }
42
+ return parser;
43
+ }
44
+ async function callParser(config, payload, cwd) {
45
+ return new Promise(async (resolve, reject) => {
46
+ try {
47
+ const parser = getParser(config);
48
+ const command = await parser.command(cwd, config, payload.mode);
49
+ if (parser.temporaryInputFilePath) {
50
+ fs_1.default.mkdirSync(path_1.default.dirname(parser.temporaryInputFilePath), { recursive: true });
51
+ fs_1.default.writeFileSync(temporaryInputFilePath, JSON.stringify(payload));
52
+ }
53
+ logging_1.logger.debug(`Running parser: ${command}`);
54
+ const commandSplit = command.split(' ');
55
+ const child = (0, cross_spawn_1.spawn)(commandSplit[0], commandSplit.slice(1), {
56
+ cwd,
57
+ });
58
+ let stdout = '';
59
+ child.stdout.on('data', (data) => {
60
+ stdout += data.toString();
61
+ });
62
+ // This handles any stderr output from the parser.
63
+ //
64
+ // Parsers should not generally write to stderr, and should instead return
65
+ // an array of messages at the end of execution, but there are cases where
66
+ // you might want to log output immediately rather than at the end of the
67
+ // run - e.g. if the parser can take a while to compile first time, you
68
+ // might want to inform the user immediately that it is compiling.
69
+ //
70
+ // To log output, the parser should write a JSON object to stderr with the
71
+ // same structure as the `messages` response object, e.g. `{ "level":
72
+ // "INFO", "message": "Compiling parser..." }`.
73
+ //
74
+ // Non-JSON output will be logged as debug messages, as this is likely to
75
+ // be e.g. compiler output which the user doesn't need to see ordinarily.
76
+ child.stderr.on('data', (data) => {
77
+ const message = data.toString().trim();
78
+ try {
79
+ const parsed = JSON.parse(message);
80
+ handleMessages([parsed]);
81
+ }
82
+ catch (e) {
83
+ logging_1.logger.debug(message);
84
+ }
85
+ });
86
+ child.on('close', (code) => {
87
+ if (code !== 0) {
88
+ reject(new Error(`Parser exited with code ${code}`));
89
+ }
90
+ else {
91
+ resolve(JSON.parse(stdout));
92
+ }
93
+ if (parser.temporaryInputFilePath) {
94
+ fs_1.default.unlinkSync(parser.temporaryInputFilePath);
95
+ }
96
+ });
97
+ child.on('error', (e) => {
98
+ reject(e);
99
+ });
100
+ if (!parser.temporaryInputFilePath) {
101
+ child.stdin.write(JSON.stringify(payload));
102
+ child.stdin.end();
103
+ }
104
+ }
105
+ catch (e) {
106
+ (0, logging_1.exitWithError)(`Error calling parser: ${e}`);
107
+ }
108
+ });
109
+ }
110
+ exports.callParser = callParser;
111
+ function handleMessages(messages) {
112
+ let hasErrors = false;
113
+ messages.forEach((message) => {
114
+ switch (message.level) {
115
+ case 'DEBUG':
116
+ logging_1.logger.debug(message.message);
117
+ break;
118
+ case 'INFO':
119
+ logging_1.logger.info(message.message);
120
+ break;
121
+ case 'WARN':
122
+ logging_1.logger.warn(message.message);
123
+ break;
124
+ case 'ERROR':
125
+ logging_1.logger.error(message.message);
126
+ break;
127
+ }
128
+ });
129
+ return { hasErrors };
130
+ }
131
+ exports.handleMessages = handleMessages;
132
+ //# sourceMappingURL=parser_executables.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser_executables.js","sourceRoot":"","sources":["../../src/connect/parser_executables.ts"],"names":[],"mappings":";;;;;;AACA,+CAAyD;AAOzD,6CAAmC;AACnC,iFAA0E;AAC1E,4CAAmB;AACnB,gDAAuB;AACvB,yEAG2C;AAE3C,MAAM,sBAAsB,GAAG,8CAA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AAE,CAAC,CAAA;QAC7C,CAAC;IACH,CAAC,CAAC,CAAA;AACJ,CAAC;AAxED,gCAwEC;AAED,SAAgB,cAAc,CAAC,QAAkD;IAC/E,IAAI,SAAS,GAAG,KAAK,CAAA;IAErB,QAAQ,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC3B,QAAQ,OAAO,CAAC,KAAK,EAAE,CAAC;YACtB,KAAK,OAAO;gBACV,gBAAM,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;gBAC7B,MAAK;YACP,KAAK,MAAM;gBACT,gBAAM,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;gBAC5B,MAAK;YACP,KAAK,MAAM;gBACT,gBAAM,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;gBAC5B,MAAK;YACP,KAAK,OAAO;gBACV,gBAAM,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;gBAC7B,MAAK;QACT,CAAC;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,EAAE,SAAS,EAAE,CAAA;AACtB,CAAC;AArBD,wCAqBC"}
@@ -0,0 +1,137 @@
1
+ import ts from 'typescript';
2
+ export declare const DEFAULT_INCLUDE_GLOBS_BY_PARSER: {
3
+ react: string[];
4
+ swift: string[];
5
+ compose: string[];
6
+ __unit_test__: string[];
7
+ };
8
+ export type FirstPartyExecutableParser = 'swift' | 'compose' | '__unit_test__';
9
+ export type FirstPartyParser = 'react' | FirstPartyExecutableParser;
10
+ type BaseCodeConnectConfig = {
11
+ /**
12
+ * Specify glob patterns for files (relative to the project root) to be
13
+ * included when looking for source files. If not specified, all files
14
+ * (except any specified in `exclude`) will be included.
15
+ */
16
+ include?: string[];
17
+ /**
18
+ * Specify glob patterns for files (relative to the project root) to be
19
+ * excluded when looking for source files. If not specified, only
20
+ * `node_modules` will be excluded.
21
+ */
22
+ exclude?: string[];
23
+ /**
24
+ * Optional object of substitutions applied to document URLs (in the format {
25
+ * fromString, toString }) for testing (e.g. remapping a production URL to a
26
+ * staging URL). Not publicly documented.
27
+ */
28
+ documentUrlSubstitutions?: Record<string, string>;
29
+ /**
30
+ * The parser name, if using an internal parser.
31
+ */
32
+ parser: FirstPartyParser;
33
+ };
34
+ export type CodeConnectExecutableParserConfig = BaseCodeConnectConfig & {
35
+ parser: FirstPartyExecutableParser;
36
+ };
37
+ /**
38
+ * React specific configuration
39
+ */
40
+ export type CodeConnectReactConfig = BaseCodeConnectConfig & {
41
+ parser: 'react';
42
+ /**
43
+ * Maps imports from their path on disk to the specified path.
44
+ * This will rewrite the imports in generated code examples, so it works with
45
+ * relative imports such as `import { Button } from "./"`.
46
+ *
47
+ * Example: { "src/components/*": "@ui/components" }
48
+ * Would rewrite imports for components located in `src/components` to `@ui/components` in
49
+ * generated code examples.
50
+ * `import { Button } from "./"` -> `import { Button } from "@ui/components/Button"`
51
+ */
52
+ importPaths?: Record<string, string>;
53
+ /**
54
+ * For import resolution - this is a temporary solution to support projects that use
55
+ * pnpm workspaces, as the compiler doesn't seem to be able to resolve imports when
56
+ * the package in node_modules is a symlink. Need to look into this more and find a
57
+ * better solution.
58
+ */
59
+ paths?: Record<string, string[]>;
60
+ /**
61
+ * Storybook specific configuration
62
+ */
63
+ storybook?: {
64
+ /**
65
+ * The URL of the Storybook instance for the project
66
+ */
67
+ url: string;
68
+ };
69
+ };
70
+ export type CodeConnectConfig = CodeConnectReactConfig | CodeConnectExecutableParserConfig | BaseCodeConnectConfig;
71
+ export declare function determineParserFromProject(dir: string): FirstPartyParser | undefined;
72
+ export declare function getGitRemoteURL(repoPath: string): string;
73
+ /**
74
+ * Uses `git rev-parse` to find absolute path to the root of the git repository
75
+ */
76
+ export declare function getGitRepoAbsolutePath(filePath: string): string;
77
+ /**
78
+ * Find the default branch name (master or main) for the git repository
79
+ */
80
+ export declare function getGitRepoDefaultBranchName(repoPath: string): "master" | "main";
81
+ /**
82
+ * Finds the URL of a remote file
83
+ * @param filePath absolute file path on disk
84
+ * @param repoURL remote URL
85
+ * @returns
86
+ */
87
+ export declare function getRemoteFileUrl(filePath: string, repoURL?: string): string;
88
+ export declare function getStorybookUrl(filePath: string, storybookUrl: string): string;
89
+ export type ProjectInfo<ConfigT = CodeConnectConfig> = {
90
+ /**
91
+ * Absolute path of the project directory
92
+ */
93
+ absPath: string;
94
+ /**
95
+ * An array of all tsx files in the project
96
+ */
97
+ files: string[];
98
+ /**
99
+ * The git remote URL of the project
100
+ */
101
+ remoteUrl: string;
102
+ /**
103
+ * The parsed Code Connect config file
104
+ */
105
+ config: ConfigT;
106
+ };
107
+ export type ReactProjectInfo = ProjectInfo<CodeConnectReactConfig> & {
108
+ /**
109
+ * TS program containing all tsx files in the project
110
+ */
111
+ tsProgram: ts.Program;
112
+ };
113
+ export declare function getDefaultConfigPath(dir: string): string;
114
+ export declare function parseOrDetermineConfig(dir: string, configPath: string): Promise<{
115
+ config: CodeConnectConfig;
116
+ hasConfigFile: boolean;
117
+ }>;
118
+ /**
119
+ * Gets information about a project from config.
120
+ *
121
+ * @param dir Directory containing the project
122
+ * @param config Code Connect config
123
+ * @returns Object containing information about the project
124
+ */
125
+ export declare function getProjectInfoFromConfig(dir: string, config: CodeConnectConfig): Promise<ProjectInfo>;
126
+ /**
127
+ * Gets information about a project from a directory.
128
+ *
129
+ * @param dir Directory containing the project
130
+ * @param configPath Optional path to Code Connect config file
131
+ * @returns Object containing information about the project
132
+ */
133
+ export declare function getProjectInfo(dir: string, configPath: string): Promise<ProjectInfo>;
134
+ export declare function getReactProjectInfo(projectInfo: ProjectInfo<CodeConnectReactConfig>): ReactProjectInfo;
135
+ export declare function resolveImportPath(filePath: string, config: CodeConnectReactConfig): string | null;
136
+ export {};
137
+ //# sourceMappingURL=project.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/connect/project.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,YAAY,CAAA;AAS3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