@atlaskit/codemod-cli 0.27.2 → 0.27.3
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/CHANGELOG.md +6 -0
- package/dist/cjs/main.js +85 -33
- package/dist/cjs/presets/index.js +2 -1
- package/dist/cjs/presets/remove-token-fallbacks/remove-token-fallbacks.js +225 -0
- package/dist/cjs/presets/remove-token-fallbacks/types.js +5 -0
- package/dist/cjs/presets/remove-token-fallbacks/utils/all-tokens.js +44 -0
- package/dist/cjs/presets/remove-token-fallbacks/utils/color-utils.js +93 -0
- package/dist/cjs/presets/remove-token-fallbacks/utils/get-team-info.js +51 -0
- package/dist/cjs/presets/remove-token-fallbacks/utils/normalize-values.js +113 -0
- package/dist/cjs/presets/remove-token-fallbacks/utils/remove-unused-imports.js +61 -0
- package/dist/cjs/presets/remove-token-fallbacks/utils/remove-unused-variables.js +37 -0
- package/dist/cjs/presets/remove-token-fallbacks/utils/reporter.js +310 -0
- package/dist/cjs/presets/remove-token-fallbacks/utils/token-processor.js +632 -0
- package/dist/cjs/presets/remove-token-fallbacks/utils/update-comments.js +58 -0
- package/dist/es2019/main.js +24 -0
- package/dist/es2019/presets/index.js +2 -1
- package/dist/es2019/presets/remove-token-fallbacks/remove-token-fallbacks.js +130 -0
- package/dist/es2019/presets/remove-token-fallbacks/types.js +1 -0
- package/dist/es2019/presets/remove-token-fallbacks/utils/all-tokens.js +30 -0
- package/dist/es2019/presets/remove-token-fallbacks/utils/color-utils.js +84 -0
- package/dist/es2019/presets/remove-token-fallbacks/utils/get-team-info.js +22 -0
- package/dist/es2019/presets/remove-token-fallbacks/utils/normalize-values.js +104 -0
- package/dist/es2019/presets/remove-token-fallbacks/utils/remove-unused-imports.js +51 -0
- package/dist/es2019/presets/remove-token-fallbacks/utils/remove-unused-variables.js +31 -0
- package/dist/es2019/presets/remove-token-fallbacks/utils/reporter.js +118 -0
- package/dist/es2019/presets/remove-token-fallbacks/utils/token-processor.js +377 -0
- package/dist/es2019/presets/remove-token-fallbacks/utils/update-comments.js +46 -0
- package/dist/esm/main.js +85 -33
- package/dist/esm/presets/index.js +2 -1
- package/dist/esm/presets/remove-token-fallbacks/remove-token-fallbacks.js +215 -0
- package/dist/esm/presets/remove-token-fallbacks/types.js +1 -0
- package/dist/esm/presets/remove-token-fallbacks/utils/all-tokens.js +38 -0
- package/dist/esm/presets/remove-token-fallbacks/utils/color-utils.js +86 -0
- package/dist/esm/presets/remove-token-fallbacks/utils/get-team-info.js +44 -0
- package/dist/esm/presets/remove-token-fallbacks/utils/normalize-values.js +107 -0
- package/dist/esm/presets/remove-token-fallbacks/utils/remove-unused-imports.js +55 -0
- package/dist/esm/presets/remove-token-fallbacks/utils/remove-unused-variables.js +31 -0
- package/dist/esm/presets/remove-token-fallbacks/utils/reporter.js +302 -0
- package/dist/esm/presets/remove-token-fallbacks/utils/token-processor.js +625 -0
- package/dist/esm/presets/remove-token-fallbacks/utils/update-comments.js +51 -0
- package/dist/types/presets/index.d.ts +1 -0
- package/dist/types/presets/remove-token-fallbacks/remove-token-fallbacks.d.ts +29 -0
- package/dist/types/presets/remove-token-fallbacks/types.d.ts +39 -0
- package/dist/types/presets/remove-token-fallbacks/utils/all-tokens.d.ts +1 -0
- package/dist/types/presets/remove-token-fallbacks/utils/color-utils.d.ts +3 -0
- package/dist/types/presets/remove-token-fallbacks/utils/get-team-info.d.ts +8 -0
- package/dist/types/presets/remove-token-fallbacks/utils/normalize-values.d.ts +8 -0
- package/dist/types/presets/remove-token-fallbacks/utils/remove-unused-imports.d.ts +2 -0
- package/dist/types/presets/remove-token-fallbacks/utils/remove-unused-variables.d.ts +2 -0
- package/dist/types/presets/remove-token-fallbacks/utils/reporter.d.ts +4 -0
- package/dist/types/presets/remove-token-fallbacks/utils/token-processor.d.ts +30 -0
- package/dist/types/presets/remove-token-fallbacks/utils/update-comments.d.ts +2 -0
- package/dist/types-ts4.5/presets/index.d.ts +1 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/remove-token-fallbacks.d.ts +29 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/types.d.ts +39 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/all-tokens.d.ts +1 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/color-utils.d.ts +3 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/get-team-info.d.ts +8 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/normalize-values.d.ts +8 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/remove-unused-imports.d.ts +2 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/remove-unused-variables.d.ts +2 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/reporter.d.ts +4 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/token-processor.d.ts +30 -0
- package/dist/types-ts4.5/presets/remove-token-fallbacks/utils/update-comments.d.ts +2 -0
- package/package.json +8 -3
package/dist/esm/main.js
CHANGED
|
@@ -128,7 +128,7 @@ var resolveTransform = /*#__PURE__*/function () {
|
|
|
128
128
|
}();
|
|
129
129
|
var runTransform = /*#__PURE__*/function () {
|
|
130
130
|
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(filePaths, transform, flags) {
|
|
131
|
-
var logger, codemodDirs, transformPath, args, jscodeshiftContent, jscodeshiftContentNew;
|
|
131
|
+
var logger, codemodDirs, transformPath, args, jscodeshiftContent, jscodeshiftContentNew, transformModule;
|
|
132
132
|
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
133
133
|
while (1) switch (_context3.prev = _context3.next) {
|
|
134
134
|
case 0:
|
|
@@ -172,11 +172,31 @@ var runTransform = /*#__PURE__*/function () {
|
|
|
172
172
|
jscodeshiftContent = fs.readFileSync(jscodeshift, 'utf8');
|
|
173
173
|
jscodeshiftContentNew = fixLineEnding(jscodeshiftContent, 'LF');
|
|
174
174
|
fs.writeFileSync(jscodeshift, jscodeshiftContentNew);
|
|
175
|
-
|
|
175
|
+
try {
|
|
176
|
+
transformModule = require(transformPath);
|
|
177
|
+
} catch (error) {
|
|
178
|
+
// eslint-disable-next-line no-console
|
|
179
|
+
console.warn("Error loading transform module: ".concat(transformPath, ". Skipping lifecycle hooks."));
|
|
180
|
+
}
|
|
181
|
+
if (!transformModule) {
|
|
182
|
+
_context3.next = 20;
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
_context3.next = 20;
|
|
186
|
+
return processLifecycleHook('beforeAll', transformModule, logger, transform, flags);
|
|
187
|
+
case 20:
|
|
188
|
+
_context3.next = 22;
|
|
176
189
|
return spawn(jscodeshift, args, {
|
|
177
190
|
stdio: 'inherit'
|
|
178
191
|
});
|
|
179
|
-
case
|
|
192
|
+
case 22:
|
|
193
|
+
if (!transformModule) {
|
|
194
|
+
_context3.next = 25;
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
_context3.next = 25;
|
|
198
|
+
return processLifecycleHook('afterAll', transformModule, logger, transform, flags);
|
|
199
|
+
case 25:
|
|
180
200
|
case "end":
|
|
181
201
|
return _context3.stop();
|
|
182
202
|
}
|
|
@@ -282,23 +302,55 @@ var defaultFlags = {
|
|
|
282
302
|
ignorePattern: 'node_modules',
|
|
283
303
|
logger: console
|
|
284
304
|
};
|
|
285
|
-
|
|
305
|
+
function processLifecycleHook(_x9, _x10, _x11, _x12, _x13) {
|
|
306
|
+
return _processLifecycleHook.apply(this, arguments);
|
|
307
|
+
}
|
|
308
|
+
function _processLifecycleHook() {
|
|
309
|
+
_processLifecycleHook = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(hookName, transformModule, logger, transform, flags) {
|
|
310
|
+
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
311
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
312
|
+
case 0:
|
|
313
|
+
if (!(typeof transformModule[hookName] === 'function')) {
|
|
314
|
+
_context5.next = 11;
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
_context5.prev = 1;
|
|
318
|
+
logger.log(chalk.green("Executing ".concat(hookName, " for transform '").concat(transform.name, "'...")));
|
|
319
|
+
_context5.next = 5;
|
|
320
|
+
return transformModule[hookName](flags);
|
|
321
|
+
case 5:
|
|
322
|
+
_context5.next = 11;
|
|
323
|
+
break;
|
|
324
|
+
case 7:
|
|
325
|
+
_context5.prev = 7;
|
|
326
|
+
_context5.t0 = _context5["catch"](1);
|
|
327
|
+
logger.log(chalk.red("Error in ".concat(hookName, " for transform '").concat(transform.name, "': ").concat(_context5.t0)));
|
|
328
|
+
throw _context5.t0;
|
|
329
|
+
case 11:
|
|
330
|
+
case "end":
|
|
331
|
+
return _context5.stop();
|
|
332
|
+
}
|
|
333
|
+
}, _callee5, null, [[1, 7]]);
|
|
334
|
+
}));
|
|
335
|
+
return _processLifecycleHook.apply(this, arguments);
|
|
336
|
+
}
|
|
337
|
+
export default function main(_x14, _x15) {
|
|
286
338
|
return _main.apply(this, arguments);
|
|
287
339
|
}
|
|
288
340
|
function _main() {
|
|
289
|
-
_main = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
341
|
+
_main = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(input, userFlags) {
|
|
290
342
|
var flags, logger, _yield$parseArgs, packages, _process$env$_PACKAGE, _PACKAGE_VERSION_, shouldHavePackages, availableTransforms, transforms, transformsWithModule, _iterator, _step, transform;
|
|
291
|
-
return _regeneratorRuntime.wrap(function
|
|
292
|
-
while (1) switch (
|
|
343
|
+
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
344
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
293
345
|
case 0:
|
|
294
346
|
flags = _objectSpread(_objectSpread({}, defaultFlags), userFlags);
|
|
295
347
|
logger = flags.logger;
|
|
296
|
-
|
|
348
|
+
_context6.next = 4;
|
|
297
349
|
return parseArgs(input, flags);
|
|
298
350
|
case 4:
|
|
299
|
-
_yield$parseArgs =
|
|
351
|
+
_yield$parseArgs = _context6.sent;
|
|
300
352
|
packages = _yield$parseArgs.packages;
|
|
301
|
-
_process$env$_PACKAGE = "0.27.
|
|
353
|
+
_process$env$_PACKAGE = "0.27.3", _PACKAGE_VERSION_ = _process$env$_PACKAGE === void 0 ? '0.0.0-dev' : _process$env$_PACKAGE;
|
|
302
354
|
logger.log(chalk.bgBlue(chalk.black("\uD83D\uDCDA Atlassian-Frontend codemod library @ ".concat(_PACKAGE_VERSION_, " \uD83D\uDCDA"))));
|
|
303
355
|
if (packages && packages.length > 0) {
|
|
304
356
|
logger.log(chalk.gray("Searching for codemods for newer versions of the following packages: ".concat(packages.map(function (pkg) {
|
|
@@ -307,36 +359,36 @@ function _main() {
|
|
|
307
359
|
}
|
|
308
360
|
shouldHavePackages = flags.sinceRef || flags.packages && flags.packages.length > 0;
|
|
309
361
|
if (!(shouldHavePackages && (packages === null || packages === void 0 ? void 0 : packages.length) === 0)) {
|
|
310
|
-
|
|
362
|
+
_context6.next = 13;
|
|
311
363
|
break;
|
|
312
364
|
}
|
|
313
365
|
logger.log(chalk.gray("Did not find updated packages, exiting"));
|
|
314
|
-
return
|
|
366
|
+
return _context6.abrupt("return", {
|
|
315
367
|
transforms: []
|
|
316
368
|
});
|
|
317
369
|
case 13:
|
|
318
370
|
availableTransforms = getTransforms(packages);
|
|
319
371
|
if (!(availableTransforms.length === 0)) {
|
|
320
|
-
|
|
372
|
+
_context6.next = 16;
|
|
321
373
|
break;
|
|
322
374
|
}
|
|
323
375
|
throw new NoTransformsExistError('No codemods available. Please make sure you have the latest version of the packages you are trying to upgrade before running the codemod');
|
|
324
376
|
case 16:
|
|
325
377
|
if (!packages) {
|
|
326
|
-
|
|
378
|
+
_context6.next = 20;
|
|
327
379
|
break;
|
|
328
380
|
}
|
|
329
|
-
|
|
330
|
-
|
|
381
|
+
_context6.t0 = availableTransforms;
|
|
382
|
+
_context6.next = 24;
|
|
331
383
|
break;
|
|
332
384
|
case 20:
|
|
333
|
-
|
|
385
|
+
_context6.next = 22;
|
|
334
386
|
return resolveTransform(flags, availableTransforms);
|
|
335
387
|
case 22:
|
|
336
|
-
|
|
337
|
-
|
|
388
|
+
_context6.t1 = _context6.sent;
|
|
389
|
+
_context6.t0 = [_context6.t1];
|
|
338
390
|
case 24:
|
|
339
|
-
transforms =
|
|
391
|
+
transforms = _context6.t0;
|
|
340
392
|
transformsWithModule = transforms.map(function (transform) {
|
|
341
393
|
return _objectSpread(_objectSpread({}, transform), {}, {
|
|
342
394
|
module: getTransformModule(transform)
|
|
@@ -346,39 +398,39 @@ function _main() {
|
|
|
346
398
|
return "".concat(transform.module, ": ").concat(transform.name);
|
|
347
399
|
}).join('\n')))));
|
|
348
400
|
_iterator = _createForOfIteratorHelper(transformsWithModule);
|
|
349
|
-
|
|
401
|
+
_context6.prev = 28;
|
|
350
402
|
_iterator.s();
|
|
351
403
|
case 30:
|
|
352
404
|
if ((_step = _iterator.n()).done) {
|
|
353
|
-
|
|
405
|
+
_context6.next = 36;
|
|
354
406
|
break;
|
|
355
407
|
}
|
|
356
408
|
transform = _step.value;
|
|
357
|
-
|
|
409
|
+
_context6.next = 34;
|
|
358
410
|
return runTransform(input, transform, flags);
|
|
359
411
|
case 34:
|
|
360
|
-
|
|
412
|
+
_context6.next = 30;
|
|
361
413
|
break;
|
|
362
414
|
case 36:
|
|
363
|
-
|
|
415
|
+
_context6.next = 41;
|
|
364
416
|
break;
|
|
365
417
|
case 38:
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
_iterator.e(
|
|
418
|
+
_context6.prev = 38;
|
|
419
|
+
_context6.t2 = _context6["catch"](28);
|
|
420
|
+
_iterator.e(_context6.t2);
|
|
369
421
|
case 41:
|
|
370
|
-
|
|
422
|
+
_context6.prev = 41;
|
|
371
423
|
_iterator.f();
|
|
372
|
-
return
|
|
424
|
+
return _context6.finish(41);
|
|
373
425
|
case 44:
|
|
374
|
-
return
|
|
426
|
+
return _context6.abrupt("return", {
|
|
375
427
|
transforms: transformsWithModule
|
|
376
428
|
});
|
|
377
429
|
case 45:
|
|
378
430
|
case "end":
|
|
379
|
-
return
|
|
431
|
+
return _context6.stop();
|
|
380
432
|
}
|
|
381
|
-
},
|
|
433
|
+
}, _callee6, null, [[28, 38, 41, 44]]);
|
|
382
434
|
}));
|
|
383
435
|
return _main.apply(this, arguments);
|
|
384
436
|
}
|
|
@@ -10,7 +10,8 @@ import './migrate-to-link/migrate-to-link';
|
|
|
10
10
|
import './migrate-to-new-buttons/migrate-to-new-buttons';
|
|
11
11
|
import './upgrade-pragmatic-drag-and-drop-to-stable/upgrade-pragmatic-drag-and-drop-to-stable';
|
|
12
12
|
import './remove-dark-theme-vr-options/remove-dark-theme-vr-options';
|
|
13
|
-
|
|
13
|
+
import './remove-token-fallbacks/remove-token-fallbacks';
|
|
14
|
+
var presets = ['styled-to-emotion', 'theme-remove-deprecated-mixins', 'migrate-to-link', 'migrate-to-new-buttons', 'upgrade-pragmatic-drag-and-drop-to-stable', 'remove-dark-theme-vr-options', 'remove-token-fallbacks'].map(function (preset) {
|
|
14
15
|
return path.join(__dirname, preset, "".concat(preset, ".@(ts|js|tsx)"));
|
|
15
16
|
});
|
|
16
17
|
export default presets;
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
4
|
+
/* eslint-disable no-console */
|
|
5
|
+
import { exec } from 'child_process';
|
|
6
|
+
import fs from 'fs/promises';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import { promisify } from 'util';
|
|
9
|
+
import { hasImportDeclaration } from '@hypermod/utils';
|
|
10
|
+
import { findRoot } from '@manypkg/find-root';
|
|
11
|
+
import chalk from 'chalk';
|
|
12
|
+
import { getTokenMap } from './utils/all-tokens';
|
|
13
|
+
import { getTeamInfo } from './utils/get-team-info';
|
|
14
|
+
import { removeUnusedImports } from './utils/remove-unused-imports';
|
|
15
|
+
import { removeUnusedVariables } from './utils/remove-unused-variables';
|
|
16
|
+
import { clearFolder, combineReports, writeReports } from './utils/reporter';
|
|
17
|
+
import { TokenProcessor } from './utils/token-processor';
|
|
18
|
+
var execAsync = promisify(exec);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Transforms the source code of a file by removing fallback values from the @atlaskit/tokens/token functions.
|
|
22
|
+
* By default removes only the fallbacks that have the same values as the tokens.
|
|
23
|
+
*
|
|
24
|
+
* @param {FileInfo} fileInfo - Information about the file to be transformed.
|
|
25
|
+
* @param {API} api - The jscodeshift API, providing utilities for AST transformations.
|
|
26
|
+
* @param {RemoveTokenFallbackOptions} options - Options for the transformation, including:
|
|
27
|
+
* @param {boolean} [options.verbose] - If true, enables verbose logging.
|
|
28
|
+
* @param {boolean} [options.forceUpdate] - If true, removes the fallbacks regardless of the difference between token and fallback. Otherwise removes only the fallbacks that are equal to the token values.
|
|
29
|
+
* @param {boolean} [options.addEslintComments] - If true, adds the eslint ignore comment for the rule @atlaskit/design-system/no-unsafe-design-token-usage for the fallbacks that weren't removed.
|
|
30
|
+
* @param {boolean} [options.useLegacyColorTheme] - If true, uses the legacy theme for color token mapping.
|
|
31
|
+
* @param {string} [options.reportFolder] - Directory path to output transformation reports. Reports will be generated only if this option is provided.
|
|
32
|
+
* @param {boolean} [options.dry] - If true, performs a dry run without modifying the files.
|
|
33
|
+
*
|
|
34
|
+
* @returns {Promise<string>} A promise that resolves to the transformed source code as a string.
|
|
35
|
+
*/
|
|
36
|
+
export default function transformer(_x, _x2, _x3) {
|
|
37
|
+
return _transformer.apply(this, arguments);
|
|
38
|
+
}
|
|
39
|
+
function _transformer() {
|
|
40
|
+
_transformer = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(fileInfo, _ref, options) {
|
|
41
|
+
var _options$useLegacyCol;
|
|
42
|
+
var j, rootDir, source, details, tokenMap, teamInfo, transformPromises, results, unusedVars, allImports, allVars;
|
|
43
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
44
|
+
while (1) switch (_context.prev = _context.next) {
|
|
45
|
+
case 0:
|
|
46
|
+
j = _ref.jscodeshift;
|
|
47
|
+
_context.next = 3;
|
|
48
|
+
return findRoot(path.dirname(fileInfo.path));
|
|
49
|
+
case 3:
|
|
50
|
+
rootDir = _context.sent;
|
|
51
|
+
source = j(fileInfo.source);
|
|
52
|
+
if (hasImportDeclaration(j, source, '@atlaskit/tokens')) {
|
|
53
|
+
_context.next = 7;
|
|
54
|
+
break;
|
|
55
|
+
}
|
|
56
|
+
return _context.abrupt("return", fileInfo.source);
|
|
57
|
+
case 7:
|
|
58
|
+
details = {
|
|
59
|
+
replaced: [],
|
|
60
|
+
notReplaced: []
|
|
61
|
+
};
|
|
62
|
+
if (options.verbose) {
|
|
63
|
+
console.log(chalk.yellow("Using ".concat(options.useLegacyColorTheme ? 'legacy light' : 'light', " theme.")));
|
|
64
|
+
}
|
|
65
|
+
tokenMap = getTokenMap((_options$useLegacyCol = options.useLegacyColorTheme) !== null && _options$useLegacyCol !== void 0 ? _options$useLegacyCol : false);
|
|
66
|
+
_context.next = 12;
|
|
67
|
+
return getTeamInfo(fileInfo.path);
|
|
68
|
+
case 12:
|
|
69
|
+
teamInfo = _context.sent;
|
|
70
|
+
transformPromises = source.find(j.CallExpression, {
|
|
71
|
+
callee: {
|
|
72
|
+
type: 'Identifier',
|
|
73
|
+
name: 'token'
|
|
74
|
+
}
|
|
75
|
+
}).paths().map(function (callPath) {
|
|
76
|
+
var processor = new TokenProcessor(j, options, fileInfo, source, rootDir, details, tokenMap, teamInfo);
|
|
77
|
+
return processor.processAndLogSingleToken(callPath);
|
|
78
|
+
});
|
|
79
|
+
_context.next = 16;
|
|
80
|
+
return Promise.all(transformPromises);
|
|
81
|
+
case 16:
|
|
82
|
+
results = _context.sent;
|
|
83
|
+
unusedVars = [];
|
|
84
|
+
if (results.some(function (result) {
|
|
85
|
+
return result.fallbackRemoved;
|
|
86
|
+
})) {
|
|
87
|
+
allImports = results.flatMap(function (result) {
|
|
88
|
+
var _result$resolvedImpor;
|
|
89
|
+
return (_result$resolvedImpor = result.resolvedImportDeclaration) !== null && _result$resolvedImpor !== void 0 ? _result$resolvedImpor : [];
|
|
90
|
+
});
|
|
91
|
+
allVars = results.flatMap(function (result) {
|
|
92
|
+
var _result$resolvedLocal;
|
|
93
|
+
return (_result$resolvedLocal = result.resolvedLocalVarDeclaration) !== null && _result$resolvedLocal !== void 0 ? _result$resolvedLocal : [];
|
|
94
|
+
});
|
|
95
|
+
unusedVars.push.apply(unusedVars, _toConsumableArray(allVars));
|
|
96
|
+
if (allImports.length) {
|
|
97
|
+
if (options.verbose) {
|
|
98
|
+
console.log(chalk.green("".concat(fileInfo.path, ": Some fallbacks were removed. Cleaning up ").concat(allImports.length, " imports.")));
|
|
99
|
+
}
|
|
100
|
+
removeUnusedImports(allImports, j);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
removeUnusedVariables(unusedVars, j);
|
|
104
|
+
if (!options.reportFolder) {
|
|
105
|
+
_context.next = 23;
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
_context.next = 23;
|
|
109
|
+
return writeReports(details, options.reportFolder);
|
|
110
|
+
case 23:
|
|
111
|
+
if (!options.dry) {
|
|
112
|
+
_context.next = 28;
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
if (options.verbose) {
|
|
116
|
+
console.log(chalk.cyan("".concat(fileInfo.path, ": dry run mode active. Source was not modified.")));
|
|
117
|
+
}
|
|
118
|
+
// Return the unmodified source if dryRun is true
|
|
119
|
+
return _context.abrupt("return", fileInfo.source);
|
|
120
|
+
case 28:
|
|
121
|
+
return _context.abrupt("return", source.toSource());
|
|
122
|
+
case 29:
|
|
123
|
+
case "end":
|
|
124
|
+
return _context.stop();
|
|
125
|
+
}
|
|
126
|
+
}, _callee);
|
|
127
|
+
}));
|
|
128
|
+
return _transformer.apply(this, arguments);
|
|
129
|
+
}
|
|
130
|
+
export var parser = 'tsx';
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Function executed before all transformations to prepare the environment by clearing the report folder.
|
|
134
|
+
*/
|
|
135
|
+
export function beforeAll(_x4) {
|
|
136
|
+
return _beforeAll.apply(this, arguments);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Function executed after all transformations to combine individual file reports into a comprehensive transformation report.
|
|
141
|
+
* It also applies prettier to the affected files.
|
|
142
|
+
*/
|
|
143
|
+
function _beforeAll() {
|
|
144
|
+
_beforeAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(options) {
|
|
145
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
146
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
147
|
+
case 0:
|
|
148
|
+
if (!options.reportFolder) {
|
|
149
|
+
_context2.next = 3;
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
_context2.next = 3;
|
|
153
|
+
return clearFolder(options.reportFolder);
|
|
154
|
+
case 3:
|
|
155
|
+
case "end":
|
|
156
|
+
return _context2.stop();
|
|
157
|
+
}
|
|
158
|
+
}, _callee2);
|
|
159
|
+
}));
|
|
160
|
+
return _beforeAll.apply(this, arguments);
|
|
161
|
+
}
|
|
162
|
+
export function afterAll(_x5) {
|
|
163
|
+
return _afterAll.apply(this, arguments);
|
|
164
|
+
}
|
|
165
|
+
function _afterAll() {
|
|
166
|
+
_afterAll = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(options) {
|
|
167
|
+
var filesTxtPath, fileContent;
|
|
168
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
169
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
170
|
+
case 0:
|
|
171
|
+
if (!options.reportFolder) {
|
|
172
|
+
_context3.next = 3;
|
|
173
|
+
break;
|
|
174
|
+
}
|
|
175
|
+
_context3.next = 3;
|
|
176
|
+
return combineReports(options.reportFolder);
|
|
177
|
+
case 3:
|
|
178
|
+
if (!(options.reportFolder && !options.dry)) {
|
|
179
|
+
_context3.next = 19;
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
_context3.prev = 4;
|
|
183
|
+
filesTxtPath = path.join(options.reportFolder, 'files.txt');
|
|
184
|
+
_context3.next = 8;
|
|
185
|
+
return fs.readFile(filesTxtPath, 'utf-8');
|
|
186
|
+
case 8:
|
|
187
|
+
fileContent = _context3.sent;
|
|
188
|
+
if (!(fileContent.length > 0)) {
|
|
189
|
+
_context3.next = 14;
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
console.log("Running prettier on files: ".concat(chalk.magenta(fileContent)));
|
|
193
|
+
_context3.next = 13;
|
|
194
|
+
return execAsync("yarn prettier --write ".concat(fileContent));
|
|
195
|
+
case 13:
|
|
196
|
+
console.log(chalk.green("Prettier was run successfully"));
|
|
197
|
+
case 14:
|
|
198
|
+
_context3.next = 19;
|
|
199
|
+
break;
|
|
200
|
+
case 16:
|
|
201
|
+
_context3.prev = 16;
|
|
202
|
+
_context3.t0 = _context3["catch"](4);
|
|
203
|
+
if (_context3.t0 instanceof Error) {
|
|
204
|
+
console.error(chalk.red("Unexpected error running Prettier: ".concat(_context3.t0.message)));
|
|
205
|
+
} else {
|
|
206
|
+
console.error(chalk.red('An unknown error occurred while running Prettier.'));
|
|
207
|
+
}
|
|
208
|
+
case 19:
|
|
209
|
+
case "end":
|
|
210
|
+
return _context3.stop();
|
|
211
|
+
}
|
|
212
|
+
}, _callee3, null, [[4, 16]]);
|
|
213
|
+
}));
|
|
214
|
+
return _afterAll.apply(this, arguments);
|
|
215
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { legacyLightTokens as legacyLightTheme, light as lightTheme, shape as shapeTheme, spacing as spacingTheme, typographyAdg3 as typographyAdg3Theme } from '@atlaskit/tokens/tokens-raw';
|
|
2
|
+
var typographyGroups = ['typography', 'fontWeight', 'fontFamily'];
|
|
3
|
+
function buildCombinedMap() {
|
|
4
|
+
var combinedMap = {};
|
|
5
|
+
for (var _len = arguments.length, arrays = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
6
|
+
arrays[_key] = arguments[_key];
|
|
7
|
+
}
|
|
8
|
+
arrays.forEach(function (array) {
|
|
9
|
+
array.forEach(function (token) {
|
|
10
|
+
combinedMap[token.cleanName] = token.value.toString();
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
return combinedMap;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Filter the typography tokens based on predefined groups and exclusions
|
|
17
|
+
var typographyAdg3ThemeFiltered = typographyAdg3Theme.filter(function (token) {
|
|
18
|
+
return typographyGroups.includes(token.attributes.group);
|
|
19
|
+
}).filter(function (token) {
|
|
20
|
+
return token.cleanName !== 'font.body.UNSAFE_small';
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// Cache array: [0] for light theme, [1] for legacy light theme
|
|
24
|
+
var tokenMapCache = [null, null];
|
|
25
|
+
|
|
26
|
+
// Function to get the token map with the desired theme.
|
|
27
|
+
// This should be used with the same value as the @atlaskit/tokens/babel-plugin is cofigured with for the given path.
|
|
28
|
+
// When there is no theme, the babel plugin would use the given theme to provide default token fallbacks. Therefore it's safe to remove fallbacks only when they match the fallbacks that would be generated by the babel plugin with the given theme.
|
|
29
|
+
// The default value is set to use the Light theme to match the behavior of the babel plugin (packages/design-system/tokens/src/babel-plugin/plugin.tsx).
|
|
30
|
+
export function getTokenMap() {
|
|
31
|
+
var useLegacyTheme = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
32
|
+
var themeIndex = useLegacyTheme ? 1 : 0;
|
|
33
|
+
if (!tokenMapCache[themeIndex]) {
|
|
34
|
+
var selectedTheme = useLegacyTheme ? legacyLightTheme : lightTheme;
|
|
35
|
+
tokenMapCache[themeIndex] = buildCombinedMap(selectedTheme, spacingTheme, shapeTheme, typographyAdg3ThemeFiltered);
|
|
36
|
+
}
|
|
37
|
+
return tokenMapCache[themeIndex];
|
|
38
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { diff, rgb_to_lab } from 'color-diff';
|
|
2
|
+
|
|
3
|
+
// Compare hex values using a CIEDE2000 color difference algorithm
|
|
4
|
+
export var compareHex = function compareHex(hex, hex2) {
|
|
5
|
+
return diff(rgb_to_lab(hexToRgbA(hex)), rgb_to_lab(hexToRgbA(hex2)));
|
|
6
|
+
};
|
|
7
|
+
function hexToRgbA(hex) {
|
|
8
|
+
// Remove the leading '#' if present
|
|
9
|
+
hex = hex.replace(/^#/, '');
|
|
10
|
+
// Parse the hex string
|
|
11
|
+
var r = parseInt(hex.substring(0, 2), 16);
|
|
12
|
+
var g = parseInt(hex.substring(2, 4), 16);
|
|
13
|
+
var b = parseInt(hex.substring(4, 6), 16);
|
|
14
|
+
var a = parseInt(hex.substring(6, 8), 16) / 255;
|
|
15
|
+
return {
|
|
16
|
+
R: r,
|
|
17
|
+
G: g,
|
|
18
|
+
B: b,
|
|
19
|
+
A: a
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
var namedColors = {
|
|
23
|
+
black: '#000000',
|
|
24
|
+
silver: '#C0C0C0',
|
|
25
|
+
gray: '#808080',
|
|
26
|
+
grey: '#808080',
|
|
27
|
+
pink: '#FFC0CB',
|
|
28
|
+
white: '#FFFFFF',
|
|
29
|
+
maroon: '#800000',
|
|
30
|
+
red: '#FF0000',
|
|
31
|
+
purple: '#800080',
|
|
32
|
+
fuchsia: '#FF00FF',
|
|
33
|
+
green: '#008000',
|
|
34
|
+
lime: '#00FF00',
|
|
35
|
+
olive: '#808000',
|
|
36
|
+
yellow: '#FFFF00',
|
|
37
|
+
navy: '#000080',
|
|
38
|
+
blue: '#0000FF',
|
|
39
|
+
teal: '#008080',
|
|
40
|
+
aqua: '#00FFFF'
|
|
41
|
+
};
|
|
42
|
+
export function isValidColor(color) {
|
|
43
|
+
// Check if it's a named color
|
|
44
|
+
if (namedColors[color.toLowerCase()]) {
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
// Check for hex colors (including those with alpha)
|
|
48
|
+
if (/^#([0-9A-F]{3}){1,2}([0-9A-F]{2})?$/i.test(color)) {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
// Check for rgba() values
|
|
52
|
+
if (/^rgba?\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*(?:,\s*(?:0?\.)?\d+\s*)?\)$/i.test(color)) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
export function colorToHex(color) {
|
|
58
|
+
// Handle named colors
|
|
59
|
+
if (namedColors[color.toLowerCase()]) {
|
|
60
|
+
return namedColors[color.toLowerCase()].toUpperCase() + 'FF'; // Add full opacity
|
|
61
|
+
}
|
|
62
|
+
if (color.startsWith('#')) {
|
|
63
|
+
// If it's already a hex color
|
|
64
|
+
if (color.length === 7) {
|
|
65
|
+
// #RRGGBB format, add full opacity
|
|
66
|
+
return (color + 'FF').toUpperCase();
|
|
67
|
+
} else if (color.length === 9) {
|
|
68
|
+
// #RRGGBBAA format, return as is
|
|
69
|
+
return color.toUpperCase();
|
|
70
|
+
} else if (color.length === 4) {
|
|
71
|
+
// #RGB format, expand to #RRGGBBFF
|
|
72
|
+
return ('#' + color[1] + color[1] + color[2] + color[2] + color[3] + color[3] + 'FF').toUpperCase();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// For rgb() and rgba(), convert to hex
|
|
76
|
+
var match = color.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?\)$/i);
|
|
77
|
+
if (match) {
|
|
78
|
+
var r = parseInt(match[1], 10);
|
|
79
|
+
var g = parseInt(match[2], 10);
|
|
80
|
+
var b = parseInt(match[3], 10);
|
|
81
|
+
var a = match[4] !== undefined ? Math.round(parseFloat(match[4]) * 255) : 255;
|
|
82
|
+
return "#".concat(((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1).padStart(6, '0')).concat(a.toString(16).padStart(2, '0')).toUpperCase();
|
|
83
|
+
}
|
|
84
|
+
// If conversion is not possible, return the original color
|
|
85
|
+
return color;
|
|
86
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
+
import readPkgUp from 'read-pkg-up';
|
|
4
|
+
/**
|
|
5
|
+
* Looks for the closest package.json and gets team and package information from it.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} filePath
|
|
8
|
+
* @returns {Promise<AtlassianTeamInfo>}
|
|
9
|
+
*/
|
|
10
|
+
export var getTeamInfo = /*#__PURE__*/function () {
|
|
11
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(filePath) {
|
|
12
|
+
var _pkgJson$packageJson$;
|
|
13
|
+
var pkgJson, packageName, teamName;
|
|
14
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
15
|
+
while (1) switch (_context.prev = _context.next) {
|
|
16
|
+
case 0:
|
|
17
|
+
_context.next = 2;
|
|
18
|
+
return readPkgUp({
|
|
19
|
+
cwd: filePath
|
|
20
|
+
});
|
|
21
|
+
case 2:
|
|
22
|
+
pkgJson = _context.sent;
|
|
23
|
+
if (!(!pkgJson || !pkgJson.packageJson)) {
|
|
24
|
+
_context.next = 5;
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
throw new Error("Closest package.json file could not be found or is invalid for ".concat(filePath, "."));
|
|
28
|
+
case 5:
|
|
29
|
+
packageName = pkgJson.packageJson.name || '';
|
|
30
|
+
teamName = ((_pkgJson$packageJson$ = pkgJson.packageJson.atlassian) === null || _pkgJson$packageJson$ === void 0 ? void 0 : _pkgJson$packageJson$.team) || '';
|
|
31
|
+
return _context.abrupt("return", {
|
|
32
|
+
packageName: packageName,
|
|
33
|
+
teamName: teamName
|
|
34
|
+
});
|
|
35
|
+
case 8:
|
|
36
|
+
case "end":
|
|
37
|
+
return _context.stop();
|
|
38
|
+
}
|
|
39
|
+
}, _callee);
|
|
40
|
+
}));
|
|
41
|
+
return function getTeamInfo(_x) {
|
|
42
|
+
return _ref.apply(this, arguments);
|
|
43
|
+
};
|
|
44
|
+
}();
|