├── CHANGELOG.md ├── .gitignore ├── logo.png ├── .travis.yml ├── .npmignore ├── .editorconfig ├── README.md ├── test.js ├── README.md.example ├── index.js ├── package.json ├── LICENSE └── start /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | npm-debug.log 3 | -------------------------------------------------------------------------------- /logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martachupil/nevskiy-postcss/HEAD/logo.png -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "6" 4 | - "4" 5 | - "0.12" 6 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .gitignore 2 | .editorconfig 3 | 4 | node_modules/ 5 | npm-debug.log 6 | 7 | test.js 8 | .travis.yml 9 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 4 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | 11 | [*.{json,yml}] 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 4 | 5 | # Плагин цитат Невского для PostCSS 6 | 7 | ## Пример 8 | 9 | **source.css** 10 | ```scss 11 | .nevskiy { 12 | position: абсолютли; 13 | font-size: 10px вотаквот; 14 | } 15 | ``` 16 | 17 | **result.css** 18 | ```scss 19 | .nevskiy { 20 | position: absolute; 21 | font-size: 10px !important; 22 | } 23 | ``` 24 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import postcss from 'postcss'; 2 | import test from 'ava'; 3 | 4 | import plugin from './'; 5 | 6 | function run(t, input, output, opts = { }) { 7 | return postcss([ plugin(opts) ]).process(input) 8 | .then( result => { 9 | t.deepEqual(result.css, output); 10 | t.deepEqual(result.warnings().length, 0); 11 | }); 12 | } 13 | 14 | /* Write tests here 15 | 16 | test('does something', t => { 17 | return run(t, 'a{ }', 'a{ }', { }); 18 | }); 19 | 20 | */ 21 | -------------------------------------------------------------------------------- /README.md.example: -------------------------------------------------------------------------------- 1 | # PLUGIN_TITLE [![Build Status][ci-img]][ci] 2 | 3 | [PostCSS] plugin PLUGIN_DESC. 4 | 5 | [PostCSS]: https://github.com/postcss/postcss 6 | [ci-img]: https://travis-ci.org/GITHUB_NAME/PLUGIN_NAME.svg 7 | [ci]: https://travis-ci.org/GITHUB_NAME/PLUGIN_NAME 8 | 9 | ```css 10 | .foo { 11 | /* Input example */ 12 | } 13 | ``` 14 | 15 | ```css 16 | .foo { 17 | /* Output example */ 18 | } 19 | ``` 20 | 21 | ## Usage 22 | 23 | ```js 24 | postcss([ require('PLUGIN_NAME') ]) 25 | ``` 26 | 27 | See [PostCSS] docs for examples for your environment. 28 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var postcss = require('postcss'); 2 | 3 | module.exports = postcss.plugin('nss', function (opts) { 4 | opts = opts || {}; 5 | var gvalues = { 6 | 'абсолютли':'absolute', 7 | 'вотаквот': '!important' 8 | }; 9 | 10 | // Work with options here 11 | 12 | return function (css, result) { 13 | css.walkDecls( function(decl) { 14 | 15 | // Search for available keyword 16 | var val = decl.value.toString(); 17 | 18 | // Replace expressions 19 | for(var key in gvalues) { 20 | var reg = new RegExp(key); 21 | val = val.replace( reg, gvalues[key] ); 22 | } 23 | 24 | decl.value = val.toString(); 25 | }); 26 | 27 | }; 28 | }); 29 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nevskiy-postcss", 3 | "version": "1.0.1", 4 | "description": "Поддержка цитат Александра Невского для PostCSS", 5 | "keywords": [ 6 | "postcss", 7 | "css", 8 | "невский" 9 | ], 10 | "author": "Denis Sedchenko , Marta Chupil ", 11 | "license": "MIT", 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/martachupil/nevskiy-postcss.git" 15 | }, 16 | "bugs": { 17 | "url": "https://github.com/martachupil/nevskiy-postcss/issues" 18 | }, 19 | "homepage": "https://github.com/GITHUB_NAME/PLUGIN_NAME", 20 | "dependencies": { 21 | "postcss": "^5.0.21" 22 | }, 23 | "devDependencies": { 24 | "ava": "^0.14.0", 25 | "eslint": "^2.10.0", 26 | "eslint-config-postcss": "^2.0.2" 27 | }, 28 | "scripts": { 29 | "test": "ava && eslint *.js" 30 | }, 31 | "eslintConfig": { 32 | "extends": "eslint-config-postcss/es5" 33 | }, 34 | "main": "index.js" 35 | } 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright 2016 AUTHOR_NAME 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /start: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | var exec = require('child_process').exec; 4 | var path = require('path'); 5 | var fs = require('fs'); 6 | 7 | process.stdin.resume(); 8 | process.stdin.setEncoding('utf8'); 9 | 10 | var questionCallback = null; 11 | var lastQuestion = 0; 12 | 13 | process.stdin.on('data', function (text) { 14 | questionCallback(text.trim()); 15 | }); 16 | 17 | var questions = { 18 | AUTHOR_NAME: 'Your name: ', 19 | AUTHOR_EMAIL: 'Your email: ', 20 | GITHUB_NAME: 'GitHub username: ', 21 | PLUGIN_NAME: 'Plugin name: postcss-', 22 | PLUGIN_DESC: '\nFinish sentence with plugin description:\nPostCSS plugin ', 23 | KEYWORDS: '\nFinish plugin keywords:\npostcss, css, postcss-plugin, ' 24 | }; 25 | var autodetects = { 26 | AUTHOR_NAME: 'git config user.name', 27 | AUTHOR_EMAIL: 'git config user.email' 28 | }; 29 | var answers = { }; 30 | 31 | function copyFileSync(source, target) { 32 | var targetFile = target; 33 | if ( fs.existsSync(target) ) { 34 | if ( fs.lstatSync(target).isDirectory() ) { 35 | targetFile = path.join( target, path.basename(source) ); 36 | } 37 | } 38 | fs.writeFileSync(targetFile, fs.readFileSync(source)); 39 | } 40 | 41 | function copyFolderSync(source, target) { 42 | var files = []; 43 | if ( !fs.existsSync(target) ) fs.mkdirSync(target); 44 | if ( fs.lstatSync(source).isDirectory() ) { 45 | files = fs.readdirSync(source); 46 | files.forEach(function (file) { 47 | var targetFile = path.join(target, file); 48 | var curSource = path.join(source, file); 49 | if ( fs.lstatSync(curSource).isDirectory() ) { 50 | copyFolderSync(curSource, targetFile); 51 | } else { 52 | copyFileSync(curSource, target); 53 | } 54 | }); 55 | } 56 | } 57 | 58 | function fillFiles(dir) { 59 | fs.readdirSync(dir).forEach(function (file) { 60 | if ( file === '.git' ) return; 61 | 62 | var filepath = path.join(dir, file); 63 | if ( fs.lstatSync(filepath).isDirectory() ) { 64 | fillFiles(filepath); 65 | 66 | } else { 67 | var content = fs.readFileSync(filepath).toString(); 68 | for ( var code in answers ) { 69 | while ( content.indexOf(code) !== -1 ) { 70 | content = content.replace(code, answers[code]); 71 | } 72 | } 73 | fs.writeFileSync(filepath, content); 74 | } 75 | }); 76 | } 77 | 78 | function cleanRepo(dir, callback) { 79 | var readme = path.join(dir, 'README.md'); 80 | fs.unlinkSync(readme); 81 | fs.renameSync(readme + '.example', readme); 82 | fs.unlinkSync(path.join(dir, 'start')); 83 | exec('cd "' + dir + '" && rm -Rf .git/', callback); 84 | } 85 | 86 | function initProject(dir, callback) { 87 | process.stdout.write('\nInstalling npm packages...'); 88 | exec('cd "' + dir + '" && git init && npm install', callback); 89 | } 90 | 91 | function autodetect(code, callback) { 92 | var command = autodetects[code]; 93 | if ( !command ) return callback(); 94 | 95 | try { 96 | exec(command, function (_, stdout) { 97 | var value = stdout.trim(); 98 | if ( value ) { 99 | process.stdout.write(questions[code] + value + '\n'); 100 | answers[code] = value; 101 | lastQuestion += 1; 102 | nextQuestion(); 103 | } else { 104 | callback(); 105 | } 106 | }); 107 | } catch (error) { 108 | callback(); 109 | } 110 | } 111 | 112 | function nextQuestion() { 113 | var code = Object.keys(questions)[lastQuestion]; 114 | if ( code ) { 115 | autodetect(code, function () { 116 | process.stdout.write(questions[code]); 117 | questionCallback = function (result) { 118 | if ( result === '' ) { 119 | nextQuestion(); 120 | } else { 121 | answers[code] = result; 122 | lastQuestion += 1; 123 | nextQuestion(); 124 | } 125 | }; 126 | }); 127 | 128 | } else { 129 | answers.PLUGIN_NAME = 'postcss-' + answers.PLUGIN_NAME; 130 | answers.PLUGIN_TITLE = answers.PLUGIN_NAME 131 | .replace(/-\w/g, function (str) { 132 | return ' ' + str[1].toUpperCase(); 133 | }) 134 | .replace(/^postcss/, 'PostCSS'); 135 | answers.KEYWORDS = ',\n ' + answers.KEYWORDS 136 | .split(',') 137 | .map(function (i) { 138 | return '"' + i.trim() + '"'; 139 | }) 140 | .join(',\n '); 141 | 142 | var dir = path.join(__dirname, '..', answers.PLUGIN_NAME); 143 | copyFolderSync(__dirname, dir); 144 | fillFiles(dir); 145 | cleanRepo(dir, function () { 146 | initProject(dir, function () { 147 | process.stdout.write( 148 | '\nDone. Remove this dir and continue work in ' + 149 | '../' + answers.PLUGIN_NAME + '/\n'); 150 | process.exit(0); 151 | }); 152 | }); 153 | } 154 | 155 | } 156 | 157 | nextQuestion(); 158 | --------------------------------------------------------------------------------