forked from amzn/style-dictionary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
144 lines (123 loc) · 4.8 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
var chalk = require('chalk');
var GroupMessages = require('./lib/utils/groupMessages');
var TEMPLATE_DEPRECATION_WARNINGS = GroupMessages.GROUP.TemplateDeprecationWarnings;
var REGISTER_TEMPLATE_DEPRECATION_WARNINGS = GroupMessages.GROUP.RegisterTemplateDeprecationWarnings;
var SASS_MAP_FORMAT_DEPRECATION_WARNINGS = GroupMessages.GROUP.SassMapFormatDeprecationWarnings;
/**
* Style Dictionary module
*
* @module style-dictionary
* @typicalname StyleDictionary
* @example
* ```js
* const StyleDictionary = require('style-dictionary').extend('config.json');
*
* StyleDictionary.buildAllPlatforms();
* ```
*/
var StyleDictionary = {
VERSION: require('./package.json').version,
properties: {},
allProperties: [],
options: {},
transform: require('./lib/common/transforms'),
transformGroup: require('./lib/common/transformGroups'),
format: require('./lib/common/formats'),
action: require('./lib/common/actions'),
filter: {}, // we need to initialise the object, since we don't have built-in filters
registerTransform: require('./lib/register/transform'),
registerTransformGroup: require('./lib/register/transformGroup'),
registerFormat: require('./lib/register/format'),
registerTemplate: require('./lib/register/template'),
registerAction: require('./lib/register/action'),
registerFilter: require('./lib/register/filter'),
exportPlatform: require('./lib/exportPlatform'),
buildPlatform: require('./lib/buildPlatform'),
buildAllPlatforms: require('./lib/buildAllPlatforms'),
cleanPlatform: require('./lib/cleanPlatform'),
cleanAllPlatforms: require('./lib/cleanAllPlatforms'),
extend: require('./lib/extend')
};
module.exports = StyleDictionary;
process.on('exit', function () {
if(GroupMessages.count(TEMPLATE_DEPRECATION_WARNINGS) > 0) {
var template_warnings = GroupMessages.flush(TEMPLATE_DEPRECATION_WARNINGS).join('\n ');
console.log(chalk.bold.yellow(`
⚠️ DEPRECATION WARNING ️️️️️⚠️
Templates are deprecated and will be removed, please update your config to use formats.
This is an example of how to update your config.json:
Before:
"files": [{
"destination": "colors.xml",
"template": "android/colors"
}]
After:
"files": [{
"destination": "colors.xml",
"format": "android/colors"
}]
Your current config uses the following templates:
${template_warnings}
`));
}
if(GroupMessages.count(REGISTER_TEMPLATE_DEPRECATION_WARNINGS) > 0) {
var register_template_warnings = GroupMessages.flush(REGISTER_TEMPLATE_DEPRECATION_WARNINGS).join('\n ');
console.log(chalk.bold.yellow(`
⚠️ DEPRECATION WARNING ️️️️️⚠️
The registerTemplate method is deprecated and will be removed, please
migrate to registerFormat. You can use any templating engine you would
like, you only need to require/import it. This is an example of how to
update your code using a lodash template (the template engine previously
used by registerTemplate):
Before:
registerTemplate({
name: 'template/name',
template: templateFile,
});
After:
registerFormat({
name: 'template/name',
formatter: _.template( fs.readFileSync( templateFile ) ),
});
Note that formatter is a function that takes in a style dictionary
and returns a string with the formatted output. There is a second
argument available that contains the configuration being used to
process the style dictionary.
Calls to registerTemplate included the registration of the following
custom templates:
${register_template_warnings}`));
}
if(GroupMessages.count(SASS_MAP_FORMAT_DEPRECATION_WARNINGS) > 0) {
var sass_map_format_warnings = GroupMessages.flush(SASS_MAP_FORMAT_DEPRECATION_WARNINGS).join('\n ');
console.log(chalk.bold.cyan(`
🔔 NOTICE 🔔
The formats 'sass/map-***' have been renamed to 'scss/map-***', please update your config.
In the future 'sass/map-***' formats may output actual Sass instead of SCSS, which may break your current configuration.
This is an example of how to update your config.json:
Before:
"files": [{
"destination": "tokens_map-flat.scss",
"format": "sass/map-flat"
}]
After:
"files": [{
"destination": "tokens_map-flat.scss",
"format": "scss/map-flat"
}]
Your current config uses the following formats:
${sass_map_format_warnings}
`));
}
});