diff --git a/aio/package.json b/aio/package.json index 5a5d82c823..9daca13364 100644 --- a/aio/package.json +++ b/aio/package.json @@ -83,6 +83,7 @@ "hast-util-to-string": "^1.0.0", "html": "^1.0.0", "http-server": "^0.9.0", + "ignore": "^3.3.3", "image-size": "^0.5.1", "jasmine-core": "~2.5.2", "jasmine-spec-reporter": "~3.2.0", diff --git a/aio/tools/transforms/angular-content-package/index.js b/aio/tools/transforms/angular-content-package/index.js index e835080c4d..f3e8384a0c 100644 --- a/aio/tools/transforms/angular-content-package/index.js +++ b/aio/tools/transforms/angular-content-package/index.js @@ -6,17 +6,29 @@ * found in the LICENSE file at https://angular.io/license */ const Package = require('dgeni').Package; - +const globby = require('globby'); +const ignore = require('ignore'); +const fs = require('fs'); +const path = require('canonical-path'); const basePackage = require('../angular-base-package'); const contentPackage = require('../content-package'); -const { CONTENTS_PATH } = require('../config'); +const { CONTENTS_PATH, GUIDE_EXAMPLES_PATH } = require('../config'); module.exports = new Package('angular-content', [basePackage, contentPackage]) // Where do we get the source files? .config(function(readFilesProcessor, collectExamples) { + const gitignoreFile = fs.readFileSync(path.resolve(GUIDE_EXAMPLES_PATH, '.gitignore'), 'utf8'); + const gitignore = ignore().add(gitignoreFile); + + const examplePaths = globby.sync('**/*', { cwd: GUIDE_EXAMPLES_PATH, mark: true, dot: true }) + .filter(filePath => filePath !== '.gitignore') // we are not interested in the .gitignore file itself + .filter(filePath => !/\/$/.test(filePath)); // this filter removes the folders, leaving only files + const filteredExamplePaths = gitignore.filter(examplePaths) // filter out files that match the .gitignore rules + .map(filePath => path.resolve(GUIDE_EXAMPLES_PATH, filePath)); // we need the full paths for the filereader + readFilesProcessor.sourceFiles = readFilesProcessor.sourceFiles.concat([ { basePath: CONTENTS_PATH, @@ -36,26 +48,7 @@ module.exports = new Package('angular-content', [basePackage, contentPackage]) }, { basePath: CONTENTS_PATH, - include: CONTENTS_PATH + '/examples/**/*', - exclude: [ - '**/*plnkr.no-link.html', - '**/node_modules/**', - // boilerplate files - '**/*/src/systemjs-angular-loader.js', - '**/*/src/systemjs.config.js', - '**/*/src/tsconfig.json', - '**/*/bs-config.e2e.json', - '**/*/bs-config.json', - '**/*/package.json', - '**/*/tslint.json', - // example files - '**/_test-output', - '**/protractor-helpers.js', - '**/e2e-spec.js', - '**/ts/**/*.js', - '**/js-es6*/**/*.js', - '**/ts-snippets/**/*.js', - ], + include: filteredExamplePaths, fileReader: 'exampleFileReader' }, { diff --git a/aio/tools/transforms/config.js b/aio/tools/transforms/config.js index 8f6008a208..59eb3cae47 100644 --- a/aio/tools/transforms/config.js +++ b/aio/tools/transforms/config.js @@ -6,6 +6,7 @@ const AIO_PATH = resolve(PROJECT_ROOT, 'aio'); const TEMPLATES_PATH = resolve(AIO_PATH, 'tools/transforms/templates'); const API_TEMPLATES_PATH = resolve(TEMPLATES_PATH, 'api'); const CONTENTS_PATH = resolve(AIO_PATH, 'content'); +const GUIDE_EXAMPLES_PATH = resolve(CONTENTS_PATH, 'examples'); const SRC_PATH = resolve(AIO_PATH, 'src'); const OUTPUT_PATH = resolve(SRC_PATH, 'generated'); const DOCS_OUTPUT_PATH = resolve(OUTPUT_PATH, 'docs'); @@ -18,5 +19,5 @@ function requireFolder(dirname, folderPath) { .map(p => require(resolve(absolutePath, p))); } -module.exports = { PROJECT_ROOT, AIO_PATH, TEMPLATES_PATH, API_TEMPLATES_PATH, CONTENTS_PATH, SRC_PATH, OUTPUT_PATH, DOCS_OUTPUT_PATH, API_SOURCE_PATH, requireFolder }; +module.exports = { PROJECT_ROOT, AIO_PATH, TEMPLATES_PATH, API_TEMPLATES_PATH, CONTENTS_PATH, GUIDE_EXAMPLES_PATH, SRC_PATH, OUTPUT_PATH, DOCS_OUTPUT_PATH, API_SOURCE_PATH, requireFolder }; diff --git a/aio/yarn.lock b/aio/yarn.lock index fc297958b2..73e1451c07 100644 --- a/aio/yarn.lock +++ b/aio/yarn.lock @@ -3366,6 +3366,10 @@ ignore@^3.2.0: version "3.3.0" resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.0.tgz#3812d22cbe9125f2c2b4915755a1b8abd745a001" +ignore@^3.3.3: + version "3.3.3" + resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.3.3.tgz#432352e57accd87ab3110e82d3fea0e47812156d" + ignorefs@^1.0.0, ignorefs@^1.1.1: version "1.2.0" resolved "https://registry.yarnpkg.com/ignorefs/-/ignorefs-1.2.0.tgz#da59fb858976e4a5e43702ccd1f282fdbc9e5756"