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