-
Notifications
You must be signed in to change notification settings - Fork 10
Add TailwindCSS Template #169
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
Draft
xdega
wants to merge
4
commits into
Flutter-Bounty-Hunters:main
Choose a base branch
from
xdega:tailwind-template
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
152 changes: 152 additions & 0 deletions
152
packages/static_shock_cli/lib/src/templates/tailwind_template.dart
This file contains hidden or 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,152 @@ | ||
import 'dart:io'; | ||
import 'dart:isolate'; | ||
|
||
import 'package:args/command_runner.dart'; | ||
import 'package:mason/mason.dart'; | ||
import 'package:static_shock_cli/src/project_maintenance/build_project.dart'; | ||
import 'package:static_shock_cli/src/templates/basic_template_cli.dart'; | ||
|
||
/// Walks the user through a selection of details that are required to generate | ||
/// and then generates the project. | ||
Future<Directory> runTailwindTemplateWizard(Logger log) async { | ||
final configuration = BasicTemplateConfigurator.promptForConfiguration(log); | ||
final targetDirectory = | ||
BasicTemplateConfigurator.promptForOutputDirectory(log); | ||
|
||
await generateTailwindTemplate( | ||
targetDirectory, | ||
projectName: configuration.projectName, | ||
projectDescription: configuration.projectDescription, | ||
); | ||
|
||
return targetDirectory; | ||
} | ||
|
||
/// A CLI command that can be directly run with provided arguments, to generate | ||
/// a new Static Shock project with a minimal collection of files. | ||
class TailwindTemplateCommand extends Command { | ||
static const argProjectName = "project-name"; | ||
static const argProjectDescription = "project-description"; | ||
static const argAutoInitialize = "auto-initialize"; | ||
|
||
TailwindTemplateCommand(this.log) { | ||
argParser | ||
..addOption( | ||
argProjectName, | ||
help: | ||
"The name of the new Static Shock project - it should be a valid Dart package name.", | ||
mandatory: true, | ||
) | ||
..addOption( | ||
argProjectDescription, | ||
help: | ||
"The description of the new Static Shock project - will be added to the project's pubspec file.", | ||
defaultsTo: "", | ||
) | ||
..addFlag( | ||
argAutoInitialize, | ||
help: | ||
"True if this command should immediately run 'dart pub get' and 'shock build' after generating the project.", | ||
defaultsTo: true, | ||
); | ||
} | ||
|
||
final Logger log; | ||
|
||
@override | ||
String get name => "tailwind"; | ||
|
||
@override | ||
String get description => | ||
"Generate a new, Static Shock project with TailwindCSS pre-configured."; | ||
|
||
@override | ||
Future<void> run() async { | ||
if (!argResults!.wasParsed(argProjectName)) { | ||
log.err("Argument $argProjectName is required."); | ||
printUsage(); | ||
return; | ||
} | ||
final projectName = argResults![argProjectName] as String; | ||
final projectDescription = argResults![argProjectDescription] as String; | ||
|
||
final targetPath = argResults!.rest.lastOrNull; | ||
final targetDirectory = | ||
targetPath != null ? Directory(targetPath) : Directory.current; | ||
if (!targetDirectory.existsSync()) { | ||
try { | ||
targetDirectory.createSync(recursive: true); | ||
} catch (exception) { | ||
log.err( | ||
"Failed to create project directory: ${targetDirectory.absolute}"); | ||
log.err("$exception"); | ||
return; | ||
} | ||
} | ||
|
||
await generateTailwindTemplate( | ||
targetDirectory, | ||
projectName: projectName, | ||
projectDescription: projectDescription, | ||
); | ||
|
||
log.success("Successfully created a new Static Shock project!\n"); | ||
|
||
if (argResults![argAutoInitialize]) { | ||
// Run "shock build". | ||
await Project.build(log: log, workingDirectory: targetDirectory); | ||
|
||
// Run "pub get". | ||
await Project.pubGet(log: log, workingDirectory: targetDirectory); | ||
} | ||
|
||
log.success("Congratulations, your Static Shock project is ready to go!"); | ||
log.info("\nTo learn how to use Static Shock, check out staticshock.io\n"); | ||
} | ||
} | ||
|
||
/// Generates a new Static Shock project using the "tailwind" template, placing | ||
/// the files in the given [targetDirectory]. | ||
/// | ||
/// The generated files are configured with the given properties. | ||
Future<void> generateTailwindTemplate( | ||
Directory targetDirectory, { | ||
required String projectName, | ||
required String projectDescription, | ||
}) async { | ||
final bundle = await _loadTemplateBundle(); | ||
final generator = await MasonGenerator.fromBundle(bundle); | ||
final target = DirectoryGeneratorTarget(targetDirectory); | ||
|
||
await generator.generate(target, vars: { | ||
_templateKeyProjectName: projectName, | ||
_templateKeyProjectDescription: projectDescription, | ||
}); | ||
} | ||
|
||
Future<MasonBundle> _loadTemplateBundle() async { | ||
// We expect to run as a globally activated Dart package. To access assets bundled | ||
// with our package, we need to resolve a package path to a file system path, as | ||
// shown below. | ||
// | ||
// Note: Dart automatically looks under "lib/" within a package. When reading the | ||
// path below, mentally insert "/lib/" between the package name and the first sub-directory. | ||
// | ||
// Reference: https://stackoverflow.com/questions/72255508/how-to-get-the-file-path-to-an-asset-included-in-a-dart-package | ||
// TODO: How to create a "tailwind.bundle" | ||
final packageUri = | ||
Uri.parse('package:static_shock_cli/templates/tailwind.bundle'); | ||
final absoluteUri = await Isolate.resolvePackageUri(packageUri); | ||
|
||
final file = File.fromUri(absoluteUri!); | ||
if (!file.existsSync()) { | ||
throw Exception( | ||
"Couldn't locate the Static Shock 'tailwind' template in the package assets. Looked in: '${file.path}'"); | ||
} | ||
|
||
// Decode the file's bytes into a Mason bundle. Return it. | ||
return await MasonBundle.fromUniversalBundle(file.readAsBytesSync()); | ||
} | ||
|
||
const _templateKeyProjectName = "project_name"; | ||
const _templateKeyProjectDescription = "project_description"; |
This file contains hidden or 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 hidden or 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,15 @@ | ||
# Build output | ||
/build | ||
|
||
# https://dart.dev/guides/libraries/private-files | ||
# Created by `dart pub` | ||
.dart_tool/ | ||
|
||
# Android Studio and IntelliJ IDEA | ||
.idea | ||
|
||
.DS_Store | ||
|
||
# Avoid committing pubspec.lock for library packages; see | ||
# https://dart.dev/guides/libraries/private-files#pubspeclock. | ||
pubspec.lock |
This file contains hidden or 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,30 @@ | ||
# This file configures the static analysis results for your project (errors, | ||
# warnings, and lints). | ||
# | ||
# This enables the 'recommended' set of lints from `package:lints`. | ||
# This set helps identify many issues that may lead to problems when running | ||
# or consuming Dart code, and enforces writing Dart using a single, idiomatic | ||
# style and format. | ||
# | ||
# If you want a smaller set of lints you can change this to specify | ||
# 'package:lints/core.yaml'. These are just the most critical lints | ||
# (the recommended set includes the core lints). | ||
# The core lints are also what is used by pub.dev for scoring packages. | ||
|
||
include: package:lints/recommended.yaml | ||
|
||
# Uncomment the following section to specify additional rules. | ||
|
||
# linter: | ||
# rules: | ||
# - camel_case_types | ||
|
||
# analyzer: | ||
# exclude: | ||
# - path/to/excluded/files/** | ||
|
||
# For more information about the core and recommended set of lints, see | ||
# https://dart.dev/go/core-lints | ||
|
||
# For additional information about configuring this file, see | ||
# https://dart.dev/guides/language/analysis-options |
Binary file not shown.
Binary file not shown.
This file contains hidden or 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,40 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:static_shock/static_shock.dart'; | ||
|
||
Future<void> main(List<String> arguments) async { | ||
var operatingSystem = Platform.operatingSystem; | ||
String tailwindPath = switch (operatingSystem) { | ||
"macos" => "./bin/macos/tailwindcss", | ||
"linux" => "./bin/linux/tailwindcss", | ||
"windows" => "./bin/windows/tailwindcss.exe", | ||
_ => throw UnsupportedError( | ||
"Unsupported operating system: $operatingSystem", | ||
), | ||
}; | ||
|
||
// Configure the static website generator. | ||
final staticShock = StaticShock() | ||
// Here, you can directly hook into the StaticShock pipeline. For example, | ||
// you can copy an "images" directory from the source set to build set: | ||
..pick(ExtensionPicker("html")) | ||
..pick(DirectoryPicker.parse("images")) | ||
// All 3rd party behavior is added through plugins, even the behavior | ||
// shipped with Static Shock. | ||
..plugin(const MarkdownPlugin()) | ||
..plugin(const JinjaPlugin()) | ||
..plugin(const PrettyUrlsPlugin()) | ||
..plugin(const RedirectsPlugin()) | ||
..plugin(const SassPlugin()) | ||
..plugin(DraftingPlugin( | ||
showDrafts: arguments.contains("preview"), | ||
)) | ||
..plugin(TailwindPlugin( | ||
input: "source/styles/tailwind.css", | ||
output: "build/styles/tailwind.css", | ||
tailwindPath: tailwindPath, | ||
)); | ||
|
||
// Generate the static website. | ||
await staticShock.generateSite(); | ||
} |
Binary file not shown.
This file contains hidden or 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,14 @@ | ||
name: shock_template_tailwind | ||
description: | ||
version: 1.0.0 | ||
publish_to: none | ||
|
||
environment: | ||
sdk: ^3.0.0 | ||
|
||
dependencies: | ||
static_shock: any | ||
|
||
dev_dependencies: | ||
lints: ^2.0.0 | ||
test: ^1.21.0 |
Binary file added
BIN
+5.34 KB
...late_sources/template_tailwind/source/images/favicon/android-chrome-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11.7 KB
...late_sources/template_tailwind/source/images/favicon/android-chrome-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.99 KB
template_sources/template_tailwind/source/images/favicon/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions
9
template_sources/template_tailwind/source/images/favicon/browserconfig.xml
This file contains hidden or 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,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<browserconfig> | ||
<msapplication> | ||
<tile> | ||
<square150x150logo src="/images/favicon/mstile-150x150.png"/> | ||
<TileColor>#da532c</TileColor> | ||
</tile> | ||
</msapplication> | ||
</browserconfig> |
Binary file added
BIN
+654 Bytes
template_sources/template_tailwind/source/images/favicon/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+1019 Bytes
template_sources/template_tailwind/source/images/favicon/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file added
BIN
+3.77 KB
template_sources/template_tailwind/source/images/favicon/mstile-150x150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions
18
template_sources/template_tailwind/source/images/favicon/safari-pinned-tab.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still need to work out how to create this
.bundle
. Please advise.