我正在使用 nestjs 使用 graphql。当我创建新模块时,我将手动创建一个文件,如(sample.graphql、sample.interface.ts、sample.module.ts、sample.schema.ts、sample.resolver.ts、sample.service.ts)。那么我如何自动生成这些文件。任何脚本可用于我的问题?
一种可能性是创建一个快捷命令并将其放在您的~/bin/
目录中。该命令将按照您期望的顺序调用所有预期的嵌套生成命令,它可能是这样的:
#! /bin/bash
if [ -z $1 ]
print "A name is necessary for using this command.";
exit 0;
fi
# Nest has the notion of modules, resolvers, services, and interfaces
nest g module $1
nest g resolver $1
nest g service $1
nest g interface $1
# To create the graphql and schema files you'll need to run touch instead
touch src/$1/$1.schema.ts
touch src/$1/$1.graphql
保存脚本后,请确保通过运行sudo chmod 744 ~/bin/myscript
. 顺便说一下,您需要一个超级用户密码。
chmod 允许您授予对脚本文件的访问权限并声明应如何处理访问权限。744 表示您 (7) 拥有完全权限(读取、写入、执行)。前 4 个表示与您具有读取访问权限的同一组的成员,第二个 4 表示使用计算机的任何人都具有读取访问权限。查看 chmod 了解更多信息。
授予执行访问权限后,您应该能够运行myscript
并查看输出
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句