Updated NNBD

This commit is contained in:
thomashii 2021-07-17 13:10:35 +08:00
parent 6254a8a471
commit 7e4aa24ce0
19 changed files with 176 additions and 152 deletions

View file

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/.pub" />
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/sample_project/.pub" />
<excludeFolder url="file://$MODULE_DIR$/sample_project/build" />
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
</component>
</module>

View file

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/angel_cli.iml" filepath="$PROJECT_DIR$/.idea/angel_cli.iml" />
</modules>
</component>
</project>

View file

@ -1,8 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Controller" type="DartCommandLineRunConfigurationType" factoryName="Dart Command Line Application" singleton="true">
<option name="arguments" value="controller" />
<option name="filePath" value="$PROJECT_DIR$/bin/angel.dart" />
<option name="workingDirectory" value="$PROJECT_DIR$/sample_project" />
<method />
</configuration>
</component>

View file

@ -1,7 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Doctor" type="DartCommandLineRunConfigurationType" factoryName="Dart Command Line Application" singleton="true">
<option name="arguments" value="doctor" />
<option name="filePath" value="$PROJECT_DIR$/bin/angel.dart" />
<method />
</configuration>
</component>

View file

@ -1,8 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Init" type="DartCommandLineRunConfigurationType" factoryName="Dart Command Line Application" singleton="true">
<option name="arguments" value="init sample_project" />
<option name="filePath" value="$PROJECT_DIR$/bin/angel.dart" />
<option name="workingDirectory" value="$PROJECT_DIR$" />
<method />
</configuration>
</component>

View file

@ -1,7 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Show Help" type="DartCommandLineRunConfigurationType" factoryName="Dart Command Line Application" singleton="true">
<option name="arguments" value="--help" />
<option name="filePath" value="$PROJECT_DIR$/bin/angel.dart" />
<method />
</configuration>
</component>

View file

@ -1,8 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Update" type="DartCommandLineRunConfigurationType" factoryName="Dart Command Line Application" singleton="true">
<option name="arguments" value="update" />
<option name="filePath" value="$PROJECT_DIR$/bin/angel.dart" />
<option name="workingDirectory" value="$PROJECT_DIR$" />
<method />
</configuration>
</component>

View file

@ -1,7 +0,0 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Version" type="DartCommandLineRunConfigurationType" factoryName="Dart Command Line Application" singleton="true">
<option name="arguments" value="version" />
<option name="filePath" value="$PROJECT_DIR$/bin/angel.dart" />
<method />
</configuration>
</component>

View file

@ -1,15 +1,27 @@
# 3.0.0-beta.2
# Change Log
## 3.0.0
* Fixed NNBD issues
* Updated to use `angel3` packages
## 3.0.0-beta.2
* Updated README
# 3.0.0-beta.1
## 3.0.0-beta.1
* Migrated to work with Dart SDK 2.12.x Non NNBD
* Replaced `mustache4dart2` with `mustache_template`
* Replaced `inflection2` with `inflection3`
# 2.1.7+1
## 2.1.7+1
* Fix a bug where new directories were not being created in
`init`.
# 2.1.7
## 2.1.7
* Fix a bug where `ArgResults.arguments` was used in `init` instead of the
intended `ArgResults.rest`.
* Stop including `package:angel_model` imports in `make model`.
@ -17,36 +29,45 @@ intended `ArgResults.rest`.
* Fix `make model` to generate ORM + migration by default.
* Fix `MakerDependency` logic to print missing dependencies.
# 2.1.6
## 2.1.6
* Fix a bug where models always defaulted to ORM.
* Add GraphQL boilerplate.
* Automatically restore terminal colors on shutdown.
# 2.1.5+1
## 2.1.5+1
* Update to `inflection2`.
# 2.1.5
## 2.1.5
* Add `shared` boilerplates.
* Remove uncecessary `angel_model` imports.
# 2.1.4+1
## 2.1.4+1
* Patch `part of 'path'` renames.
# 2.1.4
## 2.1.4
* The `migration` argument to `model` just emits an annotation now.
* Add the ORM boilerplate.
# 2.1.3
## 2.1.3
* Fix generation of ORM models.
* A `--project-name` to `init` command.
# 2.1.2
## 2.1.2
* No migrations-by-default.
# 2.1.1
## 2.1.1
* Edit the way `rename` runs, leaving no corner unturned.
# 2.1.0
## 2.1.0
* Deprecate `angel install`.
* Rename projects using `snake_case`.
* `init` now fetches from `master`.
@ -55,34 +76,43 @@ intended `ArgResults.rest`.
* Replace `{{oldName}}` in the `rename` command.
* `pub get` now runs with `inheritStdio`.
# 2.0.1
## 2.0.1
* `deploy systemd` now has an `--install` option, where you can immediately
spawn the service.
# 2.0.0
## 2.0.0
* `init` can now produce either 1.x or 2.x projects.
* Fixed deps for compatibility with Dart2 stable.
# 1.3.4
## 1.3.4
* Fix another typo.
# 1.3.3
## 1.3.3
* Fix a small typo in the model generator.
# 1.3.2
## 1.3.2
* Restore `part` directives in generated models.
# 1.3.1
## 1.3.1
* Add `deploy nginx` and `deploy systemd`.
# 1.3.0
## 1.3.0
* Focus on Dart2 from here on out.
* Update `code_builder`.
* More changes...
# 1.1.5
## 1.1.5
Deprecated several commands, in favor of the `make`
command:
* `controller`
* `plugin`
* `service`

