Merge branch 'themer-xcode-master'

This commit is contained in:
Matt Swensen 2018-08-08 20:48:57 -06:00
commit 49e2c7e771
No known key found for this signature in database
GPG Key ID: 3F9E482BFC526F35
10 changed files with 4416 additions and 0 deletions

1
packages/themer-xcode/.gitignore vendored Normal file

@ -0,0 +1 @@
node_modules

@ -0,0 +1,2 @@
__snapshots__
index.spec.js

@ -0,0 +1,5 @@
language: node_js
node_js:
- "lts/*"
script: npm test

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 Matt Swensen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

@ -0,0 +1,19 @@
# themer-xcode [![Travis](https://img.shields.io/travis/mjswensen/themer-xcode.svg)](https://travis-ci.org/mjswensen/themer-xcode)
An Xcode theme generator for [themer](https://github.com/mjswensen/themer).
## Installation & usage
Install this module wherever you have `themer` installed:
npm install themer-xcode
Then pass `themer-xcode` as a `-t` (`--template`) arg to `themer`:
themer -c my-colors.js -t themer-xcode -o gen
## Output
`themer-xcode` will generate a `Themer Dark.dvtcolortheme` / `Themer Light.dvtcolortheme` (or both) in your output directory.
Copy (or symlink) your theme(s) to `~/Library/Developer/Xcode/UserData/FontAndColorThemes/` (you can create this directory if it does not already exist), then restart Xcode. Your theme will then be available in Preferences > Fonts and Colors.

@ -0,0 +1,173 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`render should render a properly formatted Xcode theme file 1`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>
<!DOCTYPE plist PUBLIC \\"-//Apple//DTD PLIST 1.0//EN\\" \\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\\">
<plist version=\\"1.0\\">
<dict>
<key>DVTConsoleDebuggerInputTextColor</key>
<string>1 0.988235 1 1</string>
<key>DVTConsoleDebuggerOutputTextColor</key>
<string>0.756863 0.737255 0.760784 1</string>
<key>DVTConsoleDebuggerPromptTextColor</key>
<string>0.94902 0.505882 0.266667 1</string>
<key>DVTConsoleExectuableInputTextColor</key>
<string>0.756863 0.737255 0.760784 1</string>
<key>DVTConsoleExectuableOutputTextColor</key>
<string>1 0.988235 1 1</string>
<key>DVTConsoleTextBackgroundColor</key>
<string>0.156863 0.14902 0.160784 1</string>
<key>DVTConsoleTextInsertionPointColor</key>
<string>0.8 0.470588 0.980392 1</string>
<key>DVTConsoleTextSelectionColor</key>
<string>0.278431 0.258824 0.278431 1</string>
<key>DVTDebuggerInstructionPointerColor</key>
<string>0.643137 0.8 0.207843 1</string>
<key>DVTSourceTextBackground</key>
<string>0.156863 0.14902 0.160784 1</string>
<key>DVTSourceTextBlockDimBackgroundColor</key>
<string>0.635294 0.615686 0.639216 1</string>
<key>DVTSourceTextInsertionPointColor</key>
<string>0.8 0.470588 0.980392 1</string>
<key>DVTSourceTextInvisiblesColor</key>
<string>0.278431 0.258824 0.278431 1</string>
<key>DVTSourceTextSelectionColor</key>
<string>0.278431 0.258824 0.278431 1</string>
<key>DVTSourceTextSyntaxColors</key>
<dict>
<key>xcode.syntax.attribute</key>
<string>0.643137 0.8 0.207843 1</string>
<key>xcode.syntax.character</key>
<string>0.14902 0.788235 0.619608 1</string>
<key>xcode.syntax.comment</key>
<string>0.396078 0.376471 0.4 1</string>
<key>xcode.syntax.comment.doc</key>
<string>0.517647 0.494118 0.521569 1</string>
<key>xcode.syntax.comment.doc.keyword</key>
<string>0.635294 0.615686 0.639216 1</string>
<key>xcode.syntax.identifier.class</key>
<string>1 0.823529 0.290196 1</string>
<key>xcode.syntax.identifier.class.system</key>
<string>1 0.823529 0.290196 1</string>
<key>xcode.syntax.identifier.constant</key>
<string>0.643137 0.8 0.207843 1</string>
<key>xcode.syntax.identifier.constant.system</key>
<string>0.643137 0.8 0.207843 1</string>
<key>xcode.syntax.identifier.function</key>
<string>0.14902 0.788235 0.619608 1</string>
<key>xcode.syntax.identifier.function.system</key>
<string>0.14902 0.788235 0.619608 1</string>
<key>xcode.syntax.identifier.macro</key>
<string>0.960784 0.32549 0.74902 1</string>
<key>xcode.syntax.identifier.macro.system</key>
<string>0.960784 0.32549 0.74902 1</string>
<key>xcode.syntax.identifier.type</key>
<string>1 0.25098 0.313725 1</string>
<key>xcode.syntax.identifier.type.system</key>
<string>0.94902 0.505882 0.266667 1</string>
<key>xcode.syntax.identifier.variable</key>
<string>1 0.988235 1 1</string>
<key>xcode.syntax.identifier.variable.system</key>
<string>1 0.988235 1 1</string>
<key>xcode.syntax.keyword</key>
<string>0.4 0.74902 1 1</string>
<key>xcode.syntax.number</key>
<string>0.643137 0.8 0.207843 1</string>
<key>xcode.syntax.plain</key>
<string>0.878431 0.862745 0.878431 1</string>
<key>xcode.syntax.preprocessor</key>
<string>0.8 0.470588 0.980392 1</string>
<key>xcode.syntax.string</key>
<string>0.643137 0.8 0.207843 1</string>
<key>xcode.syntax.url</key>
<string>0.4 0.74902 1 1</string>
</dict>
</dict>
</plist>"
`;
exports[`render should render a properly formatted Xcode theme file 2`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>
<!DOCTYPE plist PUBLIC \\"-//Apple//DTD PLIST 1.0//EN\\" \\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\\">
<plist version=\\"1.0\\">
<dict>
<key>DVTConsoleDebuggerInputTextColor</key>
<string>0.156863 0.14902 0.160784 1</string>
<key>DVTConsoleDebuggerOutputTextColor</key>
<string>0.396078 0.376471 0.4 1</string>
<key>DVTConsoleDebuggerPromptTextColor</key>
<string>0.952941 0.466667 0.207843 1</string>
<key>DVTConsoleExectuableInputTextColor</key>
<string>0.396078 0.376471 0.4 1</string>
<key>DVTConsoleExectuableOutputTextColor</key>
<string>0.156863 0.14902 0.160784 1</string>
<key>DVTConsoleTextBackgroundColor</key>
<string>1 0.988235 1 1</string>
<key>DVTConsoleTextInsertionPointColor</key>
<string>0.74902 0.396078 0.941176 1</string>
<key>DVTConsoleTextSelectionColor</key>
<string>0.878431 0.862745 0.878431 1</string>
<key>DVTDebuggerInstructionPointerColor</key>
<string>0.592157 0.741176 0.176471 1</string>
<key>DVTSourceTextBackground</key>
<string>1 0.988235 1 1</string>
<key>DVTSourceTextBlockDimBackgroundColor</key>
<string>0.517647 0.494118 0.521569 1</string>
<key>DVTSourceTextInsertionPointColor</key>
<string>0.74902 0.396078 0.941176 1</string>
<key>DVTSourceTextInvisiblesColor</key>
<string>0.878431 0.862745 0.878431 1</string>
<key>DVTSourceTextSelectionColor</key>
<string>0.878431 0.862745 0.878431 1</string>
<key>DVTSourceTextSyntaxColors</key>
<dict>
<key>xcode.syntax.attribute</key>
<string>0.592157 0.741176 0.176471 1</string>
<key>xcode.syntax.character</key>
<string>0.121569 0.772549 0.596078 1</string>
<key>xcode.syntax.comment</key>
<string>0.756863 0.737255 0.760784 1</string>
<key>xcode.syntax.comment.doc</key>
<string>0.635294 0.615686 0.639216 1</string>
<key>xcode.syntax.comment.doc.keyword</key>
<string>0.517647 0.494118 0.521569 1</string>
<key>xcode.syntax.identifier.class</key>
<string>0.933333 0.729412 0.129412 1</string>
<key>xcode.syntax.identifier.class.system</key>
<string>0.933333 0.729412 0.129412 1</string>
<key>xcode.syntax.identifier.constant</key>
<string>0.592157 0.741176 0.176471 1</string>
<key>xcode.syntax.identifier.constant.system</key>
<string>0.592157 0.741176 0.176471 1</string>
<key>xcode.syntax.identifier.function</key>
<string>0.121569 0.772549 0.596078 1</string>
<key>xcode.syntax.identifier.function.system</key>
<string>0.121569 0.772549 0.596078 1</string>
<key>xcode.syntax.identifier.macro</key>
<string>0.933333 0.305882 0.721569 1</string>
<key>xcode.syntax.identifier.macro.system</key>
<string>0.933333 0.305882 0.721569 1</string>
<key>xcode.syntax.identifier.type</key>
<string>0.941176 0.243137 0.301961 1</string>
<key>xcode.syntax.identifier.type.system</key>
<string>0.952941 0.466667 0.207843 1</string>
<key>xcode.syntax.identifier.variable</key>
<string>0.156863 0.14902 0.160784 1</string>
<key>xcode.syntax.identifier.variable.system</key>
<string>0.156863 0.14902 0.160784 1</string>
<key>xcode.syntax.keyword</key>
<string>0.32549 0.65098 0.882353 1</string>
<key>xcode.syntax.number</key>
<string>0.592157 0.741176 0.176471 1</string>
<key>xcode.syntax.plain</key>
<string>0.278431 0.258824 0.278431 1</string>
<key>xcode.syntax.preprocessor</key>
<string>0.74902 0.396078 0.941176 1</string>
<key>xcode.syntax.string</key>
<string>0.592157 0.741176 0.176471 1</string>
<key>xcode.syntax.url</key>
<string>0.32549 0.65098 0.882353 1</string>
</dict>
</dict>
</plist>"
`;

@ -0,0 +1,133 @@
const _ = require('lodash');
const Color = require('color');
const formatColorSet = colors =>
_.mapValues(colors, hex =>
Color(hex)
.rgb()
.array()
.concat(255)
.map(component => _.round(component / 255, 6))
.join(' ')
);
const render = colors => {
const colorSets = [
{name: 'dark', colors: colors.dark && formatColorSet(colors.dark)},
{name: 'light', colors: colors.light && formatColorSet(colors.light)},
].filter(colorSet => !!colorSet.colors);
return colorSets.map(colorSet => {
const {
shade0,
shade1,
shade2,
shade3,
shade4,
shade5,
shade6,
shade7,
accent0,
accent1,
accent2,
accent3,
accent4,
accent5,
accent6,
accent7,
} = colorSet.colors;
return Promise.resolve({
name: `Themer ${_.capitalize(colorSet.name)}.dvtcolortheme`,
contents: Buffer.from(
`<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DVTConsoleDebuggerInputTextColor</key>
<string>${shade7}</string>
<key>DVTConsoleDebuggerOutputTextColor</key>
<string>${shade5}</string>
<key>DVTConsoleDebuggerPromptTextColor</key>
<string>${accent1}</string>
<key>DVTConsoleExectuableInputTextColor</key>
<string>${shade5}</string>
<key>DVTConsoleExectuableOutputTextColor</key>
<string>${shade7}</string>
<key>DVTConsoleTextBackgroundColor</key>
<string>${shade0}</string>
<key>DVTConsoleTextInsertionPointColor</key>
<string>${accent6}</string>
<key>DVTConsoleTextSelectionColor</key>
<string>${shade1}</string>
<key>DVTDebuggerInstructionPointerColor</key>
<string>${accent3}</string>
<key>DVTSourceTextBackground</key>
<string>${shade0}</string>
<key>DVTSourceTextBlockDimBackgroundColor</key>
<string>${shade4}</string>
<key>DVTSourceTextInsertionPointColor</key>
<string>${accent6}</string>
<key>DVTSourceTextInvisiblesColor</key>
<string>${shade1}</string>
<key>DVTSourceTextSelectionColor</key>
<string>${shade1}</string>
<key>DVTSourceTextSyntaxColors</key>
<dict>
<key>xcode.syntax.attribute</key>
<string>${accent3}</string>
<key>xcode.syntax.character</key>
<string>${accent4}</string>
<key>xcode.syntax.comment</key>
<string>${shade2}</string>
<key>xcode.syntax.comment.doc</key>
<string>${shade3}</string>
<key>xcode.syntax.comment.doc.keyword</key>
<string>${shade4}</string>
<key>xcode.syntax.identifier.class</key>
<string>${accent2}</string>
<key>xcode.syntax.identifier.class.system</key>
<string>${accent2}</string>
<key>xcode.syntax.identifier.constant</key>
<string>${accent3}</string>
<key>xcode.syntax.identifier.constant.system</key>
<string>${accent3}</string>
<key>xcode.syntax.identifier.function</key>
<string>${accent4}</string>
<key>xcode.syntax.identifier.function.system</key>
<string>${accent4}</string>
<key>xcode.syntax.identifier.macro</key>
<string>${accent7}</string>
<key>xcode.syntax.identifier.macro.system</key>
<string>${accent7}</string>
<key>xcode.syntax.identifier.type</key>
<string>${accent0}</string>
<key>xcode.syntax.identifier.type.system</key>
<string>${accent1}</string>
<key>xcode.syntax.identifier.variable</key>
<string>${shade7}</string>
<key>xcode.syntax.identifier.variable.system</key>
<string>${shade7}</string>
<key>xcode.syntax.keyword</key>
<string>${accent5}</string>
<key>xcode.syntax.number</key>
<string>${accent3}</string>
<key>xcode.syntax.plain</key>
<string>${shade6}</string>
<key>xcode.syntax.preprocessor</key>
<string>${accent6}</string>
<key>xcode.syntax.string</key>
<string>${accent3}</string>
<key>xcode.syntax.url</key>
<string>${accent5}</string>
</dict>
</dict>
</plist>`,
'utf8'
),
});
});
};
module.exports = {
formatColorSet,
render,
};

@ -0,0 +1,27 @@
const {formatColorSet, render} = require('./index');
const {colors} = require('themer-colors-default');
describe('formatColorSet', () => {
it('should properly format from hex to space-delimited rounded decimal', () => {
const input = {color0: '#ff0000', color1: '#c3aed0', color2: '#15232E'};
const expected = {
color0: '1 0 0 1',
color1: '0.764706 0.682353 0.815686 1',
color2: '0.082353 0.137255 0.180392 1',
};
expect(formatColorSet(input)).toEqual(expected);
});
});
describe('render', () => {
it('should render a properly formatted Xcode theme file', done => {
Promise.all(render(colors)).then(files => {
expect(files.length).toBe(2);
files.forEach(file => {
expect(/Themer (Dark|Light)\.dvtcolortheme/.test(file.name)).toBe(true);
expect(file.contents.toString('utf8')).toMatchSnapshot();
});
done();
});
});
});

3999
packages/themer-xcode/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

@ -0,0 +1,36 @@
{
"name": "themer-xcode",
"version": "2.0.2",
"description": "An Xcode theme generator for themer.",
"main": "index.js",
"scripts": {
"test": "jest"
},
"author": "mjswensen",
"license": "MIT",
"dependencies": {
"color": "^2.0.0",
"lodash": "^4.17.4"
},
"devDependencies": {
"jest": "^21.0.1",
"themer-colors-default": "^1.0.3"
},
"peerDependencies": {
"themer": "^1.0.2||^2||^3"
},
"repository": {
"type": "git",
"url": "git+https://github.com/mjswensen/themer-xcode.git"
},
"bugs": {
"url": "https://github.com/mjswensen/themer-xcode/issues"
},
"homepage": "https://github.com/mjswensen/themer-xcode#readme",
"keywords": [
"themer",
"Xcode",
"theme",
"syntax"
]
}