Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breakpoint Generator (CLI support) #13

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 38 additions & 22 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const fileExists = require('file-exists')
const cssstats = require('cssstats')
const trailingLines = require('single-trailing-newline')
const authorsToMd = require('authors-to-markdown')
const pathExists = require('path-exists');
const generate = require('tachyons-build-mediaquerie')

const tachyonsBuildCss = require('tachyons-build-css')

Expand All @@ -26,8 +28,10 @@ const cli = meow(`
-n, --new Generate a new Tachyons project
--generate-docs Generate documentation for a given module
--package The path to the module package to be documented
--customMedia Generate media queries for single files or a directory

Example
$ tachyons src/ --customMedia --variables=src/variables.css --overwrite=false
$ tachyons src/tachyons.css > dist/c.css
$ tachyons src/tachyons.css > dist/c.css --minify
$ tachyons src/tachyons.css > dist/c.repeated.css --repeat
Expand All @@ -45,36 +49,46 @@ const cli = meow(`
const inputFile = cli.input[0]
const outputFile = cli.input[1]


if (cli.flags.customMedia) {

generate(inputFile, {
variables: cli.flags.variables,
overwrite: cli.flags.overwrite
})

} else {

if (cli.flags.new) {
console.log('Generating a new Tachyons project')
const projDir = cli.flags.new == true ? 'tachyons-project' : cli.flags.new
console.log('Generating a new Tachyons project')
const projDir = cli.flags.new == true ? 'tachyons-project' : cli.flags.new

mkdirp.sync(projDir)
mkdirp.sync(projDir + '/src')
mkdirp.sync(projDir + '/css')
mkdirp.sync(projDir)
mkdirp.sync(projDir + '/src')
mkdirp.sync(projDir + '/css')

const index = fs.readFileSync(__dirname + '/templates/new/index.html','utf8')
const pkg = fs.readFileSync(__dirname + '/templates/new/package.json', 'utf8')
const readme = fs.readFileSync(__dirname + '/templates/new/readme.md', 'utf8')
const style = fs.readFileSync(__dirname + '/templates/new/src/styles.css', 'utf8')
const index = fs.readFileSync(__dirname + '/templates/new/index.html','utf8')
const pkg = fs.readFileSync(__dirname + '/templates/new/package.json', 'utf8')
const readme = fs.readFileSync(__dirname + '/templates/new/readme.md', 'utf8')
const style = fs.readFileSync(__dirname + '/templates/new/src/styles.css', 'utf8')

fs.writeFileSync(projDir + '/index.html', index)
fs.writeFileSync(projDir + '/package.json', pkg)
fs.writeFileSync(projDir + '/readme.md', readme)
fs.writeFileSync(projDir + '/src/styles.css', style)
fs.writeFileSync(projDir + '/index.html', index)
fs.writeFileSync(projDir + '/package.json', pkg)
fs.writeFileSync(projDir + '/readme.md', readme)
fs.writeFileSync(projDir + '/src/styles.css', style)

console.log('New project located in ' + projDir)
process.exit(0)
console.log('New project located in ' + projDir)
process.exit(0)
}

if (isBlank(inputFile)) {
console.error(chalk.red('Please provide an input stylesheet'))
console.log(cli.help)
process.exit(1)
} else if (!fileExists(inputFile)) {
console.error(chalk.red('File does not exist ' + inputFile))
console.log(cli.help)
process.exit(1)
console.error(chalk.red('Please provide an input stylesheet'))
console.log(cli.help)
process.exit(1)
} else if (!pathExists.sync(inputFile)) {
console.error(chalk.red('File does not exist ' + inputFile))
console.log(cli.help)
process.exit(1)
}

const input = fs.readFileSync(inputFile, 'utf8')
Expand Down Expand Up @@ -112,3 +126,5 @@ tachyonsBuildCss(input, {
process.exit(0)
}
})

}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@
"lodash": "^4.16.0",
"meow": "^3.7.0",
"mkdirp": "^0.5.1",
"path-exists": "^3.0.0",
"single-trailing-newline": "^1.0.0",
"tachyons-build-css": "^1.1.2"
"tachyons-build-css": "^1.1.2",
"tachyons-build-mediaquerie" : "git://github.com/zehfernandes/tachyons-build-mediaquerie.git"
},
"devDependencies": {
"ava": "*",
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ $ tachyons --help
-n, --new Generate a new Tachyons project
--generate-docs Generate documentation for a given module
--package The path to the module package to be documented
--customMedia Generate media queries for single files or a directory

Example
$ tachyons src/ --customMedia --variables=src/variables.css --overwrite=false
$ tachyons src/tachyons.css > dist/c.css
$ tachyons src/tachyons.css > dist/c.css --minify
$ tachyons src/tachyons.css > dist/c.repeated.css --repeat
Expand Down