@carbon/cli 10.29.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 +201 -0
- package/README.md +57 -0
- package/bin/carbon-cli.js +46 -0
- package/docker-compose.yml +13 -0
- package/package.json +56 -0
- package/src/changelog.js +217 -0
- package/src/cli.js +39 -0
- package/src/commands/bundle/bundlers.js +14 -0
- package/src/commands/bundle/javascript.js +142 -0
- package/src/commands/bundle.js +67 -0
- package/src/commands/changelog.js +70 -0
- package/src/commands/check.js +71 -0
- package/src/commands/ci-check.js +51 -0
- package/src/commands/component.js +130 -0
- package/src/commands/contribute/setup.js +232 -0
- package/src/commands/contribute/tools/getGitHubClient.js +73 -0
- package/src/commands/contribute.js +16 -0
- package/src/commands/inline.js +170 -0
- package/src/commands/publish.js +274 -0
- package/src/commands/release.js +302 -0
- package/src/commands/sassdoc/tools.js +405 -0
- package/src/commands/sassdoc.js +90 -0
- package/src/commands/sync/npm.js +43 -0
- package/src/commands/sync/package.js +122 -0
- package/src/commands/sync/readme.js +68 -0
- package/src/commands/sync/remark/remark-monorepo.js +425 -0
- package/src/commands/sync.js +39 -0
- package/src/compile.js +26 -0
- package/src/component/index.js +47 -0
- package/src/component/templates/component.template.js +19 -0
- package/src/component/templates/index.template.js +9 -0
- package/src/component/templates/mdx.template.mdx +37 -0
- package/src/component/templates/story.template.js +22 -0
- package/src/component/templates/test.template.js +35 -0
- package/src/git.js +38 -0
- package/src/logger.js +95 -0
- package/src/workspace.js +60 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2019, 2019
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
const fs = require('fs-extra');
|
|
11
|
+
const path = require('path');
|
|
12
|
+
const prettier = require('prettier');
|
|
13
|
+
const prettierConfig = require('prettier-config-carbon');
|
|
14
|
+
const createRemark = require('remark');
|
|
15
|
+
const monorepo = require('./remark/remark-monorepo');
|
|
16
|
+
|
|
17
|
+
const packageDenyList = new Set([
|
|
18
|
+
'carbon-components',
|
|
19
|
+
'carbon-components-react',
|
|
20
|
+
'@carbon/react',
|
|
21
|
+
'@carbon/sketch',
|
|
22
|
+
'@carbon/styles',
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
function run({ root, packagePaths }) {
|
|
26
|
+
const remark = createRemark().use(monorepo, {
|
|
27
|
+
root: root.directory,
|
|
28
|
+
});
|
|
29
|
+
const prettierOptions = {
|
|
30
|
+
...prettierConfig,
|
|
31
|
+
parser: 'markdown',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
return Promise.all(
|
|
35
|
+
packagePaths
|
|
36
|
+
.filter((pkg) => !packageDenyList.has(pkg.packageJson.name))
|
|
37
|
+
.map(async ({ packagePath }) => {
|
|
38
|
+
const README_PATH = path.join(packagePath, 'README.md');
|
|
39
|
+
if (!(await fs.pathExists(README_PATH))) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const readme = await fs.readFile(README_PATH, 'utf8');
|
|
44
|
+
const file = await process(remark, packagePath, readme);
|
|
45
|
+
await fs.writeFile(
|
|
46
|
+
README_PATH,
|
|
47
|
+
prettier.format(String(file), prettierOptions)
|
|
48
|
+
);
|
|
49
|
+
})
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function process(remark, cwd, contents) {
|
|
54
|
+
return new Promise((resolve, reject) => {
|
|
55
|
+
remark.process({ cwd, contents }, (error, file) => {
|
|
56
|
+
if (error) {
|
|
57
|
+
reject(error);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
resolve(file);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
module.exports = {
|
|
66
|
+
name: 'readme',
|
|
67
|
+
run,
|
|
68
|
+
};
|
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2018, 2018
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
const fs = require('fs-extra');
|
|
11
|
+
const path = require('path');
|
|
12
|
+
|
|
13
|
+
function monorepo() {
|
|
14
|
+
async function transformer(tree, file) {
|
|
15
|
+
const { cwd } = file;
|
|
16
|
+
const localPackageJsonPath = path.join(cwd, 'package.json');
|
|
17
|
+
const localPackageJson = await fs.readJson(localPackageJsonPath);
|
|
18
|
+
const { name, description } = localPackageJson;
|
|
19
|
+
|
|
20
|
+
if (!name) {
|
|
21
|
+
return new Error(
|
|
22
|
+
`Expected a name to be defined for the package at: ${cwd}`
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
if (!description) {
|
|
26
|
+
return new Error(
|
|
27
|
+
`Expected a description to be defined for the package at: ${cwd}`
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Grab all sections under `## Usage` as these are custom for each project
|
|
32
|
+
const usage = [];
|
|
33
|
+
let usageHeadingFound = false;
|
|
34
|
+
|
|
35
|
+
for (const child of tree.children) {
|
|
36
|
+
if (usageHeadingFound) {
|
|
37
|
+
if (child.type === 'heading' && child.depth <= 2) {
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
usage.push(child);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (
|
|
44
|
+
child.type === 'heading' &&
|
|
45
|
+
child.depth === 2 &&
|
|
46
|
+
child.children[0].value === 'Usage'
|
|
47
|
+
) {
|
|
48
|
+
usageHeadingFound = true;
|
|
49
|
+
usage.push(child);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// [x] Title
|
|
54
|
+
// [x] Getting Started
|
|
55
|
+
// [x] Usage
|
|
56
|
+
// [x] Examples
|
|
57
|
+
// [ ] Contributors
|
|
58
|
+
// [x] Contributing
|
|
59
|
+
// [x] License
|
|
60
|
+
// eslint-disable-next-line require-atomic-updates
|
|
61
|
+
tree.children = [
|
|
62
|
+
...createTitle(localPackageJson.name, localPackageJson.description),
|
|
63
|
+
...createGettingStarted(localPackageJson.name),
|
|
64
|
+
...usage,
|
|
65
|
+
...(await createAPIDoc(localPackageJson.name, path.join(cwd, 'docs'))),
|
|
66
|
+
...(await createExamples(
|
|
67
|
+
localPackageJson.name,
|
|
68
|
+
path.join(cwd, 'examples')
|
|
69
|
+
)),
|
|
70
|
+
...createContributing(),
|
|
71
|
+
...createLicense(),
|
|
72
|
+
];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return transformer;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function createTitle(name, description) {
|
|
79
|
+
return [
|
|
80
|
+
{
|
|
81
|
+
type: 'heading',
|
|
82
|
+
depth: 1,
|
|
83
|
+
children: [
|
|
84
|
+
{
|
|
85
|
+
type: 'text',
|
|
86
|
+
value: name,
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
type: 'blockquote',
|
|
92
|
+
children: [
|
|
93
|
+
{
|
|
94
|
+
type: 'paragraph',
|
|
95
|
+
children: [
|
|
96
|
+
{
|
|
97
|
+
type: 'text',
|
|
98
|
+
value: description,
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function createGettingStarted(name) {
|
|
108
|
+
return [
|
|
109
|
+
{
|
|
110
|
+
type: 'heading',
|
|
111
|
+
depth: 2,
|
|
112
|
+
children: [
|
|
113
|
+
{
|
|
114
|
+
type: 'text',
|
|
115
|
+
value: 'Getting started',
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
type: 'paragraph',
|
|
121
|
+
children: [
|
|
122
|
+
{
|
|
123
|
+
type: 'text',
|
|
124
|
+
value: 'To install ',
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
type: 'inlineCode',
|
|
128
|
+
value: name,
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
type: 'text',
|
|
132
|
+
value:
|
|
133
|
+
' in your project, you will need to run the following command using ',
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
type: 'link',
|
|
137
|
+
title: null,
|
|
138
|
+
url: 'https://www.npmjs.com/',
|
|
139
|
+
children: [
|
|
140
|
+
{
|
|
141
|
+
type: 'text',
|
|
142
|
+
value: 'npm',
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
type: 'text',
|
|
148
|
+
value: ':',
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
type: 'code',
|
|
154
|
+
lang: 'bash',
|
|
155
|
+
value: `npm install -S ${name}`,
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
type: 'paragraph',
|
|
159
|
+
children: [
|
|
160
|
+
{
|
|
161
|
+
type: 'text',
|
|
162
|
+
value: 'If you prefer ',
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
type: 'link',
|
|
166
|
+
title: null,
|
|
167
|
+
url: 'https://yarnpkg.com/en/',
|
|
168
|
+
children: [
|
|
169
|
+
{
|
|
170
|
+
type: 'text',
|
|
171
|
+
value: 'Yarn',
|
|
172
|
+
},
|
|
173
|
+
],
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
type: 'text',
|
|
177
|
+
value: ', use the following command\ninstead:',
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
type: 'code',
|
|
183
|
+
lang: 'bash',
|
|
184
|
+
meta: null,
|
|
185
|
+
value: `yarn add ${name}`,
|
|
186
|
+
},
|
|
187
|
+
];
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
async function createAPIDoc(name, docsDir) {
|
|
191
|
+
// No docs to list
|
|
192
|
+
if (!(await fs.pathExists(docsDir))) {
|
|
193
|
+
return [];
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const docs = (await fs.readdir(docsDir)).filter((name) => {
|
|
197
|
+
// Ignore dotfiles and json files
|
|
198
|
+
return !(name[0] === '.' || name === 'sass.json');
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
if (docs.length === 0) {
|
|
202
|
+
return [];
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return [
|
|
206
|
+
{
|
|
207
|
+
type: 'heading',
|
|
208
|
+
depth: 2,
|
|
209
|
+
children: [
|
|
210
|
+
{
|
|
211
|
+
type: 'text',
|
|
212
|
+
value: '📖 API Documentation',
|
|
213
|
+
},
|
|
214
|
+
],
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
type: 'paragraph',
|
|
218
|
+
children: [
|
|
219
|
+
{
|
|
220
|
+
type: 'text',
|
|
221
|
+
value: "If you're looking for ",
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
type: 'inlineCode',
|
|
225
|
+
value: name,
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
type: 'text',
|
|
229
|
+
value: ' API documentation, check out:',
|
|
230
|
+
},
|
|
231
|
+
],
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
type: 'list',
|
|
235
|
+
ordered: false,
|
|
236
|
+
spread: false,
|
|
237
|
+
children: docs.map((doc) => ({
|
|
238
|
+
type: 'listItem',
|
|
239
|
+
spread: false,
|
|
240
|
+
checked: null,
|
|
241
|
+
children: [
|
|
242
|
+
{
|
|
243
|
+
type: 'paragraph',
|
|
244
|
+
children: [
|
|
245
|
+
{
|
|
246
|
+
type: 'link',
|
|
247
|
+
title: null,
|
|
248
|
+
url: `./docs/${doc}`,
|
|
249
|
+
children: [
|
|
250
|
+
{
|
|
251
|
+
type: 'text',
|
|
252
|
+
value: `${
|
|
253
|
+
doc[0].toUpperCase() +
|
|
254
|
+
doc.slice(1).replace(/\.[^/.]+$/, '')
|
|
255
|
+
}`,
|
|
256
|
+
},
|
|
257
|
+
],
|
|
258
|
+
},
|
|
259
|
+
],
|
|
260
|
+
},
|
|
261
|
+
],
|
|
262
|
+
})),
|
|
263
|
+
},
|
|
264
|
+
];
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
async function createExamples(name, examplesDir) {
|
|
268
|
+
// No examples to list
|
|
269
|
+
if (!(await fs.pathExists(examplesDir))) {
|
|
270
|
+
return [];
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const examples = (await fs.readdir(examplesDir)).filter((name) => {
|
|
274
|
+
// Ignore dotfiles and special cases `codesandbox` and `storybook`
|
|
275
|
+
return !(
|
|
276
|
+
name[0] === '.' ||
|
|
277
|
+
name === 'codesandbox' ||
|
|
278
|
+
name === 'storybook' ||
|
|
279
|
+
name === 'preview'
|
|
280
|
+
);
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
if (examples.length === 0) {
|
|
284
|
+
return [];
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return [
|
|
288
|
+
{
|
|
289
|
+
type: 'heading',
|
|
290
|
+
depth: 2,
|
|
291
|
+
children: [
|
|
292
|
+
{
|
|
293
|
+
type: 'text',
|
|
294
|
+
value: '📚 Examples',
|
|
295
|
+
},
|
|
296
|
+
],
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
type: 'paragraph',
|
|
300
|
+
children: [
|
|
301
|
+
{
|
|
302
|
+
type: 'text',
|
|
303
|
+
value: "If you're looking for more examples on how to use ",
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
type: 'inlineCode',
|
|
307
|
+
value: name,
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
type: 'text',
|
|
311
|
+
value: ', we have some examples that you can check out:',
|
|
312
|
+
},
|
|
313
|
+
],
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
type: 'list',
|
|
317
|
+
ordered: false,
|
|
318
|
+
spread: false,
|
|
319
|
+
children: examples.map((example) => ({
|
|
320
|
+
type: 'listItem',
|
|
321
|
+
spread: false,
|
|
322
|
+
checked: null,
|
|
323
|
+
children: [
|
|
324
|
+
{
|
|
325
|
+
type: 'paragraph',
|
|
326
|
+
children: [
|
|
327
|
+
{
|
|
328
|
+
type: 'link',
|
|
329
|
+
title: null,
|
|
330
|
+
url: `./examples/${example}`,
|
|
331
|
+
children: [
|
|
332
|
+
{
|
|
333
|
+
type: 'text',
|
|
334
|
+
value: example,
|
|
335
|
+
},
|
|
336
|
+
],
|
|
337
|
+
},
|
|
338
|
+
],
|
|
339
|
+
},
|
|
340
|
+
],
|
|
341
|
+
})),
|
|
342
|
+
},
|
|
343
|
+
];
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function createContributing() {
|
|
347
|
+
return [
|
|
348
|
+
{
|
|
349
|
+
type: 'heading',
|
|
350
|
+
depth: 2,
|
|
351
|
+
children: [
|
|
352
|
+
{
|
|
353
|
+
type: 'text',
|
|
354
|
+
value: '🙌 Contributing',
|
|
355
|
+
},
|
|
356
|
+
],
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
type: 'paragraph',
|
|
360
|
+
children: [
|
|
361
|
+
{
|
|
362
|
+
type: 'text',
|
|
363
|
+
value:
|
|
364
|
+
"We're always looking for contributors to help us fix bugs, build new features, or help us improve the project documentation. If you're interested, definitely check out our ",
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
type: 'link',
|
|
368
|
+
title: null,
|
|
369
|
+
url: '/.github/CONTRIBUTING.md',
|
|
370
|
+
children: [
|
|
371
|
+
{
|
|
372
|
+
type: 'text',
|
|
373
|
+
value: 'Contributing Guide',
|
|
374
|
+
},
|
|
375
|
+
],
|
|
376
|
+
},
|
|
377
|
+
{
|
|
378
|
+
type: 'text',
|
|
379
|
+
value: '! 👀',
|
|
380
|
+
},
|
|
381
|
+
],
|
|
382
|
+
},
|
|
383
|
+
];
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function createLicense() {
|
|
387
|
+
return [
|
|
388
|
+
{
|
|
389
|
+
type: 'heading',
|
|
390
|
+
depth: 2,
|
|
391
|
+
children: [
|
|
392
|
+
{
|
|
393
|
+
type: 'text',
|
|
394
|
+
value: '📝 License',
|
|
395
|
+
},
|
|
396
|
+
],
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
type: 'paragraph',
|
|
400
|
+
children: [
|
|
401
|
+
{
|
|
402
|
+
type: 'text',
|
|
403
|
+
value: 'Licensed under the ',
|
|
404
|
+
},
|
|
405
|
+
{
|
|
406
|
+
type: 'link',
|
|
407
|
+
title: null,
|
|
408
|
+
url: '/LICENSE',
|
|
409
|
+
children: [
|
|
410
|
+
{
|
|
411
|
+
type: 'text',
|
|
412
|
+
value: 'Apache 2.0 License',
|
|
413
|
+
},
|
|
414
|
+
],
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
type: 'text',
|
|
418
|
+
value: '.',
|
|
419
|
+
},
|
|
420
|
+
],
|
|
421
|
+
},
|
|
422
|
+
];
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
module.exports = monorepo;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2019, 2019
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
const { workspace } = require('../workspace');
|
|
11
|
+
|
|
12
|
+
const tasks = {
|
|
13
|
+
npm: require('./sync/npm'),
|
|
14
|
+
package: require('./sync/package'),
|
|
15
|
+
readme: require('./sync/readme'),
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
async function sync(args, env) {
|
|
19
|
+
const { target } = args;
|
|
20
|
+
const tasksToRun = target === 'all' ? Object.keys(tasks) : [target];
|
|
21
|
+
|
|
22
|
+
for (const name of tasksToRun) {
|
|
23
|
+
const task = tasks[name];
|
|
24
|
+
await task.run(env);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = {
|
|
29
|
+
command: 'sync [target]',
|
|
30
|
+
desc: 'sync files across workspaces',
|
|
31
|
+
builder(yargs) {
|
|
32
|
+
yargs.positional('target', {
|
|
33
|
+
describe: 'choose a target to sync',
|
|
34
|
+
choices: ['all', 'npm', 'package', 'readme'],
|
|
35
|
+
default: 'all',
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
handler: workspace(sync),
|
|
39
|
+
};
|
package/src/compile.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2018, 2018
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
const sass = require('sass');
|
|
11
|
+
|
|
12
|
+
const defaultOptions = {
|
|
13
|
+
includePaths: ['node_modules', '../../node_modules'],
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
function compile(filepaths, options) {
|
|
17
|
+
return filepaths.map((file) => {
|
|
18
|
+
return sass.renderSync({
|
|
19
|
+
file,
|
|
20
|
+
...defaultOptions,
|
|
21
|
+
...options,
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = compile;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2019, 2019
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
const fs = require('fs-extra');
|
|
11
|
+
const path = require('path');
|
|
12
|
+
const template = require('lodash.template');
|
|
13
|
+
|
|
14
|
+
const TEMPLATES_DIR = path.join(__dirname, 'templates');
|
|
15
|
+
const blocklist = new Set(['.DS_Store']);
|
|
16
|
+
|
|
17
|
+
async function loadTemplates() {
|
|
18
|
+
const files = await fs.readdir(TEMPLATES_DIR).then((names) => {
|
|
19
|
+
return names
|
|
20
|
+
.filter((name) => {
|
|
21
|
+
return !blocklist.has(name);
|
|
22
|
+
})
|
|
23
|
+
.map((name) => {
|
|
24
|
+
const extension = path.extname(name);
|
|
25
|
+
return {
|
|
26
|
+
name: path.basename(name, `.template${extension}`),
|
|
27
|
+
filepath: path.join(TEMPLATES_DIR, name),
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const templates = {};
|
|
33
|
+
|
|
34
|
+
for (const { name, filepath } of files) {
|
|
35
|
+
const contents = await fs.readFile(filepath, 'utf8');
|
|
36
|
+
const compile = template(contents);
|
|
37
|
+
templates[name] = {
|
|
38
|
+
compile,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return templates;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports = {
|
|
46
|
+
loadTemplates,
|
|
47
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2020
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import PropTypes from 'prop-types';
|
|
9
|
+
import React from 'react';
|
|
10
|
+
|
|
11
|
+
function <%= name %>({ children, ...rest }) {
|
|
12
|
+
return <div {...rest}>{children}</div>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
<%= name %>.propTypes = {
|
|
16
|
+
children: PropTypes.node,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default <%= name %>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Props } from '@storybook/addon-docs/blocks';
|
|
2
|
+
import { <%= name %> } from './';
|
|
3
|
+
|
|
4
|
+
# <%= name %>
|
|
5
|
+
|
|
6
|
+
[Source
|
|
7
|
+
code](https://github.com/carbon-design-system/carbon/tree/master/packages/react/src/components/<%=
|
|
8
|
+
name %>) | [Usage
|
|
9
|
+
guidelines](https://www.carbondesignsystem.com/components/<%= name %>/usage)
|
|
10
|
+
| [Accessibility](https://www.carbondesignsystem.com/components/<%=
|
|
11
|
+
url %>/accessibility)
|
|
12
|
+
|
|
13
|
+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
|
14
|
+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
|
15
|
+
|
|
16
|
+
## Table of Contents
|
|
17
|
+
|
|
18
|
+
- [Overview](#overview)
|
|
19
|
+
- [Component API](#component-api)
|
|
20
|
+
- [Feedback](#feedback)
|
|
21
|
+
|
|
22
|
+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
|
|
23
|
+
|
|
24
|
+
## Overview
|
|
25
|
+
|
|
26
|
+
TODO
|
|
27
|
+
|
|
28
|
+
## Component API
|
|
29
|
+
|
|
30
|
+
<Props />
|
|
31
|
+
|
|
32
|
+
## Feedback
|
|
33
|
+
|
|
34
|
+
Help us improve this component by providing feedback, asking questions on Slack,
|
|
35
|
+
or updating this file on
|
|
36
|
+
[GitHub](https://github.com/carbon-design-system/carbon/edit/master/packages/react/src/components/<%=
|
|
37
|
+
name %>/<%= name %>.mdx).
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2018
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import React from 'react';
|
|
9
|
+
import { <%= name %> } from './';
|
|
10
|
+
import mdx from './<%= name %>.mdx';
|
|
11
|
+
|
|
12
|
+
export default {
|
|
13
|
+
title: '<%= name %>',
|
|
14
|
+
component: <%= name %>,
|
|
15
|
+
parameters: {
|
|
16
|
+
docs: {
|
|
17
|
+
page: mdx,
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const example = () => <<%= name %>>Story Example</<%= name %>>;
|