Skip to content

Commit

Permalink
Merge pull request #11 from openactive/feature/restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
petewalker committed Sep 3, 2018
2 parents f2765e6 + 06a0516 commit 5d6297f
Show file tree
Hide file tree
Showing 57 changed files with 74 additions and 81 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -74,3 +74,6 @@ typings/

# OSX
.DS_Store

# Editor
.idea
16 changes: 16 additions & 0 deletions .npmignore
@@ -0,0 +1,16 @@
# Tests
spec
src/**/*[sS]pec.js

# Build scripts
scripts

# CI
.travis.yml
.nvmrc

# Linters
.eslintrc*

# Editor settings
.editorconfig
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -31,7 +31,7 @@
"scripts": {
"build": "node scripts/build.js",
"lint": "eslint \"src/**/*.js\"",
"prepublish": "npm run build",
"prepare": "npm run build",
"pretest": "npm run build && npm run lint",
"test": "npm run test-no-lint",
"test-no-lint": "jasmine"
Expand Down
4 changes: 2 additions & 2 deletions scripts/build.js
Expand Up @@ -11,7 +11,7 @@ const specs = {};
const contexts = {};

for (const version of uniqueVersions) {
const specPath = path.join(__dirname, '..', 'src', version);
const specPath = path.join(__dirname, '..', 'versions', version);
const spec = {
models: {},
rpde: {},
Expand All @@ -34,7 +34,7 @@ for (const version of uniqueVersions) {
}

specs[version] = spec;
contexts[version] = generateContext(version);
contexts[version] = generateContext(version, spec.meta);
}

fs.writeFileSync(
Expand Down
20 changes: 5 additions & 15 deletions scripts/generateContext.js
Expand Up @@ -4,20 +4,10 @@ const path = require('path');
const getMetaData = require('../src/getMetaData');
const derivePrefix = require('../src/helpers/derivePrefix');
const deriveSingularTypes = require('../src/helpers/deriveSingularTypes');
const versions = require('../src/versions');
const deriveVersion = require('../src/helpers/deriveVersion');

const generateContext = (version) => {
let localVersion = version;
if (typeof localVersion === 'undefined') {
localVersion = 'latest';
}
if (typeof versions[localVersion] === 'undefined') {
throw Error('Invalid specification version supplied');
}

const specVersion = versions[localVersion];

const metaData = getMetaData(specVersion);
const generateContext = (version, metaData) => {
const specVersion = deriveVersion(version);

const context = {
concepts: {
Expand All @@ -30,11 +20,11 @@ const generateContext = (version) => {
const newModels = {};
const newFields = {};

const files = fs.readdirSync(path.join(__dirname, '..', 'src', specVersion, 'models'));
const files = fs.readdirSync(path.join(__dirname, '..', 'versions', specVersion, 'models'));

for (const file of files) {
if (file !== 'model_list.json') {
const jsonPath = path.join(__dirname, '..', 'src', specVersion, 'models', file);
const jsonPath = path.join(__dirname, '..', 'versions', specVersion, 'models', file);
const data = fs.readFileSync(jsonPath, 'utf8');
const model = JSON.parse(data);

Expand Down
20 changes: 5 additions & 15 deletions scripts/generateGraph.js
Expand Up @@ -10,20 +10,10 @@ const path = require('path');
const getMetaData = require('../src/getMetaData');
const derivePrefix = require('../src/helpers/derivePrefix');
const deriveSingularTypes = require('../src/helpers/deriveSingularTypes');
const versions = require('../src/versions');
const deriveVersion = require('../src/helpers/deriveVersion');

const getGraph = (version) => {
let localVersion = version;
if (typeof localVersion === 'undefined') {
localVersion = 'latest';
}
if (typeof versions[localVersion] === 'undefined') {
throw Error('Invalid specification version supplied');
}

const specVersion = versions[localVersion];

const metaData = getMetaData(specVersion);
const getGraph = (version, metaData) => {
const specVersion = deriveVersion(version);
const extraData = {
'@id': metaData.namespaces[metaData.openActivePrefix],
'dc:date': (new Date()).toISOString().replace(/T.*$/, ''),
Expand All @@ -33,10 +23,10 @@ const getGraph = (version) => {
rdfs_classes: [],
rdfs_properties: [],
};
const files = fs.readdirSync(path.join(__dirname, '..', 'src', specVersion, 'models'));
const files = fs.readdirSync(path.join(__dirname, '..', 'versions', specVersion, 'models'));
for (const file of files) {
if (file !== 'model_list.json') {
const jsonPath = path.join(__dirname, '..', 'src', specVersion, 'models', file);
const jsonPath = path.join(__dirname, '..', 'versions', specVersion, 'models', file);
const data = fs.readFileSync(jsonPath, 'utf8');
const model = JSON.parse(data);

Expand Down
2 changes: 1 addition & 1 deletion src/dist/contexts.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/dist/specs.js

Large diffs are not rendered by default.

14 changes: 4 additions & 10 deletions src/getContext.js
@@ -1,18 +1,12 @@
const contexts = require('./dist/contexts');
const versions = require('./versions');
const deriveVersion = require('./helpers/deriveVersion');

const getContext = (version) => {
let localVersion = version;
if (typeof localVersion === 'undefined') {
localVersion = 'latest';
}
if (
typeof versions[localVersion] === 'undefined'
|| typeof contexts[versions[localVersion]] === 'undefined'
) {
const specVersion = deriveVersion(version);
if (typeof contexts[specVersion] === 'undefined') {
throw Error('Invalid specification version supplied');
}
return contexts[versions[localVersion]];
return contexts[specVersion];
};

module.exports = getContext;
11 changes: 2 additions & 9 deletions src/getFullyQualifiedProperty.js
@@ -1,17 +1,10 @@
const getContext = require('./getContext');
const versions = require('./versions');
const deriveVersion = require('./helpers/deriveVersion');

const KEYWORD_REGEX = /^@(context|id|value|language|type|container|list|set|reverse|index|base|vocab|graph)$/;

const getFullyQualifiedProperty = (value, version, contexts = []) => {
let localVersion = version;
if (typeof localVersion === 'undefined') {
localVersion = 'latest';
}
if (typeof versions[localVersion] === 'undefined') {
throw Error(`Invalid specification version '${localVersion}' supplied`);
}
const specVersion = versions[localVersion];
const specVersion = deriveVersion(version);

let contextsArg = contexts;
// Sort the contexts
Expand Down
16 changes: 6 additions & 10 deletions src/getMetaData.js
@@ -1,19 +1,15 @@
const specs = require('./dist/specs');
const versions = require('./versions');
const deriveVersion = require('./helpers/deriveVersion');

const getMetaData = (version) => {
let localVersion = version;
if (typeof localVersion === 'undefined') {
localVersion = 'latest';
}
const specVersion = deriveVersion(version);
if (
typeof versions[localVersion] === 'undefined'
|| typeof specs[versions[localVersion]] === 'undefined'
|| typeof specs[versions[localVersion]].meta === 'undefined'
typeof specs[specVersion] === 'undefined'
|| typeof specs[specVersion].meta === 'undefined'
) {
throw Error('Invalid specification version supplied');
throw Error(`Invalid specification version "${specVersion}" supplied`);
}
return specs[versions[localVersion]].meta;
return specs[specVersion].meta;
};

module.exports = getMetaData;
18 changes: 18 additions & 0 deletions src/helpers/deriveVersion.js
@@ -0,0 +1,18 @@
const versions = require('../versions');

const deriveVersion = (version) => {
let localVersion = version;
if (typeof localVersion === 'undefined') {
localVersion = 'latest';
}
if (Object.values(versions).indexOf(localVersion) >= 0) {
return localVersion;
}
if (typeof versions[localVersion] !== 'undefined') {
return versions[localVersion];
}

throw Error(`Invalid specification version "${version}" supplied`);
};

module.exports = deriveVersion;
11 changes: 2 additions & 9 deletions src/helpers/loadModelCheckArgs.js
@@ -1,17 +1,10 @@
const versions = require('../versions');
const deriveVersion = require('./deriveVersion');

const loadModelCheckArgs = (name, version) => {
if (!name.match(/^[A-Za-z]+$/) || name === 'model_list') {
throw Error('Invalid model name supplied');
}
let localVersion = version;
if (typeof localVersion === 'undefined') {
localVersion = 'latest';
}
if (typeof versions[localVersion] === 'undefined') {
throw Error('Invalid specification version supplied');
}
return versions[localVersion];
return deriveVersion(version);
};

module.exports = loadModelCheckArgs;
2 changes: 1 addition & 1 deletion src/loadModel.js
Expand Up @@ -13,7 +13,7 @@ const loadModel = (name, version) => {
|| typeof specs[specVersion][jsonKey] === 'undefined'
|| typeof specs[specVersion][jsonKey][name] === 'undefined'
) {
throw Error('Invalid model name supplied');
throw Error(`Invalid model name "${name}" supplied`);
}
let model = Object.assign({}, specs[specVersion][jsonKey][name]);
if (
Expand Down
4 changes: 2 additions & 2 deletions src/loadModelFromFile.js
Expand Up @@ -7,9 +7,9 @@ const loadModelFromFile = (name, version) => {
const specVersion = loadModelCheckArgs(name, version);
let jsonPath;
if (name === 'FeedItem' || name === 'FeedPage') {
jsonPath = path.join(__dirname, specVersion, 'rpde', `${name}.json`);
jsonPath = path.join(__dirname, '..', 'versions', specVersion, 'rpde', `${name}.json`);
} else {
jsonPath = path.join(__dirname, specVersion, 'models', `${name}.json`);
jsonPath = path.join(__dirname, '..', 'versions', specVersion, 'models', `${name}.json`);
}
const data = fs.readFileSync(jsonPath, 'utf8');
let model = JSON.parse(data);
Expand Down
6 changes: 3 additions & 3 deletions src/models-spec.js
Expand Up @@ -12,8 +12,8 @@ describe('models', () => {
const uniqueVersions = [...new Set(Object.values(versions))];
for (const version of uniqueVersions) {
const files = [
...fs.readdirSync(path.join(__dirname, version, 'models')),
...fs.readdirSync(path.join(__dirname, version, 'rpde')),
...fs.readdirSync(path.join(__dirname, '..', 'versions', version, 'models')),
...fs.readdirSync(path.join(__dirname, '..', 'versions', version, 'rpde')),
];
const metaData = getMetaData(version);
for (const file of files) {
Expand All @@ -22,7 +22,7 @@ describe('models', () => {
if (file.match(/^Feed/)) {
dir = 'rpde';
}
const filePath = path.join(__dirname, version, dir, file);
const filePath = path.join(__dirname, '..', 'versions', version, dir, file);
const data = fs.readFileSync(filePath, 'utf8');
let jsonData;
const readJson = () => { jsonData = JSON.parse(data); };
Expand Down
4 changes: 2 additions & 2 deletions src/versions.js
@@ -1,4 +1,4 @@
module.exports = {
latest: '2.0',
'2.0': '2.0',
latest: '2.x',
'2.0': '2.x',
};
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 5d6297f

Please sign in to comment.