Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
zxypro1 committed Dec 23, 2024
1 parent 5d75055 commit aaf3a95
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/registry/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
14 changes: 13 additions & 1 deletion packages/registry/src/actions/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,16 @@ export const publishSchema = {
}
}
}
}
}

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`;
13 changes: 8 additions & 5 deletions packages/registry/src/actions/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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<string, any>;
if (Edition !== '3.0.0') {
Expand Down Expand Up @@ -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<string, any>;
} 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<string, any>;
const errorMsg = `Publish.yaml illegal.
Application dev: https://manual.serverless-devs.com/dev-guide/application/
Expand Down

0 comments on commit aaf3a95

Please sign in to comment.