Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add semis back #131

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ module.exports = {
},
},
],
}
};
1 change: 0 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"singleQuote": true,
"semi": false,
"printWidth": 100,
"arrowParens": "avoid"
}
90 changes: 45 additions & 45 deletions generate-local.js
Original file line number Diff line number Diff line change
@@ -1,99 +1,99 @@
import chalk from 'chalk'
import commandExists from 'command-exists'
import execa from 'execa'
import { copyFileSync, ensureFileSync, existsSync, removeSync } from 'fs-extra'
import minimist from 'minimist'
import path from 'path'
import chalk from 'chalk';
import commandExists from 'command-exists';
import execa from 'execa';
import { copyFileSync, ensureFileSync, existsSync, removeSync } from 'fs-extra';
import minimist from 'minimist';
import path from 'path';

const docsPath = '../ember-api-docs-data'
const docsPath = '../ember-api-docs-data';

const argv = minimist(process.argv.slice(2))
const argv = minimist(process.argv.slice(2));

const { project, version, install } = argv
const { project, version, install } = argv;

const exit = function exit() {
console.log(...arguments)
process.exit(1)
}
console.log(...arguments);
process.exit(1);
};

async function runCmd(cmd, path, args = []) {
console.log(chalk.underline(`Running '${chalk.green(cmd)}' in ${path}`))
const executedCmd = await execa(cmd, args, { cwd: path, shell: true, stdio: 'inherit' })
console.log(chalk.underline(`Running '${chalk.green(cmd)}' in ${path}`));
const executedCmd = await execa(cmd, args, { cwd: path, shell: true, stdio: 'inherit' });

if (executedCmd.failed) {
console.error(executedCmd.stdout)
console.error(executedCmd.stderr)
process.exit(1)
console.error(executedCmd.stdout);
console.error(executedCmd.stderr);
process.exit(1);
}

console.log(executedCmd.stdout + '\n')
console.log(executedCmd.stdout + '\n');
}

;(async () => {
(async () => {
if (!project || !version) {
exit(
chalk.red('Both project and version args are required.\n'),
chalk.yellow(' e.g., yarn gen --project ember --version 3.10.1'),
)
);
}

if (!['ember', 'ember-data'].includes(project)) {
exit(chalk.red(`Project has to be either 'ember' or 'ember-data'. (was given ${project})\n`))
exit(chalk.red(`Project has to be either 'ember' or 'ember-data'. (was given ${project})\n`));
}

try {
await commandExists('yarn')
await commandExists('yarn');
} catch (e) {
exit(chalk.red('We need yarn installed globally for this script to work'))
exit(chalk.red('We need yarn installed globally for this script to work'));
}

let emberProjectPath = path.join(__dirname, '../', 'ember.js')
let emberDataProjectPath = path.join(__dirname, '../', 'data')
let emberProjectPath = path.join(__dirname, '../', 'ember.js');
let emberDataProjectPath = path.join(__dirname, '../', 'data');

let checkIfProjectDirExists = dirPath => {
if (!existsSync(dirPath)) {
exit(chalk.yellow(`Please checkout the ${project} project at ${dirPath}`))
exit(chalk.yellow(`Please checkout the ${project} project at ${dirPath}`));
}
}
};

let buildDocs = async projDirPath => {
checkIfProjectDirExists(projDirPath)
checkIfProjectDirExists(projDirPath);

if (project === 'ember') {
await runCmd('volta', projDirPath, ['run', 'yarn'])
await runCmd('volta', projDirPath, ['run', 'yarn']);
} else {
await runCmd('corepack', projDirPath, ['pnpm', 'install'])
await runCmd('corepack', projDirPath, ['pnpm', 'install']);
}

if (install) {
await runCmd(project === 'ember' ? 'yarn' : 'pnpm install', projDirPath)
console.log('\n\n')
await runCmd(project === 'ember' ? 'yarn' : 'pnpm install', projDirPath);
console.log('\n\n');
}

await runCmd(
project === 'ember' ? 'volta run yarn docs' : 'corepack pnpm run build:docs',
projDirPath,
)
);

let destination = `${docsPath}/s3-docs/v${version}/${project}-docs.json`
ensureFileSync(destination)
const projYuiDocFile = destination
removeSync(projYuiDocFile)
removeSync(`${docsPath}/json-docs/${project}/${version}`)
let destination = `${docsPath}/s3-docs/v${version}/${project}-docs.json`;
ensureFileSync(destination);
const projYuiDocFile = destination;
removeSync(projYuiDocFile);
removeSync(`${docsPath}/json-docs/${project}/${version}`);

const yuiDocFile = path.join(
projDirPath,
project === 'ember' ? 'docs/data.json' : 'packages/-ember-data/dist/docs/data.json',
)
copyFileSync(yuiDocFile, projYuiDocFile)
}
);
copyFileSync(yuiDocFile, projYuiDocFile);
};

