本文整理汇总了TypeScript中fs-extra.pathExistsSync函数的典型用法代码示例。如果您正苦于以下问题:TypeScript pathExistsSync函数的具体用法?TypeScript pathExistsSync怎么用?TypeScript pathExistsSync使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pathExistsSync函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: expect
.then(function () {
const cwd = process.cwd();
expect(cwd).to.not.match(/foo/, 'does not use app name for directory name');
expect(!fs.pathExistsSync(path.join(cwd, 'foo')), 'does not create new directory with app name');
expect(cwd).to.match(/bar/, 'uses given directory name');
expect(fs.pathExistsSync(path.join(cwd, 'bar')), 'creates new directory with specified name');
const pkgJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
expect(pkgJson.name).to.equal('foo', 'uses app name for package name');
});
示例2: expect
.then(() => {
const cwd = process.cwd();
expect(cwd).not.toMatch(/foo/, 'does not use app name for directory name');
expect(fs.pathExistsSync(path.join(cwd, 'foo'))).toBe(false, 'does not create new directory with app name');
expect(cwd).toMatch(/bar/, 'uses given directory name');
expect(fs.pathExistsSync(path.join(cwd, '..', 'bar'))).toBe(true, 'creates new directory with specified name');
const pkgJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
expect(pkgJson.name).toBe('foo', 'uses app name for package name');
})
示例3: transformHeaders
return Object.keys(this.definition!.subscriptions!).map(name => {
const subscription = this.definition!.subscriptions![name]
const url =
typeof subscription.webhook === 'string'
? subscription.webhook
: subscription.webhook.url
const headers =
typeof subscription.webhook === 'string'
? []
: transformHeaders(subscription.webhook.headers)
let query = subscription.query
if (subscription.query.endsWith('.graphql')) {
const queryPath = path.join(this.definitionDir, subscription.query)
if (!fs.pathExistsSync(queryPath)) {
throw new Error(
`Subscription query ${queryPath} provided in subscription "${name}" in prisma.yml does not exist.`,
)
}
query = fs.readFileSync(queryPath, 'utf-8')
}
return {
name,
query,
headers,
url,
}
})
示例4: expect
.then(() => {
const testPath =
path.join(root, 'tmp', 'foo', 'src', 'app', 'mycomp', 'mycomp.component.ts');
expect(pathExistsSync(testPath)).toBe(true);
const contents = readFileSync(testPath, 'utf8');
expect(contents.indexOf('selector: \'test-mycomp\'') === -1).toBe(false);
})
示例5: PluginPath
plugins = plugins.concat((cli.plugins || []).map(name => {
let pluginPath = path.join(this.config.root, 'node_modules', name)
if (!fs.pathExistsSync(pluginPath)) {
pluginPath = path.join(this.config.root, '../../', 'node_modules', name)
}
return new PluginPath({output: this.out, type: 'core', path: pluginPath})
}))
示例6: readDefinition
export async function readDefinition(
filePath: string,
args: Args,
out: IOutput = new Output(),
envVars?: any,
): Promise<{ definition: PrismaDefinition; rawJson: any }> {
if (!fs.pathExistsSync(filePath)) {
throw new Error(`${filePath} could not be found.`)
}
const file = fs.readFileSync(filePath, 'utf-8')
const json = yaml.safeLoad(file) as PrismaDefinition
// we need this copy because populateJson runs inplace
const jsonCopy = { ...json }
const vars = new Variables(filePath, args, out, envVars)
const populatedJson = await vars.populateJson(json)
if (populatedJson.custom) {
delete populatedJson.custom
}
const valid = validate(populatedJson)
// TODO activate as soon as the backend sends valid yaml
if (!valid) {
debugger
let errorMessage =
`Invalid prisma.yml file` + '\n' + printErrors(validate.errors!)
throw new Error(errorMessage)
}
cache[file] = populatedJson
return {
definition: populatedJson,
rawJson: jsonCopy,
}
}
示例7: seed
async seed(
serviceName: string,
stageName: string,
reset: boolean = false,
workspaceSlug?: string,
) {
const seed = this.definition.definition!.seed
if (!seed) {
throw new Error(
`In order to seed, you need to provide a "seed" property in your prisma.yml`,
)
}
if (seed.import && seed.run) {
throw new Error(
`Please provider either seed.import or seed.run but not both at the same time`,
)
}
if (seed.import) {
const source = path.join(this.config.definitionDir, seed.import)
debug(source)
if (!source.endsWith('.zip') && !source.endsWith('.graphql')) {
throw new Error(`Source must end with .zip or .graphql`)
}
if (!fs.pathExistsSync(source)) {
throw new Error(`Path ${source} does not exist`)
}
const token = this.definition.getToken(serviceName, stageName)
if (reset) {
await this.reset(serviceName, stageName)
}
if (source.endsWith('.zip')) {
await this.import(source, serviceName, stageName, token, workspaceSlug)
} else if (source.endsWith('.graphql')) {
await this.executeQuery(
source,
serviceName,
stageName,
token,
workspaceSlug,
)
}
}
if (seed.run) {
if (reset) {
await this.reset(serviceName, stageName)
}
await this.run(seed.run)
}
}
示例8: expect
.then(() => {
expect(fs.pathExistsSync(path.join(testPath, '+my-route/my-route.component.ts')))
.to.equal(true);
expect(fs.pathExistsSync(path.join(testPath, '+my-route/+my-other/my-other.component.ts')))
.to.equal(true);
expect(fs.pathExistsSync(path.join(testPath, '+my-route/+my-other/+my-third/my-third.component.ts')))
.to.equal(true);
const appContent = fs.readFileSync(path.join(testPath, 'foo.component.ts'), 'utf-8');
const myRouteContent = fs.readFileSync(path.join(testPath, '+my-route/my-route.component.ts'), 'utf-8');
const myOtherRouteContent = fs.readFileSync(path.join(testPath, '+my-route/+my-other/my-other.component.ts'), 'utf-8');
const myThirdRouteContent = fs.readFileSync(path.join(testPath, '+my-route/+my-other/+my-third/my-third.component.ts'), 'utf-8');
expect(appContent).to.match(/@Routes\(\[[\s\S]+\/\+my-route\/\.\.\.[\s\S]+\]\)/m);
expect(myRouteContent).to.match(/@Routes\(\[[\s\S]+\/my-other\/\.\.\.[\s\S]+\]\)/m);
expect(myOtherRouteContent).to.match(/@Routes\(\[[\s\S]+\/my-third[^\.][\s\S]+\]\)/m);
expect(myThirdRouteContent).to.not.include('@Routes');
});
示例9: ng
return ng(['generate', 'module', 'm', '--app', 'other']).then(() => {
const expectedModule = path.join(appRoot, 'other', 'src', 'm', 'm.module.ts');
expect(pathExistsSync(expectedModule)).toBe(true);
return ng(['generate', 'component', 'm/c', '--app', 'other', '--module', 'm']).then(() => {
expect(pathExistsSync(path.join(appRoot, 'other', 'src', 'm', 'c', 'c.component.ts'))).toBe(true);
expect(readFileSync(expectedModule, 'utf-8')).toContain(`import { CComponent } from './c/c.component'`);
});
}).then(done, done.fail);
示例10: teardown
export function teardown(path: string) {
process.chdir(root);
if (fs.pathExistsSync(path)) {
return fs.remove(path);
} else {
return Promise.resolve();
}
};