受Moleculer-Cli启发的项目:如何使用EJS代替车把

时间:2019-07-18 14:35:21

标签: javascript ejs scaffolding metalsmith moleculer

我正在尝试创建一些脚手架工具,以便以自己想要的方式轻松启动项目。我喜欢Molecularr的家伙在他们的https://github.com/moleculerjs/moleculer-cli

中的操作方式

他们使用把手,因此现在我可以在模板中执行此操作(例如,用于package.json的模板):

"name" : "{{ projectName }}"

效果很好,但是我更喜欢使用ejs。 不幸的是,我无法弄清楚如何成功更改init.js文件,因此Metalsmith可以修改如下内容:

"name" : "<%= projectName %>}}"

1 个答案:

答案 0 :(得分:0)

Molecularr-cli使用consolidate软件包,该软件包也支持ejs。

因此,您应该在此处更改render变量:class FancyFab extends StatefulWidget { final String tooltip; final IconData icon; String photo; TextEditingController birthController; TextEditingController firstController; TextEditingController lastController; TextEditingController emailController; TextEditingController phoneController; TextEditingController associationController; TextEditingController countryController; final Function saveData; FancyFab({ this.tooltip, this.icon, this.saveData, this.firstController, this.lastController, this.emailController, this.phoneController, this.associationController, this.countryController, this.birthController, this.photo}); @override _FancyFabState createState() => _FancyFabState(); } class _FancyFabState extends State<FancyFab> with SingleTickerProviderStateMixin { bool isOpened = false; AnimationController _animationController; Animation<Color> _buttonColor; Animation<double> _animateIcon; Animation<double> _translateButton; Curve _curve = Curves.easeOut; double _fabHeight = 56.0; @override initState() { _animationController = AnimationController(vsync: this, duration: Duration(milliseconds: 500)) ..addListener(() { setState(() {}); }); _animateIcon = Tween<double>(begin: 0.0, end: 1.0).animate(_animationController); _buttonColor = ColorTween( begin: Colors.pink, end: Colors.red, ).animate(CurvedAnimation( parent: _animationController, curve: Interval( 0.00, 1.00, curve: Curves.linear, ), )); _translateButton = Tween<double>( begin: _fabHeight, end: -14.0, ).animate(CurvedAnimation( parent: _animationController, curve: Interval( 0.0, 0.75, curve: _curve, ), )); super.initState(); } @override dispose() { _animationController.dispose(); super.dispose(); } animate() { if (!isOpened) { _animationController.forward(); } else { _animationController.reverse(); } isOpened = !isOpened; } Widget save() { return Container( child: FloatingActionButton( heroTag: 'saveBtn', onPressed: () { }, tooltip: 'Save', child: Icon(Icons.save), ), ); } Widget image() { return Container( child: FloatingActionButton( heroTag: 'imageBtn', onPressed: () async { File file = await FilePicker.getFile(type: FileType.IMAGE); AlertDialog alert = AlertDialog( title: Text('Uploading photo'), titlePadding: EdgeInsets.all(20.0), contentPadding: EdgeInsets.all(20.0), elevation:10, content: CircularProgressIndicator(), ); final StorageReference storageRef = FirebaseStorage.instance.ref().child(file.path); final String fileName = file.path; final StorageUploadTask uploadTask = storageRef.putFile( File(fileName), ); final StorageTaskSnapshot downloadUrl = (await uploadTask.onComplete); final String url = (await downloadUrl.ref.getDownloadURL()); print('URL Is $url'); setState(() { widget.photo = url; }); }, tooltip: 'Image', child: Icon(Icons.image), ), ); } Widget toggle() { return Container( child: FloatingActionButton( backgroundColor: _buttonColor.value, onPressed: animate, heroTag: 'toggleBtn', tooltip: 'Toggle', child: AnimatedIcon( icon: AnimatedIcons.menu_close, progress: _animateIcon, ), ), ); } @override Widget build(BuildContext context) { return Column( mainAxisAlignment: MainAxisAlignment.end, children: <Widget>[ Transform( transform: Matrix4.translationValues( 0.0, _translateButton.value * 2.0, 0.0, ), child: save(), ), Transform( transform: Matrix4.translationValues( 0.0, _translateButton.value * 1.0, 0.0, ), child: image(), ), toggle(), ], ); } }