diff --git a/packages/registry/package.json b/packages/registry/package.json index 787468b..d9cadd2 100644 --- a/packages/registry/package.json +++ b/packages/registry/package.json @@ -1,6 +1,6 @@ { "name": "@serverless-devs/registry", - "version": "0.0.11-beta.6", + "version": "0.0.11-beta.7", "description": "request for serverless-devs", "main": "lib/index.js", "scripts": { diff --git a/packages/registry/src/actions/constant.ts b/packages/registry/src/actions/constant.ts index 761f4db..92c833f 100644 --- a/packages/registry/src/actions/constant.ts +++ b/packages/registry/src/actions/constant.ts @@ -158,4 +158,16 @@ export const publishSchema = { } } } -} \ No newline at end of file +} + +export const STANDARD_DIR_STRUCTURE = ` +A standard directory structure can be like this: +├── publish.yaml +├── readme.md +├── readme_en.md +├── version.md +├── src/ +│ ├── s.yaml +│ ├── readme.md +│ └── code +└── hook`; diff --git a/packages/registry/src/actions/package.ts b/packages/registry/src/actions/package.ts index d381618..eb29289 100644 --- a/packages/registry/src/actions/package.ts +++ b/packages/registry/src/actions/package.ts @@ -9,7 +9,7 @@ import yaml from 'js-yaml'; import querystring from 'querystring'; import { forEach, get, isEmpty, includes, keys, difference } from 'lodash'; import chalk from 'chalk'; -import { publishSchema } from './constant'; +import { publishSchema, STANDARD_DIR_STRUCTURE } from './constant'; import Ajv from 'ajv'; import { validateTemplateParameters } from '../util/validate'; @@ -58,7 +58,7 @@ interface IRequest { function checkEdition(str: string) { if (!str) { - throw new Error('Need to publish YAML content'); + throw new Error('No Publish.yaml found or Publish.yaml is empty.'); } const { Edition } = yaml.load(str) as Record; if (Edition !== '3.0.0') { @@ -164,14 +164,17 @@ export const list = async (options?: IList) => { // yaml validate before publish const validate = (codeUri: string) => { + // check folders + if (!fs.existsSync(path.join(codeUri, 'src'))) { + throw new Error(`src folder not found in the current working directory.${STANDARD_DIR_STRUCTURE}`); + } const publishYaml = getYamlContentText(path.join(codeUri, 'publish')) as string; - checkEdition(publishYaml); - try { yaml.load(publishYaml) as Record; } catch (error) { - throw new Error(`Publish.yaml format error, please check the yaml.`); + throw new Error(`Publish.yaml format error: \n${error}`); } + checkEdition(publishYaml); const yamlObject = yaml.load(publishYaml) as Record; const errorMsg = `Publish.yaml illegal. Application dev: https://manual.serverless-devs.com/dev-guide/application/