-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
402 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
.DS_Store | ||
node_modules | ||
/dist | ||
# static export build | ||
tcv-build | ||
|
||
# local env files | ||
.env.local | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const fs = require('fs-extra') | ||
const path = require('path') | ||
const crypto = require('crypto') | ||
const replace = require('replace-in-file') | ||
const { resolveConfigToJson } = require('../lib/tailwindConfigUtils') | ||
|
||
module.exports = function (outputDir, config) { | ||
outputDir = path.resolve(process.cwd(), outputDir) | ||
|
||
fs.removeSync(outputDir) | ||
fs.mkdirSync(outputDir) | ||
|
||
const configJson = resolveConfigToJson(config) | ||
const configFileName = generateConfigFileNameFromJson(configJson) | ||
|
||
fs.writeFileSync(path.resolve(outputDir, configFileName), configJson) | ||
|
||
fs.copySync('./dist', outputDir) | ||
|
||
replace.sync({ | ||
files: `${outputDir}/index.html`, | ||
from: 'config.json', | ||
to: configFileName | ||
}) | ||
} | ||
|
||
function generateConfigFileNameFromJson (configJson) { | ||
const configFileHash = crypto.createHash('md5').update(configJson).digest('hex') | ||
|
||
return `config.${configFileHash.substr(0, 8)}.json` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,27 @@ | ||
#!/usr/bin/env node | ||
const program = require('commander') | ||
|
||
require('../server/index.js') | ||
program | ||
.option('-c, --config <path>', 'Path to your Tailwind config file', 'tailwind.config.js') | ||
|
||
program | ||
.command('serve', { isDefault: true }) | ||
.description('Serve the viewer') | ||
.option('-p, --port <port>', 'Port to run the viewer on', 3000) | ||
.option('-o, --open', 'Open the viewer in default browser') | ||
.action(args => { | ||
require('../server')({ | ||
port: args.port, | ||
tailwindConfigPath: program.config, | ||
shouldOpen: args.open | ||
}) | ||
}) | ||
|
||
program | ||
.command('export [outputDir]') | ||
.description('Create a static export of the viewer') | ||
.action((outputDir = './tcv-build') => { | ||
require('./export')(outputDir, program.config) | ||
}) | ||
|
||
program.parse(process.argv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const path = require('path') | ||
const resolveTailwindConfig = require('tailwindcss/resolveConfig') | ||
|
||
const resolveConfigPath = configPath => path.resolve(process.cwd(), configPath) | ||
|
||
const resolveConfig = configPath => { | ||
const config = require(resolveConfigPath(configPath)) | ||
return resolveTailwindConfig(config) | ||
} | ||
|
||
const resolveConfigToJson = configPath => JSON.stringify(resolveConfig(configPath)) | ||
|
||
module.exports = { | ||
resolveConfig, | ||
resolveConfigPath, | ||
resolveConfigToJson | ||
} |
Oops, something went wrong.