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

Alias package name to root directory #651

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
generate template app with absolute import paths
  • Loading branch information
ccorcos committed Sep 14, 2016
commit f2e3490f17c2ff3aee8c9711c6875b82a31c23e4
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"filesize": "3.3.0",
"find-cache-dir": "^0.1.1",
"fs-extra": "0.30.0",
"glob": "^7.0.6",
"gzip-size": "3.0.0",
"html-loader": "0.4.3",
"html-webpack-plugin": "2.22.0",
Expand Down
8 changes: 8 additions & 0 deletions scripts/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var path = require('path');
var spawn = require('cross-spawn');
var pathExists = require('path-exists');
var chalk = require('chalk');
var glob = require('glob');

module.exports = function(appPath, appName, verbose, originalDirectory) {
var ownPath = path.join(appPath, 'node_modules', 'react-scripts');
Expand Down Expand Up @@ -43,6 +44,13 @@ module.exports = function(appPath, appName, verbose, originalDirectory) {
// Copy the files for the user
fs.copySync(path.join(ownPath, 'template'), appPath);

// Rewrite the root path
glob.sync(path.join(appPath, 'src/**/*.{js,css,html,md,svg}')).forEach(function (file) {
const templateStr = fs.readFileSync(file, {encoding: 'utf8'})
const str = templateStr.replace(/__ROOT__/g, appPackage.name)
fs.writeFileSync(file, str)
})

// Rename gitignore after the fact to prevent npm from renaming it to .npmignore
// See: https://github.com/npm/npm/issues/1862
fs.move(path.join(appPath, 'gitignore'), path.join(appPath, '.gitignore'), [], function (err) {
Expand Down
4 changes: 2 additions & 2 deletions template/src/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import logo from '__ROOT__/src/logo.svg';
import '__ROOT__/src/App.css';

class App extends Component {
render() {
Expand Down
2 changes: 1 addition & 1 deletion template/src/App.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import App from '__ROOT__/src/App';

it('renders without crashing', () => {
const div = document.createElement('div');
Expand Down
4 changes: 2 additions & 2 deletions template/src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import './index.css';
import App from '__ROOT__/src/App';
import '__ROOT__/src/index.css';

ReactDOM.render(
<App />,
Expand Down