@occmundial/occ-atomic 1.20.1 → 1.21.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 +7 -0
- package/build/plugin/babel.js +59 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
# [1.21.0](https://github.com/occmundial/occ-atomic/compare/v1.20.1...v1.21.0) (2022-02-16)
|
2
|
+
|
3
|
+
|
4
|
+
### Features
|
5
|
+
|
6
|
+
* Implement babel plugin ([a73c4fe](https://github.com/occmundial/occ-atomic/commit/a73c4fe73abd82e8c159ed7b6bfae0e26ecb613b))
|
7
|
+
|
1
8
|
## [1.20.1](https://github.com/occmundial/occ-atomic/compare/v1.20.0...v1.20.1) (2022-01-31)
|
2
9
|
|
3
10
|
|
@@ -0,0 +1,59 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var types = require('@babel/types');
|
4
|
+
|
5
|
+
function error(msg) {
|
6
|
+
throw new Error("babel-plugin-occ-atomic: ".concat(msg));
|
7
|
+
}
|
8
|
+
|
9
|
+
function getImportsList(path) {
|
10
|
+
return path.node.specifiers.filter(function (specifier) {
|
11
|
+
if (specifier.type !== 'ImportSpecifier') {
|
12
|
+
error('Import entire module detected. Using this syntax means we cannot tree shake properly.');
|
13
|
+
} else return true;
|
14
|
+
});
|
15
|
+
}
|
16
|
+
|
17
|
+
function importDeclaration(specifier, path) {
|
18
|
+
return types.importDeclaration([specifier], types.stringLiteral(path));
|
19
|
+
}
|
20
|
+
|
21
|
+
function replaceImport(path, statements) {
|
22
|
+
if (statements.length > 0) {
|
23
|
+
path.replaceWithMultiple(statements);
|
24
|
+
}
|
25
|
+
|
26
|
+
return path;
|
27
|
+
}
|
28
|
+
|
29
|
+
var subatomic = ['colors', 'fonts', 'grid', 'icons', 'iconSizes', 'shadows', 'spacing'];
|
30
|
+
|
31
|
+
function importModule(path) {
|
32
|
+
var importsList = getImportsList(path);
|
33
|
+
var importStatements = importsList.map(function (specifier) {
|
34
|
+
var importName = specifier.imported.name;
|
35
|
+
|
36
|
+
if (importName === 'toaster') {
|
37
|
+
return importDeclaration(specifier, '@occmundial/occ-atomic/build/Toaster/functions');
|
38
|
+
} else if (importName === 'Nav' || importName === 'Menu') {
|
39
|
+
return importDeclaration(specifier, "@occmundial/occ-atomic/build/Header/".concat(importName));
|
40
|
+
} else if (subatomic.includes(importName)) {
|
41
|
+
return importDeclaration(types.importDefaultSpecifier(types.identifier(importName)), "@occmundial/occ-atomic/build/subatomic/".concat(importName));
|
42
|
+
}
|
43
|
+
|
44
|
+
return importDeclaration(types.importDefaultSpecifier(types.identifier(importName)), "@occmundial/occ-atomic/build/".concat(importName));
|
45
|
+
});
|
46
|
+
replaceImport(path, importStatements);
|
47
|
+
}
|
48
|
+
|
49
|
+
module.exports = function () {
|
50
|
+
return {
|
51
|
+
visitor: {
|
52
|
+
ImportDeclaration: function ImportDeclaration(path) {
|
53
|
+
if (path.node.source.value === '@occmundial/occ-atomic') {
|
54
|
+
return importModule(path);
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
};
|
59
|
+
};
|
package/package.json
CHANGED