@atlaskit/codemod-cli 0.11.4 → 0.12.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/CHANGELOG.md +17 -0
- package/dist/cjs/cli.js +72 -75
- package/dist/cjs/filepath.js +29 -83
- package/dist/cjs/index.js +3 -6
- package/dist/cjs/main.js +165 -441
- package/dist/cjs/presets/css-to-design-tokens/css-to-design-tokens.js +44 -135
- package/dist/cjs/presets/css-to-design-tokens/utils/legacy-colors.js +3 -4
- package/dist/cjs/presets/css-to-design-tokens/utils/meta.js +6 -29
- package/dist/cjs/presets/index.js +2 -9
- package/dist/cjs/presets/styled-to-emotion/styled-to-emotion.js +13 -25
- package/dist/cjs/presets/theme-to-design-tokens/theme-to-design-tokens.js +34 -82
- package/dist/cjs/presets/theme-to-design-tokens/utils/ast-meta.js +14 -41
- package/dist/cjs/presets/theme-to-design-tokens/utils/ast.js +0 -2
- package/dist/cjs/presets/theme-to-design-tokens/utils/color.js +9 -28
- package/dist/cjs/presets/theme-to-design-tokens/utils/fuzzy-search.js +44 -106
- package/dist/cjs/presets/theme-to-design-tokens/utils/legacy-colors.js +3 -3
- package/dist/cjs/presets/theme-to-design-tokens/utils/named-colors.js +1 -1
- package/dist/cjs/presets/theme-to-design-tokens/utils/tokens.js +2 -22
- package/dist/cjs/sinceRef.js +36 -92
- package/dist/cjs/transforms.js +27 -72
- package/dist/cjs/types.js +2 -45
- package/dist/cjs/utils.js +7 -20
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/filepath.js +7 -5
- package/dist/es2019/main.js +17 -51
- package/dist/es2019/presets/css-to-design-tokens/css-to-design-tokens.js +19 -51
- package/dist/es2019/presets/css-to-design-tokens/utils/legacy-colors.js +0 -1
- package/dist/es2019/presets/css-to-design-tokens/utils/meta.js +0 -6
- package/dist/es2019/presets/index.js +1 -1
- package/dist/es2019/presets/styled-to-emotion/styled-to-emotion.js +1 -4
- package/dist/es2019/presets/theme-to-design-tokens/theme-to-design-tokens.js +4 -14
- package/dist/es2019/presets/theme-to-design-tokens/utils/ast-meta.js +2 -11
- package/dist/es2019/presets/theme-to-design-tokens/utils/color.js +2 -7
- package/dist/es2019/presets/theme-to-design-tokens/utils/fuzzy-search.js +38 -95
- package/dist/es2019/presets/theme-to-design-tokens/utils/tokens.js +0 -1
- package/dist/es2019/sinceRef.js +2 -11
- package/dist/es2019/transforms.js +3 -13
- package/dist/es2019/types.js +1 -0
- package/dist/es2019/utils.js +1 -12
- package/dist/es2019/version.json +1 -1
- package/dist/esm/cli.js +53 -57
- package/dist/esm/filepath.js +51 -63
- package/dist/esm/main.js +221 -322
- package/dist/esm/presets/css-to-design-tokens/css-to-design-tokens.js +33 -71
- package/dist/esm/presets/css-to-design-tokens/utils/legacy-colors.js +0 -1
- package/dist/esm/presets/css-to-design-tokens/utils/meta.js +0 -6
- package/dist/esm/presets/index.js +1 -1
- package/dist/esm/presets/styled-to-emotion/styled-to-emotion.js +1 -4
- package/dist/esm/presets/theme-to-design-tokens/theme-to-design-tokens.js +4 -15
- package/dist/esm/presets/theme-to-design-tokens/utils/ast-meta.js +2 -11
- package/dist/esm/presets/theme-to-design-tokens/utils/color.js +2 -7
- package/dist/esm/presets/theme-to-design-tokens/utils/fuzzy-search.js +38 -95
- package/dist/esm/presets/theme-to-design-tokens/utils/tokens.js +0 -1
- package/dist/esm/sinceRef.js +49 -65
- package/dist/esm/transforms.js +4 -14
- package/dist/esm/types.js +1 -11
- package/dist/esm/utils.js +1 -12
- package/dist/esm/version.json +1 -1
- package/package.json +2 -2
- package/tmp/api-report-tmp.d.ts +0 -66
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @atlaskit/codemod-cli
|
|
2
2
|
|
|
3
|
+
## 0.12.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`56507598609`](https://bitbucket.org/atlassian/atlassian-frontend/commits/56507598609) - Skip minor dependency bump
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
|
|
13
|
+
## 0.11.5
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- [`cc84a1ed227`](https://bitbucket.org/atlassian/atlassian-frontend/commits/cc84a1ed227) - Updates default behaviour of codemods when a suggested token cannot be found
|
|
18
|
+
- Updated dependencies
|
|
19
|
+
|
|
3
20
|
## 0.11.4
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/dist/cjs/cli.js
CHANGED
|
@@ -1,91 +1,88 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.run = run;
|
|
9
|
-
|
|
10
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
-
|
|
12
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
-
|
|
14
8
|
var _meow = _interopRequireDefault(require("meow"));
|
|
15
|
-
|
|
16
9
|
var _types = require("./types");
|
|
17
|
-
|
|
18
10
|
var _main = _interopRequireDefault(require("./main"));
|
|
19
|
-
|
|
20
11
|
var _chalk = _interopRequireDefault(require("chalk"));
|
|
12
|
+
async function run() {
|
|
13
|
+
const cli = (0, _meow.default)(`
|
|
14
|
+
Usage
|
|
15
|
+
$ npx @atlaskit/codemod-cli [options] <file-paths>...
|
|
16
|
+
|
|
17
|
+
Options
|
|
18
|
+
--preset, -n select transform by preset name, avoid user interaction
|
|
19
|
+
--transform, -t the transform to run, will prompt for a transform if not provided and no module is passed
|
|
20
|
+
--since-ref, runs transforms for all packages that have been upgraded since the specified git ref
|
|
21
|
+
--packages, runs transforms for the specified comma separated list of packages, optionally include a version for each package to run all transforms since that version
|
|
22
|
+
--parser, -p babel|babylon|flow|ts|tsx parser to use for parsing the source files (default: babel)
|
|
23
|
+
--extensions, -e transform files with these file extensions (comma separated list) (default: js)
|
|
24
|
+
--ignore-pattern, ignore files that match a provided glob expression
|
|
25
|
+
--fail-on-error, return a 1 exit code when errors were found during execution of codemods
|
|
26
|
+
--version, -v version number
|
|
27
|
+
--no-filter-paths disables dependant package file path filtering logic
|
|
28
|
+
--help Help me 😱
|
|
21
29
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
30
|
+
Examples
|
|
31
|
+
# Run a codemod over the /project/src directory, will be prompted for which codemod to run
|
|
32
|
+
$ npx @atlaskit/codemod-cli /project/src
|
|
25
33
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
var cli;
|
|
29
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
30
|
-
while (1) {
|
|
31
|
-
switch (_context.prev = _context.next) {
|
|
32
|
-
case 0:
|
|
33
|
-
cli = (0, _meow.default)("\nUsage\n $ npx @atlaskit/codemod-cli [options] <file-paths>...\n\nOptions\n --preset, -n select transform by preset name, avoid user interaction\n --transform, -t the transform to run, will prompt for a transform if not provided and no module is passed\n --since-ref, runs transforms for all packages that have been upgraded since the specified git ref\n --packages, runs transforms for the specified comma separated list of packages, optionally include a version for each package to run all transforms since that version\n --parser, -p babel|babylon|flow|ts|tsx parser to use for parsing the source files (default: babel)\n --extensions, -e transform files with these file extensions (comma separated list) (default: js)\n --ignore-pattern, ignore files that match a provided glob expression\n --fail-on-error, return a 1 exit code when errors were found during execution of codemods\n --version, -v version number\n --no-filter-paths disables dependant package file path filtering logic \n --help Help me \uD83D\uDE31\n\nExamples\n # Run a codemod over the /project/src directory, will be prompted for which codemod to run\n $ npx @atlaskit/codemod-cli /project/src\n\n # Run the \"4.0.0-remove-appearance-prop\" transform of the \"button\" package\n $ npx @atlaskit/codemod-cli -t button@4.0.0-remove-appearance-prop /project/src\n\n # Run all transforms for \"@atlaskit/button\" greater than version 3.0.0 and @atlaskit/range greater than 4.0.0\n $ npx @atlaskit/codemod-cli --packages @atlaskit/button@3.0.0,@atlaskit/range@4.0.0 /project/src\n", {
|
|
34
|
-
flags: {
|
|
35
|
-
transform: {
|
|
36
|
-
type: 'string',
|
|
37
|
-
alias: 't'
|
|
38
|
-
},
|
|
39
|
-
preset: {
|
|
40
|
-
type: 'string',
|
|
41
|
-
alias: 'n'
|
|
42
|
-
},
|
|
43
|
-
packages: {
|
|
44
|
-
type: 'string'
|
|
45
|
-
},
|
|
46
|
-
parser: {
|
|
47
|
-
type: 'string',
|
|
48
|
-
alias: 'p'
|
|
49
|
-
},
|
|
50
|
-
extensions: {
|
|
51
|
-
type: 'string',
|
|
52
|
-
alias: 'e'
|
|
53
|
-
},
|
|
54
|
-
ignorePattern: {
|
|
55
|
-
type: 'string'
|
|
56
|
-
},
|
|
57
|
-
sinceRef: {
|
|
58
|
-
type: 'string'
|
|
59
|
-
},
|
|
60
|
-
failOnError: {
|
|
61
|
-
type: 'boolean'
|
|
62
|
-
},
|
|
63
|
-
filterPaths: {
|
|
64
|
-
type: 'boolean',
|
|
65
|
-
default: true
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
(0, _main.default)(cli.input, cli.flags).catch(function (e) {
|
|
70
|
-
if (e instanceof _types.ValidationError) {
|
|
71
|
-
console.error(cli.help);
|
|
72
|
-
console.error(_chalk.default.red(e.message));
|
|
73
|
-
process.exit(1);
|
|
74
|
-
} else if (e instanceof _types.NoTransformsExistError) {
|
|
75
|
-
console.warn(_chalk.default.yellow(e.message));
|
|
76
|
-
process.exit(0);
|
|
77
|
-
} else {
|
|
78
|
-
console.error(_chalk.default.red(e));
|
|
79
|
-
process.exit(3);
|
|
80
|
-
}
|
|
81
|
-
});
|
|
34
|
+
# Run the "4.0.0-remove-appearance-prop" transform of the "button" package
|
|
35
|
+
$ npx @atlaskit/codemod-cli -t button@4.0.0-remove-appearance-prop /project/src
|
|
82
36
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
37
|
+
# Run all transforms for "@atlaskit/button" greater than version 3.0.0 and @atlaskit/range greater than 4.0.0
|
|
38
|
+
$ npx @atlaskit/codemod-cli --packages @atlaskit/button@3.0.0,@atlaskit/range@4.0.0 /project/src
|
|
39
|
+
`, {
|
|
40
|
+
flags: {
|
|
41
|
+
transform: {
|
|
42
|
+
type: 'string',
|
|
43
|
+
alias: 't'
|
|
44
|
+
},
|
|
45
|
+
preset: {
|
|
46
|
+
type: 'string',
|
|
47
|
+
alias: 'n'
|
|
48
|
+
},
|
|
49
|
+
packages: {
|
|
50
|
+
type: 'string'
|
|
51
|
+
},
|
|
52
|
+
parser: {
|
|
53
|
+
type: 'string',
|
|
54
|
+
alias: 'p'
|
|
55
|
+
},
|
|
56
|
+
extensions: {
|
|
57
|
+
type: 'string',
|
|
58
|
+
alias: 'e'
|
|
59
|
+
},
|
|
60
|
+
ignorePattern: {
|
|
61
|
+
type: 'string'
|
|
62
|
+
},
|
|
63
|
+
sinceRef: {
|
|
64
|
+
type: 'string'
|
|
65
|
+
},
|
|
66
|
+
failOnError: {
|
|
67
|
+
type: 'boolean'
|
|
68
|
+
},
|
|
69
|
+
filterPaths: {
|
|
70
|
+
type: 'boolean',
|
|
71
|
+
default: true
|
|
87
72
|
}
|
|
88
|
-
}
|
|
89
|
-
})
|
|
90
|
-
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
(0, _main.default)(cli.input, cli.flags).catch(e => {
|
|
76
|
+
if (e instanceof _types.ValidationError) {
|
|
77
|
+
console.error(cli.help);
|
|
78
|
+
console.error(_chalk.default.red(e.message));
|
|
79
|
+
process.exit(1);
|
|
80
|
+
} else if (e instanceof _types.NoTransformsExistError) {
|
|
81
|
+
console.warn(_chalk.default.yellow(e.message));
|
|
82
|
+
process.exit(0);
|
|
83
|
+
} else {
|
|
84
|
+
console.error(_chalk.default.red(e));
|
|
85
|
+
process.exit(3);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
91
88
|
}
|
package/dist/cjs/filepath.js
CHANGED
|
@@ -1,94 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
6
|
exports.findDependentPackagePaths = findDependentPackagePaths;
|
|
9
|
-
|
|
10
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
-
|
|
12
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
-
|
|
14
7
|
var _glob = require("glob");
|
|
15
|
-
|
|
16
8
|
var _fs = require("fs");
|
|
9
|
+
const {
|
|
10
|
+
readFile
|
|
11
|
+
} = _fs.promises;
|
|
17
12
|
|
|
18
|
-
var readFile = _fs.promises.readFile;
|
|
19
13
|
/** Return products packages filePaths for running codemods from specified dependent package */
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
47
|
-
while (1) {
|
|
48
|
-
switch (_context.prev = _context.next) {
|
|
49
|
-
case 0:
|
|
50
|
-
fileContents = readFile(filePath, 'utf8'); // Grep for installedPackage
|
|
51
|
-
|
|
52
|
-
_context.next = 3;
|
|
53
|
-
return fileContents;
|
|
54
|
-
|
|
55
|
-
case 3:
|
|
56
|
-
isMatch = _context.sent.toString().split(/\n/).some(function (line) {
|
|
57
|
-
return line.match(dependencyPackage);
|
|
58
|
-
});
|
|
59
|
-
return _context.abrupt("return", isMatch && filePath);
|
|
60
|
-
|
|
61
|
-
case 5:
|
|
62
|
-
case "end":
|
|
63
|
-
return _context.stop();
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}, _callee);
|
|
67
|
-
}));
|
|
68
|
-
|
|
69
|
-
return function (_x3) {
|
|
70
|
-
return _ref.apply(this, arguments);
|
|
71
|
-
};
|
|
72
|
-
}());
|
|
73
|
-
_context2.next = 6;
|
|
74
|
-
return Promise.all(productPackageJsonPathPromises);
|
|
75
|
-
|
|
76
|
-
case 6:
|
|
77
|
-
productPackageJsonPaths = _context2.sent.filter(function (path) {
|
|
78
|
-
return path !== false;
|
|
79
|
-
});
|
|
80
|
-
// Get directory
|
|
81
|
-
productPackagePaths = productPackageJsonPaths.map(function (line) {
|
|
82
|
-
return line.replace('/package.json', '');
|
|
83
|
-
});
|
|
84
|
-
return _context2.abrupt("return", productPackagePaths);
|
|
85
|
-
|
|
86
|
-
case 9:
|
|
87
|
-
case "end":
|
|
88
|
-
return _context2.stop();
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}, _callee2);
|
|
92
|
-
}));
|
|
93
|
-
return _findDependentPackagePaths.apply(this, arguments);
|
|
14
|
+
async function findDependentPackagePaths(crawlPaths, dependencyPackage) {
|
|
15
|
+
// Get file paths leading to package.jsons
|
|
16
|
+
const searchStrings = crawlPaths.map(crawlPath => {
|
|
17
|
+
//Replace leading './' due to bug with node-glob not properly ignoring files https://github.com/isaacs/node-glob/issues/309
|
|
18
|
+
return `${crawlPath.replace(/^\.\//, '')}/**/package.json`;
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
// Convert array into glob string
|
|
22
|
+
const globString = searchStrings.length > 1 ? `{${searchStrings.join(',')}}` : searchStrings[0];
|
|
23
|
+
const packageJsonPaths = _glob.glob.sync(globString, {
|
|
24
|
+
ignore: '**/node_modules/**',
|
|
25
|
+
nodir: true
|
|
26
|
+
});
|
|
27
|
+
let productPackageJsonPathPromises = packageJsonPaths.map(async filePath => {
|
|
28
|
+
const fileContents = readFile(filePath, 'utf8');
|
|
29
|
+
// Grep for installedPackage
|
|
30
|
+
const isMatch = (await fileContents).toString().split(/\n/).some(function (line) {
|
|
31
|
+
return line.match(dependencyPackage);
|
|
32
|
+
});
|
|
33
|
+
return isMatch && filePath;
|
|
34
|
+
});
|
|
35
|
+
const productPackageJsonPaths = (await Promise.all(productPackageJsonPathPromises)).filter(path => path !== false);
|
|
36
|
+
|
|
37
|
+
// Get directory
|
|
38
|
+
const productPackagePaths = productPackageJsonPaths.map(line => line.replace('/package.json', ''));
|
|
39
|
+
return productPackagePaths;
|
|
94
40
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,29 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
Object.defineProperty(exports, "NoTransformsExistError", {
|
|
9
8
|
enumerable: true,
|
|
10
|
-
get: function
|
|
9
|
+
get: function () {
|
|
11
10
|
return _types.NoTransformsExistError;
|
|
12
11
|
}
|
|
13
12
|
});
|
|
14
13
|
Object.defineProperty(exports, "ValidationError", {
|
|
15
14
|
enumerable: true,
|
|
16
|
-
get: function
|
|
15
|
+
get: function () {
|
|
17
16
|
return _types.ValidationError;
|
|
18
17
|
}
|
|
19
18
|
});
|
|
20
19
|
Object.defineProperty(exports, "default", {
|
|
21
20
|
enumerable: true,
|
|
22
|
-
get: function
|
|
21
|
+
get: function () {
|
|
23
22
|
return _main.default;
|
|
24
23
|
}
|
|
25
24
|
});
|
|
26
|
-
|
|
27
25
|
var _main = _interopRequireDefault(require("./main"));
|
|
28
|
-
|
|
29
26
|
var _types = require("./types");
|