View file

@ -1,6 +1,6 @@
MIT License
MIT License (MIT)
Copyright (c) [year] [fullname]
Copyright (c) 2021 dukefirehawk.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View file

@ -8,25 +8,31 @@
[![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel3-cli/blob/master/LICENSE)
Command-line tools for the Angel3 framework that provides the following functionalities:
Command-line tools for the Angel3 framework.
Includes functionality such as:
* Project scaffolding
* Generating service models, plugins, tests and more
* Renaming projects
* Much more...
* To install:
## Installation
Release version:
```bash
$ pub global activate angel3_cli
dart pub global activate angel3_cli
```
* Install development version
`dart pub global activate --source git https://github.com/dukefirehawk/angel3-cli`
And then, for information on each command:
Development version:
```bash
$ angel3 help
dart pub global activate --source git https://github.com/dukefirehawk/angel3-cli
```
## Help
For information on the available options:
```bash
angel3 help
```

View file

@ -1,8 +1,7 @@
# Todo
* Migrate inflection2, mustache4dart2 and prompts packages to NNBD
* `service`
* Add tests
* Add tests
* `migration`
* `deploy`
* Call these from Grinder script :)
* Call these from Grinder script

View file

@ -12,11 +12,11 @@ final String DOCTOR = 'doctor';
void main(List<String> args) async {
var runner = CommandRunner(
'angel',
asciiArt.trim() +
asciiArt +
'\n\n' +
'Command-line tools for the Angel framework.' +
'Command-line tools for the Angel3 framework.' +
'\n\n' +
'https://angel-dart.github.io');
'https://angel3-framework.web.app');
runner.argParser
.addFlag('verbose', help: 'Print verbose output.', negatable: false);
@ -46,7 +46,34 @@ void main(List<String> args) async {
});
}
const String asciiArt2 = '''
___ _ ________________ _____
/ | / | / / ____/ ____/ / |__ /
/ /| | / |/ / / __/ __/ / / /_ <
/ ___ |/ /| / /_/ / /___/ /______/ /
/_/ |_/_/ |_/\\____/_____/_____/____/
''';
const String asciiArt = '''
_ _ _ ____ _____ _ _____
/ \\ | \\ | |/ ___| ____| | |___ /
/ _ \\ | \\| | | _| _| | | |_ \\
/ ___ \\| |\\ | |_| | |___| |___ ___) |
/_/ \\_\\_| \\_|\\____|_____|_____|____/
''';
const String asciiArt3 = '''
\ \ | ___| ____| | ___ /
_ \ \ | | __| | _ \
___ \ |\ | | | | | ) |
_/ _\ _| \_| \____| _____| _____| ____/
''';
const String asciiArtOld = '''
____________ ________________________
___ |__ | / /_ ____/__ ____/__ /
__ /| |_ |/ /_ / __ __ __/ __ /

View file

@ -34,6 +34,11 @@ class InitCommand extends Command {
@override
void run() async {
if (argResults == null) {
print('Invalid arguements');
return;
}
var projectDir =
Directory(argResults!.rest.isEmpty ? '.' : argResults!.rest[0]);
print('Creating new Angel3 project in ${projectDir.absolute.path}...');
@ -50,7 +55,7 @@ class InitCommand extends Command {
File.fromUri(projectDir.uri.resolve('config/production.yaml')), secret);
var name = argResults!.wasParsed('project-name')
? (argResults!['project-name'] as String?)!
? (argResults!['project-name'] as String)
: p.basenameWithoutExtension(
projectDir.absolute.uri.normalizePath().toFilePath());
@ -58,6 +63,7 @@ class InitCommand extends Command {
print('Renaming project from "angel" to "$name"...');
await renamePubspec(projectDir, 'angel', name);
await renameDartFiles(projectDir, 'angel', name);
// Renaming executable files
if (argResults!['pub-get'] != false && argResults!['offline'] == false) {
print('Now running pub get...');
@ -77,8 +83,8 @@ class InitCommand extends Command {
..writeln(' in your terminal.')
..writeln()
..writeln('Find more documentation about Angel3:')
..writeln(' * https://angel3-framework.web.app')
..writeln(' * https://angel3-docs.dukefirehaw.com')
..writeln(' * https://github.com/dukefirehawk/angel/wiki')
..writeln(
' * https://www.youtube.com/playlist?list=PLl3P3tmiT-frEV50VdH_cIrA2YqIyHkkY')
..writeln(' * https://medium.com/the-angel-framework')
@ -144,17 +150,23 @@ class InitCommand extends Command {
// var boilerplate = basicBoilerplate;
print('Choose a project type before continuing:');
var boilerplate = prompts.choose(
'Choose a project type before continuing', boilerplates)!;
'Choose a project type before continuing', boilerplates) ??
basicBoilerplate;
// Ultimately, we want a clone of every boilerplate locally on the system.
var boilerplateRootDir = Directory(p.join(angelDir.path, 'boilerplates'));
var boilerplateBasename = p.basenameWithoutExtension(boilerplate.url!);
if (boilerplate.ref != null) boilerplateBasename += '.${boilerplate.ref}';
var boilerplateBasename = p.basenameWithoutExtension(boilerplate.url);
if (boilerplate.ref != '') {
boilerplateBasename += '.${boilerplate.ref}';
}
boilerplateDir =
Directory(p.join(boilerplateRootDir.path, boilerplateBasename));
await boilerplateRootDir.create(recursive: true);
var branch = boilerplate.ref ?? 'master';
var branch = boilerplate.ref;
if (branch == '') {
branch = 'master';
}
// If there is no clone existing, clone it.
if (!await boilerplateDir.exists()) {
@ -167,7 +179,7 @@ class InitCommand extends Command {
'Cloning "${boilerplate.name}" boilerplate from "${boilerplate.url}"...');
Process git;
if (boilerplate.ref == null) {
if (boilerplate.ref == '') {
print(darkGray.wrap(
'\$ git clone --depth 1 ${boilerplate.url} ${boilerplateDir.absolute.path}'));
git = await Process.start(
@ -176,7 +188,7 @@ class InitCommand extends Command {
'clone',
'--depth',
'1',
boilerplate.url!,
boilerplate.url,
boilerplateDir.absolute.path
],
mode: ProcessStartMode.inheritStdio,
@ -193,8 +205,8 @@ class InitCommand extends Command {
'1',
'--single-branch',
'-b',
boilerplate.ref!,
boilerplate.url!,
boilerplate.ref,
boilerplate.url,
boilerplateDir.absolute.path
],
mode: ProcessStartMode.inheritStdio,
@ -231,7 +243,9 @@ class InitCommand extends Command {
var gitDir = Directory.fromUri(projectDir.uri.resolve('.git'));
if (await gitDir.exists()) await gitDir.delete(recursive: true);
} catch (e) {
await boilerplateDir.delete(recursive: true).catchError((_) => null);
await boilerplateDir.delete(recursive: true).catchError((e) {
print('Got error: ${e.error}');
});
if (e is! String) {
print(red.wrap('$ballot Could not initialize Angel3 project.'));
@ -271,21 +285,21 @@ const RepoLocation = 'https://github.com/dukefirehawk';
const BoilerplateInfo graphQLBoilerplate = BoilerplateInfo(
'GraphQL',
'A starting point for GraphQL API servers.',
'A starter application with GraphQL support.',
'$RepoLocation/boilerplates.git',
ref: 'angel3-graphql',
);
const BoilerplateInfo ormBoilerplate = BoilerplateInfo(
'ORM',
"A starting point for applications that use Angel3's ORM.",
'A starter application with ORM support.',
'$RepoLocation/boilerplates.git',
ref: 'angel3-orm',
);
const BoilerplateInfo basicBoilerplate = BoilerplateInfo(
'Basic',
'Minimal starting point for Angel3 - A simple server with only a few additional packages.',
'A basic starter application with minimal packages.',
'$RepoLocation/boilerplates.git',
ref: 'angel3-basic');
@ -310,11 +324,12 @@ const List<BoilerplateInfo> boilerplates = [
];
class BoilerplateInfo {
final String? name, description, url, ref;
final String name, description, url;
final String ref;
final bool needsPrebuild;
const BoilerplateInfo(this.name, this.description, this.url,
{this.ref, this.needsPrebuild = false});
{this.ref = '', this.needsPrebuild = false});
@override
String toString() => '$name ($description)';

View file

@ -6,7 +6,7 @@ class MakerDependency implements Comparable<MakerDependency> {
final String name, version;
final bool dev;
const MakerDependency(this.name, this.version, {this.dev: false});
const MakerDependency(this.name, this.version, {this.dev = false});
@override
int compareTo(MakerDependency other) => name.compareTo(other.name);

View file

@ -36,13 +36,13 @@ class MigrationCommand extends Command {
}
var deps = [const MakerDependency('angel_migration', '^2.0.0')];
var rc = new ReCase(name!);
var rc = ReCase(name!);
var migrationLib = new Library((migrationLib) {
var migrationLib = Library((migrationLib) {
migrationLib
..directives.add(new Directive.import(
..directives.add(Directive.import(
'package:angel_migration.dart/angel_migration.dart'))
..body.add(new Class((migrationClazz) {
..body.add(Class((migrationClazz) {
migrationClazz
..name = '${rc.pascalCase}Migration'
..extend = refer('Migration');
@ -50,21 +50,21 @@ class MigrationCommand extends Command {
var tableName = pluralize(rc.snakeCase);
// up()
migrationClazz.methods.add(new Method((up) {
migrationClazz.methods.add(Method((up) {
up
..name = 'up'
..returns = refer('void')
..annotations.add(refer('override'))
..requiredParameters.add(new Parameter((b) => b
..requiredParameters.add(Parameter((b) => b
..name = 'schema'
..type = refer('Schema')))
..body = new Block((block) {
..body = Block((block) {
// (table) { ... }
var callback = new Method((callback) {
var callback = Method((callback) {
callback
..requiredParameters
.add(new Parameter((b) => b..name = 'table'))
..body = new Block((block) {
.add(Parameter((b) => b..name = 'table'))
..body = Block((block) {
var table = refer('table');
block.addExpression(
@ -95,15 +95,15 @@ class MigrationCommand extends Command {
}));
// down()
migrationClazz.methods.add(new Method((down) {
migrationClazz.methods.add(Method((down) {
down
..name = 'down'
..returns = refer('void')
..annotations.add(refer('override'))
..requiredParameters.add(new Parameter((b) => b
..requiredParameters.add(Parameter((b) => b
..name = 'schema'
..type = refer('Schema')))
..body = new Block((block) {
..body = Block((block) {
block.addExpression(
refer('schema').property('drop').call([
literal(tableName),
@ -115,15 +115,16 @@ class MigrationCommand extends Command {
});
// Save migration file
var migrationDir = new Directory.fromUri(
var migrationDir = Directory.fromUri(
Directory.current.uri.resolve(argResults!['output-dir'] as String));
var migrationFile =
new File.fromUri(migrationDir.uri.resolve('${rc.snakeCase}.dart'));
if (!await migrationFile.exists())
File.fromUri(migrationDir.uri.resolve('${rc.snakeCase}.dart'));
if (!await migrationFile.exists()) {
await migrationFile.create(recursive: true);
}
await migrationFile.writeAsString(new DartFormatter()
.format(migrationLib.accept(new DartEmitter()).toString()));
await migrationFile.writeAsString(
DartFormatter().format(migrationLib.accept(DartEmitter()).toString()));
print(green.wrap(
'$checkmark Created migration file "${migrationFile.absolute.path}".'));

View file

@ -31,8 +31,8 @@ class ServiceCommand extends Command {
}
@override
run() async {
var pubspec = await loadPubspec();
void run() async {
await loadPubspec();
String? name;
if (argResults!.wasParsed('name')) name = argResults!['name'] as String?;
@ -40,7 +40,7 @@ class ServiceCommand extends Command {
name = prompts.get('Name of service');
}
List<MakerDependency> deps = [
var deps = <MakerDependency>[
const MakerDependency('angel_framework', '^2.0.0')
];
@ -122,7 +122,7 @@ class ServiceCommand extends Command {
final outputDir = Directory.fromUri(
Directory.current.uri.resolve(argResults!['output-dir'] as String));
final serviceFile =
File.fromUri(outputDir.uri.resolve("${rc.snakeCase}.dart"));
File.fromUri(outputDir.uri.resolve('${rc.snakeCase}.dart'));
if (!await serviceFile.exists()) await serviceFile.create(recursive: true);
await serviceFile.writeAsString(
DartFormatter().format(serviceLib.accept(DartEmitter()).toString()));

View file

@ -88,6 +88,7 @@ Future renameDartFiles(Directory dir, String oldName, String newName) async {
if (!await dir.exists()) return;
// Try to replace MongoDB URL
// Replace name in config directory
var configGlob = Glob('config/**/*.yaml');
try {
@ -104,6 +105,23 @@ Future renameDartFiles(Directory dir, String oldName, String newName) async {
}
} catch (_) {}
// Replace name in bin directory
var binGlob = Glob('bin/**/*.dart');
try {
await for (var dartFile in binGlob.list(root: dir.absolute.path)) {
if (dartFile is File) {
print(
'Replacing occurrences of "$oldName" with "$newName" in file "${dartFile.absolute.path}"...');
if (dartFile is File) {
var contents = (dartFile as File).readAsStringSync();
contents = contents.replaceAll(oldName, newName);
(dartFile as File).writeAsStringSync(contents);
}
}
}
} catch (_) {}
var entry = File.fromUri(dir.uri.resolve('lib/$oldName.dart'));
if (await entry.exists()) {

View file

@ -1,7 +1,8 @@
name: angel3_cli
version: 3.0.0-beta.2
description: Command-line tools for the Angel framework, including scaffolding.
homepage: https://github.com/dukefirehawk/angel3-cli
description: Command line tools for the Angel3 framework, including scaffolding.
homepage: https://angel3-framework.web.app/
repository: https://github.com/dukefirehawk/angel3-cli
environment:
sdk: '>=2.12.0 <3.0.0'
dependencies:
@ -13,7 +14,6 @@ dependencies:
http: ^0.13.3
io: ^1.0.0
inflection3: ^0.5.3+2
#mustache4dart2: ^0.1.0
mustache_template: ^2.0.0
path: ^1.8.0
prompts: ^2.0.0