@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,405 @@
|
|
|
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 prettier = require('prettier');
|
|
11
|
+
const sassdoc = require('sassdoc');
|
|
12
|
+
const toc = require('markdown-toc');
|
|
13
|
+
|
|
14
|
+
const prettierOptions = {
|
|
15
|
+
parser: 'markdown',
|
|
16
|
+
printWidth: 80,
|
|
17
|
+
singleQuote: true,
|
|
18
|
+
trailingComma: 'es5',
|
|
19
|
+
proseWrap: 'always',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Custom slugify for markdown-toc to not include escaped emoji characters
|
|
24
|
+
* @param {string} title - the anchor link
|
|
25
|
+
*/
|
|
26
|
+
const slugify = (title) => {
|
|
27
|
+
return [...toc.slugify(title)].reduce((acc, ch) => {
|
|
28
|
+
if (ch.charCodeAt(0) > 255) {
|
|
29
|
+
return acc;
|
|
30
|
+
}
|
|
31
|
+
return acc + ch;
|
|
32
|
+
}, '');
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Create a JSON file of documented Sass items
|
|
37
|
+
* @see {@link http://sassdoc.com/configuration/|Sassdoc configuration}
|
|
38
|
+
* @param {string} sourceDir - source directory
|
|
39
|
+
* @param {object} config - configuration object
|
|
40
|
+
* @returns {object} json object
|
|
41
|
+
*/
|
|
42
|
+
async function createJson(sourceDir, config) {
|
|
43
|
+
config = config || {};
|
|
44
|
+
|
|
45
|
+
return sassdoc.parse(sourceDir, config).then(
|
|
46
|
+
(data) => {
|
|
47
|
+
return data;
|
|
48
|
+
},
|
|
49
|
+
(err) => {
|
|
50
|
+
console.error(err);
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Remove duplicate objects in `require` and `usedBy` arrays. Array objects have
|
|
57
|
+
* `name` and `type` properties, sometimes nested in a `context` object.
|
|
58
|
+
* @param {Array} arr - array with potential duplicates
|
|
59
|
+
* @returns {Array} deduped array
|
|
60
|
+
*/
|
|
61
|
+
function dedupeArray(arr) {
|
|
62
|
+
return arr.reduce(
|
|
63
|
+
(p, item) => {
|
|
64
|
+
const type = item.type || item.context.type;
|
|
65
|
+
const name = item.name || item.context.name;
|
|
66
|
+
const id = [type, name].join('|');
|
|
67
|
+
|
|
68
|
+
if (p.temp.indexOf(id) === -1) {
|
|
69
|
+
p.out.push(item);
|
|
70
|
+
p.temp.push(id);
|
|
71
|
+
}
|
|
72
|
+
return p;
|
|
73
|
+
},
|
|
74
|
+
{ temp: [], out: [] }
|
|
75
|
+
).out;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Create a unique Sassdoc item name
|
|
80
|
+
* @param {string} name - Sassdoc name
|
|
81
|
+
* @param {string} type - Sassdoc type (e.g. `variable`, `mixin`)
|
|
82
|
+
* @returns {string} unique Sassdoc item name
|
|
83
|
+
*/
|
|
84
|
+
function createUniqueName(name, type) {
|
|
85
|
+
return `${name} [${type}]`;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Create a standardized group name
|
|
90
|
+
* @param {Array} group - Item's group
|
|
91
|
+
* @returns {string} group name
|
|
92
|
+
*/
|
|
93
|
+
function createGroupName(group) {
|
|
94
|
+
return !group || !group[0] || group[0] === 'undefined' ? 'general' : group[0];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Create GitHub-flavored markdown anchor link
|
|
99
|
+
* @param {string} name - anchor value
|
|
100
|
+
* @param {string} heading - anchor link destination
|
|
101
|
+
* @returns {string} markdown anchor
|
|
102
|
+
*/
|
|
103
|
+
function createAnchorLink(name, heading) {
|
|
104
|
+
const anchorLink = heading
|
|
105
|
+
.toLowerCase()
|
|
106
|
+
.replace(/ /g, '-')
|
|
107
|
+
.replace(/[`~!@#$%^&*()+=<>?,./:;"'|{}[\]\\–—]/g, '')
|
|
108
|
+
.replace(
|
|
109
|
+
// eslint-disable-next-line no-irregular-whitespace
|
|
110
|
+
/[ 。?!,、;:“”【】()〔〕[]﹃﹄“”‘’﹁﹂—…-~《》〈〉「」]/g,
|
|
111
|
+
''
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
return `[${name}](#${anchorLink})`;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Create markdown for Sassdoc item (function, mixin, placeholder, variable)
|
|
119
|
+
* @param {string} item - Sassdoc item
|
|
120
|
+
* @returns {string} item in markdown formatting
|
|
121
|
+
*/
|
|
122
|
+
function createMarkdownItem(item) {
|
|
123
|
+
let str = '';
|
|
124
|
+
|
|
125
|
+
if (!item.context) {
|
|
126
|
+
return '';
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
let status = item.access === 'public' ? '✅' : '❌';
|
|
130
|
+
|
|
131
|
+
if (item.deprecated || item.deprecated === '') {
|
|
132
|
+
status += '⚠️';
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Name
|
|
136
|
+
str += `\n\n### ${status}${createUniqueName(
|
|
137
|
+
item.context.name,
|
|
138
|
+
item.context.type
|
|
139
|
+
)}`;
|
|
140
|
+
|
|
141
|
+
// Description
|
|
142
|
+
if (item.description) {
|
|
143
|
+
str += `\n\n${item.description.trim()}`;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Value (variables)
|
|
147
|
+
if (item.context.value) {
|
|
148
|
+
str += `
|
|
149
|
+
|
|
150
|
+
<details>
|
|
151
|
+
<summary>Source code</summary>
|
|
152
|
+
|
|
153
|
+
\`\`\`scss
|
|
154
|
+
$${item.context.name}: ${item.context.value};
|
|
155
|
+
\`\`\`
|
|
156
|
+
</details>`;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Code (mixins)
|
|
160
|
+
if (item.context.code) {
|
|
161
|
+
let paramStr = '';
|
|
162
|
+
|
|
163
|
+
if (item.parameter) {
|
|
164
|
+
item.parameter.forEach((param) => {
|
|
165
|
+
if (paramStr) {
|
|
166
|
+
paramStr += `, `;
|
|
167
|
+
}
|
|
168
|
+
paramStr += `$${param.name}`;
|
|
169
|
+
if (param.default) {
|
|
170
|
+
paramStr += `: ${param.default}`;
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
str += `
|
|
176
|
+
|
|
177
|
+
<details>
|
|
178
|
+
<summary>Source code</summary>
|
|
179
|
+
|
|
180
|
+
\`\`\`scss
|
|
181
|
+
@${item.context.type} ${item.context.name}(${paramStr}) {${item.context.code}}
|
|
182
|
+
\`\`\`
|
|
183
|
+
</details>`;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Parameters
|
|
187
|
+
if (item.parameter && item.parameter.length) {
|
|
188
|
+
str += `
|
|
189
|
+
|
|
190
|
+
- **Parameters**:
|
|
191
|
+
|
|
192
|
+
| Name | Description | Type | Default value |
|
|
193
|
+
| --- | --- | --- | --- |`;
|
|
194
|
+
|
|
195
|
+
item.parameter.forEach((param) => {
|
|
196
|
+
const paramType = param.type
|
|
197
|
+
? `\`${param.type.replace(/\|/g, `\\|`)}\``
|
|
198
|
+
: '—';
|
|
199
|
+
const paramDefault = param.default ? `\`${param.default}\`` : '—';
|
|
200
|
+
|
|
201
|
+
const row = `\n| \`$${param.name}\` | ${
|
|
202
|
+
param.description || '—'
|
|
203
|
+
} | ${paramType} | ${paramDefault} |`;
|
|
204
|
+
|
|
205
|
+
str += row;
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Example
|
|
210
|
+
if (item.example && item.example.length) {
|
|
211
|
+
str += `\n\n**Example**:`;
|
|
212
|
+
|
|
213
|
+
if (item.example[0].description) {
|
|
214
|
+
str += ` ${item.example[0].description}`;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
str += `
|
|
218
|
+
|
|
219
|
+
<details>
|
|
220
|
+
<summary>Example code</summary>
|
|
221
|
+
|
|
222
|
+
\`\`\`${item.example[0].type}
|
|
223
|
+
${item.example[0].code}
|
|
224
|
+
\`\`\`
|
|
225
|
+
</details>`;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Bullets
|
|
229
|
+
const metadata = [];
|
|
230
|
+
|
|
231
|
+
const groupName = createGroupName(item.group);
|
|
232
|
+
|
|
233
|
+
metadata.push({
|
|
234
|
+
key: 'Group',
|
|
235
|
+
value: createAnchorLink(groupName, groupName),
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
if (item.return) {
|
|
239
|
+
metadata.push({
|
|
240
|
+
key: 'Returns',
|
|
241
|
+
value: `\`${item.return.type}\` ${item.return.description || ''}`,
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (item.type) {
|
|
246
|
+
metadata.push({
|
|
247
|
+
key: 'Type',
|
|
248
|
+
value: `\`${item.type}\``,
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (item.alias) {
|
|
253
|
+
metadata.push({
|
|
254
|
+
key: 'Alias',
|
|
255
|
+
value: `\`${item.alias}\``,
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (item.aliased) {
|
|
260
|
+
let subbullets = '';
|
|
261
|
+
|
|
262
|
+
item.aliased.forEach((aliased) => {
|
|
263
|
+
subbullets += `\n - \`${aliased}\``;
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
metadata.push({
|
|
267
|
+
key: 'Aliased',
|
|
268
|
+
value: subbullets,
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (item.content) {
|
|
273
|
+
metadata.push({
|
|
274
|
+
key: 'Content',
|
|
275
|
+
value: item.content,
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
if (item.require && item.require.length) {
|
|
280
|
+
let subbullets = '';
|
|
281
|
+
|
|
282
|
+
dedupeArray(item.require).forEach((requires) => {
|
|
283
|
+
subbullets += `\n - ${createAnchorLink(
|
|
284
|
+
`${requires.name} [${requires.type}]`,
|
|
285
|
+
createUniqueName(requires.name, requires.type)
|
|
286
|
+
)}`;
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
metadata.push({
|
|
290
|
+
key: 'Requires',
|
|
291
|
+
value: subbullets,
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (item.usedBy && item.usedBy.length) {
|
|
296
|
+
let subbullets = '';
|
|
297
|
+
|
|
298
|
+
dedupeArray(item.usedBy).forEach((usedBy) => {
|
|
299
|
+
subbullets += `\n - ${createAnchorLink(
|
|
300
|
+
`${usedBy.context.name} [${usedBy.context.type}]`,
|
|
301
|
+
createUniqueName(usedBy.context.name, usedBy.context.type)
|
|
302
|
+
)}`;
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
metadata.push({
|
|
306
|
+
key: 'Used by',
|
|
307
|
+
value: subbullets,
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// if (item.since && item.since.length) {
|
|
312
|
+
// metadata.push({
|
|
313
|
+
// key: 'Since',
|
|
314
|
+
// value: item.since[0].version,
|
|
315
|
+
// });
|
|
316
|
+
// }
|
|
317
|
+
|
|
318
|
+
if (item.link && item.link.length) {
|
|
319
|
+
let subbullets = '';
|
|
320
|
+
|
|
321
|
+
item.link.forEach((link) => {
|
|
322
|
+
subbullets += `\n - [${link.caption || 'Link'}](${link.url})`;
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
metadata.push({
|
|
326
|
+
key: 'Links',
|
|
327
|
+
value: subbullets,
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
if (item.deprecated || item.deprecated === '') {
|
|
332
|
+
metadata.push({
|
|
333
|
+
key: 'Deprecated',
|
|
334
|
+
value: item.deprecated || 'This may not be available in future releases',
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if (metadata.length) {
|
|
339
|
+
str += '\n';
|
|
340
|
+
|
|
341
|
+
metadata.forEach((meta) => {
|
|
342
|
+
str += `\n- **${meta.key}**: ${meta.value}`;
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
return str;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Create a markdown file of documented Sass items
|
|
351
|
+
* @see {@link http://sassdoc.com/configuration/|Sassdoc configuration}
|
|
352
|
+
* @param {string} sourceDir - source directory
|
|
353
|
+
* @param {object} config - configuration object
|
|
354
|
+
* @returns {string} markdown
|
|
355
|
+
*/
|
|
356
|
+
async function createMarkdown(sourceDir, config) {
|
|
357
|
+
config = config || {};
|
|
358
|
+
|
|
359
|
+
return sassdoc.parse(sourceDir, config).then(
|
|
360
|
+
(data) => {
|
|
361
|
+
let markdownFile = '';
|
|
362
|
+
|
|
363
|
+
const documentedItems = data.filter(
|
|
364
|
+
(item) => item.access === 'public' || item.access === 'private'
|
|
365
|
+
);
|
|
366
|
+
|
|
367
|
+
markdownFile += `# Sass API
|
|
368
|
+
|
|
369
|
+
| Mark | Description |
|
|
370
|
+
| --- | --- |
|
|
371
|
+
| ✅ | Public functions, mixins, placeholders, and variables |
|
|
372
|
+
| ❌ | Private items - not supported outside package's build |
|
|
373
|
+
| ⚠️ | Deprecated items - may not be available in future releases |
|
|
374
|
+
|
|
375
|
+
<!-- toc -->
|
|
376
|
+
<!-- tocstop -->`;
|
|
377
|
+
|
|
378
|
+
let currentGroup = '';
|
|
379
|
+
|
|
380
|
+
documentedItems.forEach((item) => {
|
|
381
|
+
const itemGroup = createGroupName(item.group);
|
|
382
|
+
|
|
383
|
+
if (itemGroup !== currentGroup) {
|
|
384
|
+
markdownFile += `\n\n## ${itemGroup}`;
|
|
385
|
+
currentGroup = itemGroup;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
markdownFile += createMarkdownItem(item);
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
return prettier.format(
|
|
392
|
+
toc.insert(markdownFile, { slugify }),
|
|
393
|
+
prettierOptions
|
|
394
|
+
);
|
|
395
|
+
},
|
|
396
|
+
(err) => {
|
|
397
|
+
console.error(err);
|
|
398
|
+
}
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
module.exports = {
|
|
403
|
+
createJson,
|
|
404
|
+
createMarkdown,
|
|
405
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
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 glob = require('fast-glob');
|
|
11
|
+
const fs = require('fs-extra');
|
|
12
|
+
const path = require('path');
|
|
13
|
+
const { createLogger } = require('../logger');
|
|
14
|
+
const { createJson, createMarkdown } = require('./sassdoc/tools');
|
|
15
|
+
|
|
16
|
+
const logger = createLogger('sassdoc');
|
|
17
|
+
|
|
18
|
+
async function sassdoc({
|
|
19
|
+
glob: pattern,
|
|
20
|
+
ignore = [],
|
|
21
|
+
json = false,
|
|
22
|
+
output = 'docs',
|
|
23
|
+
} = {}) {
|
|
24
|
+
logger.start('sassdoc');
|
|
25
|
+
|
|
26
|
+
const cwd = process.cwd();
|
|
27
|
+
const DOCS_DIR = path.resolve(cwd, output);
|
|
28
|
+
const JSON_FILE = path.resolve(DOCS_DIR, 'sass.json');
|
|
29
|
+
const MARKDOWN_FILE = path.resolve(DOCS_DIR, 'sass.md');
|
|
30
|
+
const files = await glob(pattern, {
|
|
31
|
+
cwd,
|
|
32
|
+
ignore,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
logger.info(
|
|
36
|
+
`Creating sassdoc for pattern: '${pattern}', ignoring: '${ignore}'`
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
if (json) {
|
|
40
|
+
try {
|
|
41
|
+
const jsonFile = await createJson(files);
|
|
42
|
+
await fs.ensureDir(DOCS_DIR);
|
|
43
|
+
await fs.writeFile(JSON_FILE, JSON.stringify(jsonFile, null, 2));
|
|
44
|
+
} catch (error) {
|
|
45
|
+
logger.info(`Sassdoc error: ${error}`);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
try {
|
|
50
|
+
const markdownFile = await createMarkdown(files);
|
|
51
|
+
await fs.ensureDir(DOCS_DIR);
|
|
52
|
+
await fs.writeFile(MARKDOWN_FILE, markdownFile);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
logger.info(`Sassdoc error: ${error}`);
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
logger.stop();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = {
|
|
63
|
+
command: 'sassdoc <glob>',
|
|
64
|
+
desc: 'generate sassdoc as markdown',
|
|
65
|
+
builder(yargs) {
|
|
66
|
+
yargs.positional('glob', {
|
|
67
|
+
type: 'string',
|
|
68
|
+
describe: 'glob pattern for files to check',
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
yargs.options({
|
|
72
|
+
i: {
|
|
73
|
+
alias: 'ignore',
|
|
74
|
+
describe: 'provide a glob pattern of files to ignore',
|
|
75
|
+
type: 'string',
|
|
76
|
+
},
|
|
77
|
+
j: {
|
|
78
|
+
alias: 'json',
|
|
79
|
+
describe: 'output as json file',
|
|
80
|
+
type: 'boolean',
|
|
81
|
+
},
|
|
82
|
+
o: {
|
|
83
|
+
alias: 'output',
|
|
84
|
+
describe: 'specify the directory in which the files are output',
|
|
85
|
+
type: 'string',
|
|
86
|
+
},
|
|
87
|
+
});
|
|
88
|
+
},
|
|
89
|
+
handler: sassdoc,
|
|
90
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
|
|
13
|
+
const defaultIgnorePatterns = [
|
|
14
|
+
'**/__mocks__/**',
|
|
15
|
+
'**/__tests__/**',
|
|
16
|
+
'**/examples/**',
|
|
17
|
+
'**/tasks/**',
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
function run({ packagePaths }) {
|
|
21
|
+
return Promise.all(
|
|
22
|
+
packagePaths.map(async ({ packagePath }) => {
|
|
23
|
+
const ignorePath = path.join(packagePath, '.npmignore');
|
|
24
|
+
const ignorePatterns = defaultIgnorePatterns.slice();
|
|
25
|
+
|
|
26
|
+
if (await fs.pathExists(ignorePath)) {
|
|
27
|
+
const ignoreFile = await fs.readFile(ignorePath, 'utf8');
|
|
28
|
+
const localIgnorePatterns = ignoreFile.split('\n').filter((pattern) => {
|
|
29
|
+
return ignorePatterns.indexOf(pattern) === -1;
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
ignorePatterns.push(...localIgnorePatterns);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
await fs.writeFile(ignorePath, ignorePatterns.join('\n'));
|
|
36
|
+
})
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
module.exports = {
|
|
41
|
+
name: 'npm',
|
|
42
|
+
run,
|
|
43
|
+
};
|
|
@@ -0,0 +1,122 @@
|
|
|
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 packageJson in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
'use strict';
|
|
9
|
+
|
|
10
|
+
const fs = require('fs-extra');
|
|
11
|
+
|
|
12
|
+
// This is our default set of keywords to include in each `package.json` packageJson
|
|
13
|
+
const DEFAULT_KEYWORDS = [
|
|
14
|
+
'ibm',
|
|
15
|
+
'carbon',
|
|
16
|
+
'carbon-design-system',
|
|
17
|
+
'components',
|
|
18
|
+
'react',
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
// We're going to use this in our `sortFields` method. The idea is that we want
|
|
22
|
+
// our `package.json` files to be ordered in the order given in this array. To
|
|
23
|
+
// accomplish this, we create an object where we can reference the value
|
|
24
|
+
// assigned to a field when sorting. By default, highest priority fields start
|
|
25
|
+
// with 1 and go up. Unknown fields are all given the same priority, which is
|
|
26
|
+
// just the length of the array + 1. When we use `sortFields` we are checking
|
|
27
|
+
// for the value from `packageJsonFields` and comparing it with the other value.
|
|
28
|
+
const packageJsonFields = [
|
|
29
|
+
'name',
|
|
30
|
+
'private',
|
|
31
|
+
'description',
|
|
32
|
+
'version',
|
|
33
|
+
'license',
|
|
34
|
+
'bin',
|
|
35
|
+
'main',
|
|
36
|
+
'module',
|
|
37
|
+
'type',
|
|
38
|
+
'exports',
|
|
39
|
+
'repository',
|
|
40
|
+
'sideEffects',
|
|
41
|
+
'bugs',
|
|
42
|
+
'homepage',
|
|
43
|
+
'engines',
|
|
44
|
+
'files',
|
|
45
|
+
'keywords',
|
|
46
|
+
'publishConfig',
|
|
47
|
+
'scripts',
|
|
48
|
+
'resolutions',
|
|
49
|
+
'peerDependencies',
|
|
50
|
+
'dependencies',
|
|
51
|
+
'devDependencies',
|
|
52
|
+
'sideEffects',
|
|
53
|
+
'eyeglass',
|
|
54
|
+
'eslintConfig',
|
|
55
|
+
'prettier',
|
|
56
|
+
'babel',
|
|
57
|
+
'jest',
|
|
58
|
+
].reduce(
|
|
59
|
+
(acc, key, index) => ({
|
|
60
|
+
...acc,
|
|
61
|
+
[key]: index + 1,
|
|
62
|
+
}),
|
|
63
|
+
{}
|
|
64
|
+
);
|
|
65
|
+
const UNKNOWN_FIELD = Object.keys(packageJsonFields).length + 1;
|
|
66
|
+
function sortFields(a, b) {
|
|
67
|
+
const aValue = packageJsonFields[a] || UNKNOWN_FIELD;
|
|
68
|
+
const bValue = packageJsonFields[b] || UNKNOWN_FIELD;
|
|
69
|
+
return aValue - bValue;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function run({ packagePaths }) {
|
|
73
|
+
return Promise.all(
|
|
74
|
+
packagePaths.map(
|
|
75
|
+
async ({ packageJsonPath, packageJson, packageFolder }) => {
|
|
76
|
+
packageJson.repository = {
|
|
77
|
+
type: 'git',
|
|
78
|
+
url: 'https://github.com/carbon-design-system/carbon.git',
|
|
79
|
+
directory: packageFolder,
|
|
80
|
+
};
|
|
81
|
+
packageJson.bugs =
|
|
82
|
+
'https://github.com/carbon-design-system/carbon/issues';
|
|
83
|
+
packageJson.license = 'Apache-2.0';
|
|
84
|
+
|
|
85
|
+
if (!packageJson.private) {
|
|
86
|
+
packageJson.publishConfig = {
|
|
87
|
+
access: 'public',
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (Array.isArray(packageJson.keywords)) {
|
|
92
|
+
const keywordsToAdd = DEFAULT_KEYWORDS.filter((keyword) => {
|
|
93
|
+
return packageJson.keywords.indexOf(keyword) === -1;
|
|
94
|
+
});
|
|
95
|
+
if (keywordsToAdd.length > 0) {
|
|
96
|
+
packageJson.keywords = [...packageJson.keywords, ...keywordsToAdd];
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
packageJson.keywords = DEFAULT_KEYWORDS;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Construct our new packageJson packageJson with sorted fields
|
|
103
|
+
const file = Object.keys(packageJson)
|
|
104
|
+
.sort(sortFields)
|
|
105
|
+
.reduce(
|
|
106
|
+
(acc, key) => ({
|
|
107
|
+
...acc,
|
|
108
|
+
[key]: packageJson[key],
|
|
109
|
+
}),
|
|
110
|
+
{}
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
await fs.writeJson(packageJsonPath, file, { spaces: 2 });
|
|
114
|
+
}
|
|
115
|
+
)
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
module.exports = {
|
|
120
|
+
name: 'package',
|
|
121
|
+
run,
|
|
122
|
+
};
|