let dirMap = {
ember: emberProjectPath,
'ember-data': emberDataProjectPath,
}
};

await buildDocs(dirMap[project])
await buildDocs(dirMap[project]);

await execa('volta', [
'run',
Expand All @@ -104,5 +104,5 @@ async function runCmd(cmd, path, args = []) {
'--version',
version,
'--no-sync',
]).stdout.pipe(process.stdout)
})()
]).stdout.pipe(process.stdout);
})();
16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// eslint-disable-next-line
require = require('esm')(module /*, options*/)

const argv = require('minimist')(process.argv.slice(2))
const argv = require('minimist')(process.argv.slice(2));

let possibleProjects = ['ember', 'ember-data']
let possibleProjects = ['ember', 'ember-data'];
let projects =
argv.project && possibleProjects.includes(argv.project) ? [argv.project] : possibleProjects
let specificDocsVersion = argv.version ? argv.version : ''
argv.project && possibleProjects.includes(argv.project) ? [argv.project] : possibleProjects;
let specificDocsVersion = argv.version ? argv.version : '';

let runClean = !!argv.clean
let noSync = !argv.sync
let runClean = !!argv.clean;
let noSync = !argv.sync;

const { apiDocsProcessor } = require('./main.js')
apiDocsProcessor(projects, specificDocsVersion, runClean, noSync)
const { apiDocsProcessor } = require('./main.js');
apiDocsProcessor(projects, specificDocsVersion, runClean, noSync);
52 changes: 26 additions & 26 deletions lib/add-inherited-items.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
import _ from 'lodash'
import _ from 'lodash';

export default function addInheritedItems(docSets) {
docSets.forEach(versionData => {
let data = versionData.data
let classes = _.values(data.classes).filter(klass => klass && klass.name)
classes = classes.filter(removeLongDocsBecauseEmber1HasWeirdDocs)
let classItems = data.classitems.filter(({ itemtype }) => itemtype)
let data = versionData.data;
let classes = _.values(data.classes).filter(klass => klass && klass.name);
classes = classes.filter(removeLongDocsBecauseEmber1HasWeirdDocs);
let classItems = data.classitems.filter(({ itemtype }) => itemtype);

classes.forEach(klass => {
let parents = getParents(klass, classes)
let parents = getParents(klass, classes);

for (let i = 0; i < parents.length; ++i) {
parents = parents.concat(getParents(parents[i], classes))
parents = parents.concat(getParents(parents[i], classes));
}
parents.forEach(parent => {
if (!parent) return
let parentItems = classItems.filter(item => item.class === parent.name)
if (!parent) return;
let parentItems = classItems.filter(item => item.class === parent.name);
parentItems = parentItems.map(item => {
item = _.clone(item)
item.inherited = true
item.inheritedFrom = item.class
item.class = klass.name
return item
})
data.classitems = data.classitems.concat(parentItems)
})
})
})
item = _.clone(item);
item.inherited = true;
item.inheritedFrom = item.class;
item.class = klass.name;
return item;
});
data.classitems = data.classitems.concat(parentItems);
});
});
});

return Promise.resolve(docSets)
return Promise.resolve(docSets);
}

function getParents(klass, classes) {
let parents = []
let parents = [];
if (klass.extends) {
parents = parents.concat([klass.extends])
parents = parents.concat([klass.extends]);
}
if (klass.uses && klass.uses.length) {
parents = parents.concat(klass.uses.reverse())
parents = parents.concat(klass.uses.reverse());
}
return parents
.map(parent => _.find(classes, ({ name }) => name === parent))
.filter(parent => parent)
.filter(parent => parent);
}

