2020-02-09 00:13:49 +00:00
#!/bin/zsh
2020-04-25 21:00:54 +00:00
DIR = " wallpaper- $1 "
NAME = " @themer/ $DIR "
ARG_PREFIX = " themer-wallpaper- $1 "
2020-02-09 00:13:49 +00:00
echo Generating $NAME ...
PACKAGES_DIR = " $( realpath " $( dirname $0 :A) /../packages " ) "
2020-04-25 21:00:54 +00:00
PACKAGE = " $PACKAGES_DIR / $DIR "
2020-02-09 00:13:49 +00:00
mkdir $PACKAGE
cat << EOF > $PACKAGE /.gitignore
node_modules
LICENSE.md
EOF
cat << EOF > $PACKAGE /.yarnrc
version-tag-prefix $NAME -v
version-git-message $NAME -v%s
EOF
cat << EOF > $PACKAGE /package.json
{
"name" : " $NAME " ,
"version" : "1.0.0" ,
"description" : "A wallpaper generator for themer." ,
"main" : "lib/index.js" ,
"engines" : {
"node" : ">=8.11.4"
} ,
"scripts" : {
"prepublishOnly" : "cp ../../../LICENSE.md ./"
} ,
"author" : "mjswensen" ,
"license" : "MIT" ,
"files" : [
"/lib/index.js"
] ,
"repository" : {
"type" : "git" ,
"url" : "git+https://github.com/mjswensen/themer.git"
} ,
"bugs" : {
"url" : "https://github.com/mjswensen/themer/issues"
} ,
2020-04-25 21:00:54 +00:00
"homepage" : " https://github.com/mjswensen/themer/tree/master/cli/packages/ $DIR #readme " ,
2020-02-09 00:13:49 +00:00
"dependencies" : {
2020-04-25 21:00:54 +00:00
"@themer/utils" : "^1.0.0"
2020-02-09 00:13:49 +00:00
} ,
"peerDependencies" : {
"themer" : "^3"
} ,
"keywords" : [
"themer" ,
"wallpaper"
]
}
EOF
cat << EOF > $PACKAGE /README.md
# $NAME
A wallpaper template for [ themer] ( https://github.com/mjswensen/themer) .
TODO
## Installation & usage
Install this module wherever you have \` themer\` installed:
npm install $NAME
Then pass \` $NAME \` as a \` -t\` ( \` --template\` ) arg to \` themer\` :
themer -c my-colors.js -t $NAME -o gen
\` $NAME \` will generate SVG wallpapers to the output directory ( \` gen/\` in this example) . ( You can then convert them to a bitmap format, if necessary, [ using Chrome] ( https://umaar.com/dev-tips/156-element-screenshot/) or other tools.)
### Default resolutions
By default, \` $NAME \` will output wallpapers at the following sizes:
* 2880 by 1800 ( desktop)
* 750 by 1334 ( device)
### Custom resolutions
\` $NAME \` adds the following argument to \` themer\` :
2020-04-25 21:00:54 +00:00
--$ARG_PREFIX -size
2020-02-09 00:13:49 +00:00
to which you would pass \` <width>x<height>\` . For example, to forego the default resolutions and generate two wallpapers, one 1024 by 768 and one 320 by 960:
2020-04-25 21:00:54 +00:00
themer -c my-colors.js -t $NAME --$ARG_PREFIX -size 1024x768 --$ARG_PREFIX -size 320x960 -o gen
2020-02-09 00:13:49 +00:00
EOF
LIB = " $PACKAGE /lib "
mkdir $LIB
cat << EOF > $LIB /index.js
const {
getSizesFromOptOrDefault,
deepFlatten,
colorSets: getColorSets,
2020-04-25 21:00:54 +00:00
} = require( '@themer/utils' ) ;
2020-02-09 00:13:49 +00:00
const render = ( colors, options) = > {
try {
var sizes = getSizesFromOptOrDefault(
2020-04-25 21:00:54 +00:00
options[ '$ARG_PREFIX-size' ]
2020-02-09 00:13:49 +00:00
) ;
} catch ( e) {
return [ Promise.reject( e.message) ] ;
}
const colorSets = getColorSets( colors) ;
return deepFlatten(
sizes.map(
size = > colorSets.map( colorSet = > {
// TODO
} ) ,
) ,
) ;
}
module.exports = { render } ;
EOF
cat << EOF > $LIB /index.spec.js
const { render } = require( './index' ) ;
2020-04-24 12:56:56 +00:00
const { colors } = require( '../../colors-default' ) ;
2020-02-09 00:13:49 +00:00
2020-04-25 21:00:54 +00:00
describe( 'themer "$1" wallpaper' , ( ) = > {
2020-04-15 13:27:06 +00:00
it( 'should render valid SVG' , async ( ) = > {
const files = await Promise.all( render( colors, { } ) ) ;
files.forEach( file = > {
expect( file.contents.toString( 'utf8' ) ) .toMatchSnapshot( ) ;
2020-02-09 00:13:49 +00:00
} ) ;
2020-04-15 13:27:06 +00:00
} ) ;
2020-02-09 00:13:49 +00:00
} ) ;
EOF