From 3934f3621f21ea2514c261af45a2e4553f535222 Mon Sep 17 00:00:00 2001 From: simonihmig Date: Fri, 4 Feb 2022 19:49:25 +0100 Subject: [PATCH] Basic blueprint setup --- LICENSE => LICENSE.md | 0 files/CONTRIBUTING.md | 25 +++++ files/LICENSE.md | 9 ++ files/README.md | 38 ++++++++ files/npmignore | 40 ++++++++ index.js | 212 ++++++++++++++++++++++++++++++++++++++++++ package.json | 24 +++++ yarn.lock | 34 +++++++ 8 files changed, 382 insertions(+) rename LICENSE => LICENSE.md (100%) create mode 100644 files/CONTRIBUTING.md create mode 100644 files/LICENSE.md create mode 100644 files/README.md create mode 100644 files/npmignore create mode 100644 index.js create mode 100644 package.json create mode 100644 yarn.lock diff --git a/LICENSE b/LICENSE.md similarity index 100% rename from LICENSE rename to LICENSE.md diff --git a/files/CONTRIBUTING.md b/files/CONTRIBUTING.md new file mode 100644 index 00000000..6067a969 --- /dev/null +++ b/files/CONTRIBUTING.md @@ -0,0 +1,25 @@ +# How To Contribute + +## Installation + +* `git clone ` +* `cd <%= addonName %>` +* `<% if (yarn) { %>yarn<% } else { %>npm<% } %> install` + +## Linting + +* `<% if (yarn) { %>yarn lint<% } else { %>npm run lint<% } %>` +* `<% if (yarn) { %>yarn lint:fix<% } else { %>npm run lint:fix<% } %>` + +## Running tests + +* `ember test` – Runs the test suite on the current Ember version +* `ember test --server` – Runs the test suite in "watch mode" +* `ember try:each` – Runs the test suite against multiple Ember versions + +## Running the dummy application + +* `ember serve` +* Visit the dummy application at [http://localhost:4200](http://localhost:4200). + +For more information on using ember-cli, visit [https://cli.emberjs.com/release/](https://cli.emberjs.com/release/). \ No newline at end of file diff --git a/files/LICENSE.md b/files/LICENSE.md new file mode 100644 index 00000000..cbf2c032 --- /dev/null +++ b/files/LICENSE.md @@ -0,0 +1,9 @@ +The MIT License (MIT) + +Copyright (c) <%= year %> + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/files/README.md b/files/README.md new file mode 100644 index 00000000..8622b2f8 --- /dev/null +++ b/files/README.md @@ -0,0 +1,38 @@ +<%= addonName %> +============================================================================== + +[Short description of the addon.] + + +Compatibility +------------------------------------------------------------------------------ + +* Ember.js v3.24 or above +* Ember CLI v3.24 or above +* Node.js v12 or above + + +Installation +------------------------------------------------------------------------------ + +``` +ember install <%= addonName %> +``` + + +Usage +------------------------------------------------------------------------------ + +[Longer description of how to use the addon in apps.] + + +Contributing +------------------------------------------------------------------------------ + +See the [Contributing](CONTRIBUTING.md) guide for details. + + +License +------------------------------------------------------------------------------ + +This project is licensed under the [MIT License](LICENSE.md). diff --git a/files/npmignore b/files/npmignore new file mode 100644 index 00000000..f63e7f39 --- /dev/null +++ b/files/npmignore @@ -0,0 +1,40 @@ +# compiled output +/dist/ +/tmp/ + +# dependencies +/bower_components/ + +# misc +/.bowerrc +/.editorconfig +/.ember-cli +/.env* +/.eslintcache +/.eslintignore +/.eslintrc.js +/.git/ +/.github/ +/.gitignore +/.prettierignore +/.prettierrc.js +/.template-lintrc.js +/.travis.yml +/.watchmanconfig +/bower.json +/config/ember-try.js +/CONTRIBUTING.md +/ember-cli-build.js +/testem.js +/tests/ +/yarn-error.log +/yarn.lock +.gitkeep + +# ember-try +/.node_modules.ember-try/ +/bower.json.ember-try +/npm-shrinkwrap.json.ember-try +/package.json.ember-try +/package-lock.json.ember-try +/yarn.lock.ember-try \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 00000000..32b40a14 --- /dev/null +++ b/index.js @@ -0,0 +1,212 @@ +'use strict'; + +// const fs = require('fs-extra'); +// const path = require('path'); +// const walkSync = require('walk-sync'); +// const chalk = require('chalk'); +const stringUtil = require('ember-cli-string-utils'); +// const uniq = require('ember-cli-lodash-subset').uniq; +const SilentError = require('silent-error'); +// const sortPackageJson = require('sort-package-json'); + +let date = new Date(); + +const normalizeEntityName = require('ember-cli-normalize-entity-name'); +// const stringifyAndNormalize = require('../../lib/utilities/stringify-and-normalize'); +// const FileInfo = require('../../lib/models/file-info'); + +// const replacers = { +// 'package.json'(content) { +// return this.updatePackageJson(content); +// }, +// }; + +// const ADDITIONAL_DEV_DEPENDENCIES = require('./additional-dev-dependencies.json').devDependencies; + +const description = 'The default blueprint for Embroider v2 addons.'; +module.exports = { + description, + + // updatePackageJson(content) { + // let contents = JSON.parse(content); + // + // contents.name = stringUtil.dasherize(this.options.entity.name); + // contents.description = this.description; + // delete contents.private; + // contents.scripts = contents.scripts || {}; + // contents.keywords = contents.keywords || []; + // contents.dependencies = contents.dependencies || {}; + // contents.devDependencies = contents.devDependencies || {}; + // + // // npm doesn't like it when we have something in both deps and devDeps + // // and dummy app still uses it when in deps + // contents.dependencies['ember-cli-babel'] = contents.devDependencies['ember-cli-babel']; + // delete contents.devDependencies['ember-cli-babel']; + // + // // Move ember-cli-htmlbars into the dependencies of the addon blueprint by default + // // to prevent error: + // // `Addon templates were detected but there are no template compilers registered for (addon-name)` + // contents.dependencies['ember-cli-htmlbars'] = contents.devDependencies['ember-cli-htmlbars']; + // delete contents.devDependencies['ember-cli-htmlbars']; + // + // // 95% of addons don't need ember-data or ember-fetch, make them opt-in instead + // delete contents.devDependencies['ember-data']; + // delete contents.devDependencies['ember-fetch']; + // + // // 100% of addons don't need ember-cli-app-version, make it opt-in instead + // delete contents.devDependencies['ember-cli-app-version']; + // + // // addons should test _without_ jquery by default + // delete contents.devDependencies['@ember/jquery']; + // + // if (contents.keywords.indexOf('ember-addon') === -1) { + // contents.keywords.push('ember-addon'); + // } + // + // Object.assign(contents.devDependencies, ADDITIONAL_DEV_DEPENDENCIES); + // + // // add `ember-compatibility` script in addons + // contents.scripts['test:ember-compatibility'] = 'ember try:each'; + // + // contents['ember-addon'] = contents['ember-addon'] || {}; + // contents['ember-addon'].configPath = 'tests/dummy/config'; + // + // return stringifyAndNormalize(sortPackageJson(contents)); + // }, + + // buildFileInfo(intoDir, templateVariables, file) { + // let mappedPath = this.mapFile(file, templateVariables); + // let options = { + // action: 'write', + // outputBasePath: path.normalize(intoDir), + // outputPath: path.join(intoDir, mappedPath), + // displayPath: path.normalize(mappedPath), + // inputPath: this.srcPath(file), + // templateVariables, + // ui: this.ui, + // }; + // + // if (file in replacers) { + // options.replacer = replacers[file].bind(this); + // } + // + // return new FileInfo(options); + // }, + + // beforeInstall() { + // const version = require('../../package.json').version; + // const prependEmoji = require('../../lib/utilities/prepend-emoji'); + // + // this.ui.writeLine(chalk.blue(`Ember CLI v${version}`)); + // this.ui.writeLine(''); + // this.ui.writeLine(prependEmoji('✨', `Creating a new Ember addon in ${chalk.yellow(process.cwd())}:`)); + // }, + + // afterInstall() { + // let packagePath = path.join(this.path, 'files', 'package.json'); + // let bowerPath = path.join(this.path, 'files', 'bower.json'); + // + // [packagePath, bowerPath].forEach((filePath) => { + // fs.removeSync(filePath); + // }); + // }, + + locals(options) { + let entity = { name: 'dummy' }; + let rawName = entity.name; + let name = stringUtil.dasherize(rawName); + let namespace = stringUtil.classify(rawName); + + let addonEntity = options.entity; + let addonRawName = addonEntity.name; + let addonName = stringUtil.dasherize(addonRawName); + let addonNamespace = stringUtil.classify(addonRawName); + + let hasOptions = options.welcome || options.yarn || options.ciProvider; + let blueprintOptions = ''; + if (hasOptions) { + let indent = `\n `; + let outdent = `\n `; + + blueprintOptions = + indent + + [ + options.welcome && '"--welcome"', + options.yarn && '"--yarn"', + options.ciProvider && `"--ci-provider=${options.ciProvider}"`, + ] + .filter(Boolean) + .join(',\n ') + + outdent; + } + + return { + name, + modulePrefix: name, + namespace, + addonName, + addonNamespace, + // emberCLIVersion: require('../../package').version, + year: date.getFullYear(), + yarn: true, // only yarn is supported for now + // yarn: options.yarn, + welcome: options.welcome, + blueprint: 'addon', + blueprintOptions, + ciProvider: options.ciProvider, + }; + }, + + // files(options) { + // let appFiles = this.lookupBlueprint(this.appBlueprintName).files(options); + // let addonFilesPath = this.filesPath(this.options); + // let ignoredCITemplate = this.options.ciProvider !== 'travis' ? '.travis.yml' : '.github'; + // + // let addonFiles = walkSync(addonFilesPath, { ignore: [ignoredCITemplate] }); + // + // return uniq(appFiles.concat(addonFiles)); + // }, + + mapFile() { + let result = this._super.mapFile.apply(this, arguments); + return this.fileMapper(result); + }, + + fileMap: { + // '^app/.gitkeep': 'app/.gitkeep', + // '^app.*': 'tests/dummy/:path', + // '^config.*': 'tests/dummy/:path', + // '^public.*': 'tests/dummy/:path', + // + // '^addon-config/environment.js': 'config/environment.js', + // '^addon-config/ember-try.js': 'config/ember-try.js', + + '^npmignore': '.npmignore', + }, + + fileMapper(path) { + for (let pattern in this.fileMap) { + if (new RegExp(pattern).test(path)) { + return this.fileMap[pattern].replace(':path', path); + } + } + + return path; + }, + + normalizeEntityName(entityName) { + entityName = normalizeEntityName(entityName); + + if (this.project.isEmberCLIProject() && !this.project.isEmberCLIAddon()) { + throw new SilentError('Generating an addon in an existing ember-cli project is not supported.'); + } + + return entityName; + }, + + // srcPath(file) { + // let path = `${this.path}/files/${file}`; + // let superPath = `${this.lookupBlueprint(this.appBlueprintName).path}/files/${file}`; + // return fs.existsSync(path) ? path : superPath; + // }, +}; \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 00000000..6001087b --- /dev/null +++ b/package.json @@ -0,0 +1,24 @@ +{ + "name": "ember-v2-addon-blueprint", + "version": "0.0.0", + "description": "Blueprint for scaffolding ember v2 addons", + "keywords": [ + "ember-addon", + "ember-blueprint" + ], + "repository": "https://github.com/simonihmig/ember-v2-addon-blueprint.git", + "author": "simonihmig ", + "license": "MIT", + "dependencies": { + "ember-cli-normalize-entity-name": "^1.0.0", + "ember-cli-string-utils": "^1.1.0", + "silent-error": "^1.1.1" + }, + "engines": { + "node": "12.* || >= 14.*" + }, + "volta": { + "node": "12.22.10", + "yarn": "1.22.17" + } +} diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 00000000..2cc4dd3a --- /dev/null +++ b/yarn.lock @@ -0,0 +1,34 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +debug@^2.2.0: + version "2.6.9" + resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" + integrity sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA== + dependencies: + ms "2.0.0" + +ember-cli-normalize-entity-name@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/ember-cli-normalize-entity-name/-/ember-cli-normalize-entity-name-1.0.0.tgz#0b14f7bcbc599aa117b5fddc81e4fd03c4bad5b7" + integrity sha1-CxT3vLxZmqEXtf3cgeT9A8S61bc= + dependencies: + silent-error "^1.0.0" + +ember-cli-string-utils@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/ember-cli-string-utils/-/ember-cli-string-utils-1.1.0.tgz#39b677fc2805f55173735376fcef278eaa4452a1" + integrity sha1-ObZ3/CgF9VFzc1N2/O8njqpEUqE= + +ms@2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" + integrity sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g= + +silent-error@^1.0.0, silent-error@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/silent-error/-/silent-error-1.1.1.tgz#f72af5b0d73682a2ba1778b7e32cd8aa7c2d8662" + integrity sha512-n4iEKyNcg4v6/jpb3c0/iyH2G1nzUNl7Gpqtn/mHIJK9S/q/7MCfoO4rwVOoO59qPFIc0hVHvMbiOJ0NdtxKKw== + dependencies: + debug "^2.2.0"