function removeLongDocsBecauseEmber1HasWeirdDocs({ name }) {
let str = 'A Suite can'
return !name.includes(str)
let str = 'A Suite can';
return !name.includes(str);
}
60 changes: 30 additions & 30 deletions lib/add-since-tags.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,67 @@
import _ from 'lodash'
import _ from 'lodash';

export default function addSinceTags(docSets) {
let versionIndex = Object.create(null)
let versionIndex = Object.create(null);

docSets.forEach(versionData => {
let data = versionData.data
let version = (versionData.version = versionData.version.replace('v', ''))
let classItems = data.classitems.filter(({ itemtype }) => itemtype)
let data = versionData.data;
let version = (versionData.version = versionData.version.replace('v', ''));
let classItems = data.classitems.filter(({ itemtype }) => itemtype);

classItems.forEach(classItem => {
let classItemName = `${classItem.class}#${classItem.name}`
classItem.version = version
createMethodEntry(versionIndex, classItemName, classItem.itemtype, version)
})
let classItemName = `${classItem.class}#${classItem.name}`;
classItem.version = version;
createMethodEntry(versionIndex, classItemName, classItem.itemtype, version);
});

let classes = _.values(data.classes)
let classes = _.values(data.classes);

classes.forEach(klass => {
klass.version = version
createMethodEntry(versionIndex, klass.name, 'class', version)
})
})
klass.version = version;
createMethodEntry(versionIndex, klass.name, 'class', version);
});
});

sortVersionIndex(versionIndex)
sortVersionIndex(versionIndex);

let classItems = classItemsWithItemType(docSets)
let classItems = classItemsWithItemType(docSets);

classItems.forEach(classItem => {
let classItemName = `${classItem.class}#${classItem.name}`
let version = versionIndex[classItem.itemtype][classItemName][0]
let classItemName = `${classItem.class}#${classItem.name}`;
let version = versionIndex[classItem.itemtype][classItemName][0];

classItem.since = version
})
classItem.since = version;
});

let classes = _.chain(docSets)
.map('data')
.map('classes')
.flatten()
.map(klassSet => _.values(klassSet))
.flatten()
.value()
.value();

classes.forEach(klass => (klass.since = versionIndex['class'][klass.name][0]))
classes.forEach(klass => (klass.since = versionIndex['class'][klass.name][0]));

return Promise.resolve(docSets)
return Promise.resolve(docSets);
}

function sortVersionIndex(versionIndex) {
let keys = Object.keys(versionIndex)
let keys = Object.keys(versionIndex);

keys.forEach(key =>
Object.keys(versionIndex[key]).forEach(item => versionIndex[key][item].sort()),
)
);
}

const createMethodEntry = (versionIndex, method, itemType, version) => {
versionIndex[itemType] = versionIndex[itemType] || Object.create(null)
versionIndex[itemType][method] = versionIndex[itemType][method] || []
versionIndex[itemType][method].push(version)
}
versionIndex[itemType] = versionIndex[itemType] || Object.create(null);
versionIndex[itemType][method] = versionIndex[itemType][method] || [];
versionIndex[itemType][method].push(version);
};

const classItemsWithItemType = versions =>
versions.reduce(
(memo, { data }) => memo.concat(data.classitems.filter(({ itemtype }) => itemtype)),
[],
)
);
18 changes: 9 additions & 9 deletions lib/create-classes.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import saveDoc from './save-document.js'
import saveDoc from './save-document.js';

export default async function (document, projectName, projectVersion) {
let things = document.data
let things = document.data;

for (const klass of things) {
if (!klass.id) {
console.log(klass)
console.log(new Error('WHAT').stack)
process.exit(1)
console.log(klass);
console.log(new Error('WHAT').stack);
process.exit(1);
}
const doc = {
data: klass,
}
};

console.log(`Creating ${klass.id} in ${projectName}-${projectVersion}`)
await saveDoc(doc, projectName, projectVersion)
console.log(`Creating ${klass.id} in ${projectName}-${projectVersion}`);
await saveDoc(doc, projectName, projectVersion);
}

return document
return document;
}
Loading