|
1 |
| -'use strict' |
| 1 | +const RSVP = require('rsvp') |
| 2 | +const fs = require('graceful-fs') |
| 3 | +const argv = require('minimist')(process.argv.slice(2)) |
2 | 4 |
|
3 |
| -let RSVP = require('rsvp') |
4 |
| -let _ = require('lodash') |
5 |
| -let rm = require('rimraf') |
6 |
| -let PouchDB = require('pouchdb') |
7 |
| -let fs = require('fs') |
8 |
| -let glob = require('glob') |
| 5 | +const markup = require('./lib/markup') |
| 6 | +const readDocs = require('./lib/read-docs') |
| 7 | +const fetchYuiDocs = require('./lib/fetch-yui-docs') |
| 8 | +const createClassesOnDisk = require('./lib/create-classes') |
| 9 | +const transformYuiObject = require('./lib/transform-yui-object') |
| 10 | +const normalizeEmberDependencies = require('./lib/normalize-ember-dependencies') |
| 11 | +const getVersionIndex = require('./lib/get-version-index') |
| 12 | +const saveDoc = require('./lib/save-document') |
| 13 | +const { syncToLocal, syncToS3 } = require('./lib/s3-sync') |
9 | 14 |
|
10 |
| -let fetch = require('./lib/fetch') |
11 |
| -let readDocs = require('./lib/read-docs') |
12 |
| -let addSinceTags = require('./lib/add-since-tags') |
13 |
| -let addInheritedItems = require('./lib/add-inherited-items') |
14 |
| -let transformModules = require('./lib/modules-transform') |
15 |
| -let putClassesInCouch = require('./lib/classes-in-couch') |
16 |
| -let createVersionIndex = require('./lib/create-version-index') |
17 |
| -let normalizeEmberDependencies = require('./lib/normalize-ember-dependencies') |
18 |
| -let normalizeIDs = require('./lib/normalize-ids') |
19 |
| -let markup = require('./lib/markup') |
20 |
| -let batchUpdate = require('./lib/batch-update') |
21 |
| - |
22 |
| -require('marked') |
23 |
| - |
24 |
| -let db = new PouchDB(process.env.COUCH_URL, { |
25 |
| - auth: { |
26 |
| - username: process.env.COUCH_USERNAME, |
27 |
| - password: process.env.COUCH_PASSWORD |
28 |
| - } |
| 15 | +RSVP.on('error', function (reason) { |
| 16 | + console.log(reason) |
| 17 | + process.exit(1) |
29 | 18 | })
|
30 | 19 |
|
31 |
| -if (fs.existsSync('tmp/docs')) { |
32 |
| - rm.sync('tmp/docs') |
33 |
| -} |
34 |
| - |
35 |
| -function transformProjectFiles (projectName) { |
36 |
| - console.log('reading docs for ' + projectName) |
37 |
| - let promise = RSVP.resolve(readDocs(projectName)) |
38 |
| - .then((stuff) => { |
39 |
| - console.log('transforming modules for ' + projectName) |
40 |
| - return transformModules(stuff) |
41 |
| - }).then((stuff) => { |
42 |
| - console.log('adding since tags for ' + projectName) |
43 |
| - return addSinceTags(stuff) |
44 |
| - }).then((stuff) => { |
45 |
| - console.log('adding inherited items for ' + projectName) |
46 |
| - return addInheritedItems(stuff) |
47 |
| - }).then(yuidocs => { |
48 |
| - console.log('normalizing yuidocs for ' + projectName) |
49 |
| - return normalizeIDs(yuidocs, projectName) |
50 |
| - }).then(doc => { |
51 |
| - console.log('creating version index for ' + projectName) |
52 |
| - return createVersionIndex(db, projectName, doc).then(() => doc) |
53 |
| - }).then(doc => { |
54 |
| - console.log('converting markdown to html for ' + projectName) |
55 |
| - return markup(doc) |
56 |
| - }) |
| 20 | +let possibleProjects = ['ember', 'ember-data'] |
| 21 | +let projects = argv.project && possibleProjects.includes(argv.project) ? [argv.project] : possibleProjects |
| 22 | +let specificDocsVersion = argv.version ? argv.version : '' |
57 | 23 |
|
58 |
| - return promise |
59 |
| -} |
| 24 | +let docsVersionMsg = specificDocsVersion !== '' ? '. For version ' + specificDocsVersion : '' |
| 25 | +console.log(`Downloading docs for ${projects.join(' & ')}${docsVersionMsg}`) |
60 | 26 |
|
61 |
| -let projects = ['ember', 'ember-data'] |
62 |
| -let releaseToGenDocFor = process.argv[2] ? process.argv[2] : '' |
| 27 | +syncToLocal() |
| 28 | + .then(() => fetchYuiDocs(projects, specificDocsVersion)) |
| 29 | + .then(() => readDocs(projects, specificDocsVersion)) |
| 30 | + .then(docs => { |
| 31 | + return RSVP.map(projects, projectName => { |
| 32 | + return RSVP.map(docs[projectName], doc => { |
| 33 | + let docVersion = doc.version |
| 34 | + console.log(`Starting to process ${projectName}-${docVersion}`) |
| 35 | + return transformYuiObject([doc], projectName).then(markup).then(doc => { |
| 36 | + let giantDocument = { |
| 37 | + data: doc.data |
| 38 | + } |
| 39 | + console.log('normalizing dependencies') |
| 40 | + return normalizeEmberDependencies(giantDocument) |
| 41 | + }).then(doc => { |
| 42 | + return createClassesOnDisk(doc, projectName, docVersion) |
| 43 | + }).then(doc => { |
| 44 | + console.log(`Finished processing ${projectName}-${docVersion}`) |
| 45 | + return getVersionIndex(doc, projectName) |
| 46 | + }) |
| 47 | + }).then((docs) => { |
| 48 | + let [docToSave, ...remainingDocs] = docs.filter(doc => doc.data.id === projectName) |
63 | 49 |
|
64 |
| -console.log('downloading docs for ' + projects.join(' & ')) |
| 50 | + if (!docToSave) { |
| 51 | + return Promise.resolve() |
| 52 | + } |
65 | 53 |
|
66 |
| -fetch(db, releaseToGenDocFor).then(downloadedFiles => { |
67 |
| - RSVP.map(projects, transformProjectFiles).then(docs => { |
68 |
| - let giantDocument = { |
69 |
| - data: _.flatten(docs.map(doc => doc.data)) |
70 |
| - } |
71 |
| - console.log('normalizing dependencies') |
72 |
| - normalizeEmberDependencies(giantDocument) |
| 54 | + let existingDoc = `tmp/json-docs/${projectName}/projects/${projectName}.json` |
| 55 | + if (fs.existsSync(existingDoc)) { |
| 56 | + existingDoc = JSON.parse(fs.readFileSync(existingDoc)) |
| 57 | + docToSave.data.relationships['project-versions'].data = docToSave.data.relationships['project-versions'].data.concat(existingDoc.data.relationships['project-versions'].data) |
| 58 | + } |
73 | 59 |
|
74 |
| - return putClassesInCouch(giantDocument, db) |
75 |
| - }).then(function () { |
76 |
| - let docs = glob.sync('tmp/docs/**/*.json') |
77 |
| - |
78 |
| - console.log('putting document in CouchDB') |
79 |
| - return batchUpdate(db, docs) |
80 |
| - }).catch(function (err) { |
81 |
| - console.warn('err!', err, err.stack) |
82 |
| - process.exit(1) |
| 60 | + remainingDocs.forEach(d => { |
| 61 | + docToSave.data.relationships['project-versions'].data = docToSave.data.relationships['project-versions'].data.concat(d.data.relationships['project-versions'].data) |
| 62 | + }) |
| 63 | + return saveDoc(docToSave, projectName).then(() => projectName) |
| 64 | + }) |
| 65 | + }) |
83 | 66 | })
|
84 |
| -}) |
| 67 | + .then(syncToS3) |
0 commit comments