Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | 5x 5x 5x | import {join} from 'path';
import {
PackageJsonEditor,
Scaffolder,
allDoExist,
install
} from '../../api';
const DEV_DEPENDENCIES = [
'npm-run-all'
];
const ALWAYS = () => true;
/**
* @type {task[]}
* @see https://reactjs.org/
*/
export const addReact = [
{
text: 'Copy React boilerplate and assets',
task: async ({assetsDirectory, sourceDirectory, overwrite, useParcel, useSnowpack}) => {
const format = filename => {
const [name, extension] = filename.split('.');
const type = useSnowpack ? 'snowpack' : (useParcel ? 'parcel' : 'default');
const dict = {
snowpack: {
main: `main-snowpack.${extension}`,
app: `App-snowpack.${extension}`,
body: `Body-snowpack.${extension}`,
header: `Header-snowpack.${extension}`,
footer: `Footer-snowpack.${extension}`,
index: `index-in-place-react-snowpack.${extension}`,
style: `style-snowpack.${extension}`,
fonts: 'fonts-in-place.css'
},
parcel: {
main: `main-parcel.${extension}`,
app: `App-parcel.${extension}`,
body: `Body.${extension}`,
header: `Header.${extension}`,
footer: `Footer.${extension}`,
index: `index-in-place-react.html`,
style: `style.${extension}`,
fonts: 'fonts-in-place.css'
},
default: {
main: `main.${extension}`,
app: `App.${extension}`,
body: `Body.${extension}`,
header: `Header.${extension}`,
footer: `Footer.${extension}`,
index: `index-react.html`,
style: `style.${extension}`,
fonts: 'fonts.css'
}
};
return dict[type][name.toLowerCase()];
};
await (new Scaffolder(join(__dirname, 'templates')))
.overwrite(overwrite)
.target(sourceDirectory)
.copy(format('main.js'), `main.js${useSnowpack ? '' : 'x'}`)
.target(`${sourceDirectory}/components`)
.copy(format('App.js'), 'App.jsx')
.copy(format('Header.js'), 'Header.jsx')
.copy(format('Body.js'), 'Body.jsx')
.copy(format('Footer.js'), 'Footer.jsx')
.commit();
await (new Scaffolder(join(__dirname, '..', 'common', 'templates')))
.overwrite(overwrite)
.target('.')
.copy('gitignore', '.gitignore')
.target(`${assetsDirectory}`)
.copy(format('index.html'), 'index.html')
.target(`${assetsDirectory}/css`)
.copy(format('style.css'), 'style.css')
.copy(format('fonts.css'), 'fonts.css')
.target(`${assetsDirectory}/images`)
.copy('react.png')
.copy('preferences.png')
.target(`${assetsDirectory}/fonts`)
.copy('SansForgetica-Regular.eot')
.copy('SansForgetica-Regular.svg')
.copy('SansForgetica-Regular.ttf')
.copy('SansForgetica-Regular.woff')
.copy('SansForgetica-Regular.woff2')
.target(`${assetsDirectory}/library`)
.copy('.gitkeep')
.target(`${assetsDirectory}/workers`)
.copy('.gitkeep')
.commit();
},
condition: ALWAYS
},
{
text: 'Copy Rust boilerplate',
task: async ({overwrite}) => {
await (new Scaffolder(join(__dirname, '..', 'common', 'templates')))
.overwrite(overwrite)
.target('.')
.copy('Cargo.toml')
.target('rust-to-wasm')
.copy('Cargo_crate.toml', 'Cargo.toml')
.target('rust-to-wasm/src')
.copy('lib.rs')
.copy('utils.rs')
.target('rust-to-wasm/tests')
.copy('app.rs')
.copy('web.rs')
.commit();
},
condition: ({withRust}) => withRust,
optional: ({withRust}) => withRust
},
{
text: 'Set package.json "main" attribute and add scripts tasks',
task: async ({sourceDirectory, useParcel, useRollup, useSnowpack}) => {
const main = `${sourceDirectory}/main.js`;
const watches = {
'watch:es': useRollup ? `watch \"npm run build:es\" ${sourceDirectory}` : 'webpack serve --hot --open --mode development'
};
const scripts = {
...(useSnowpack ? {} : watches),
start: useSnowpack ? 'snowpack dev' : 'npm-run-all build:es --parallel watch:*'
};
await (new PackageJsonEditor())
.extend({main})
.extend(useParcel ? {} : {scripts})
.commit();
},
condition: () => allDoExist('package.json')
},
{
text: 'Install React dependencies',
task: async ({legacyNpm, reactVersion, skipInstall, useSnowpack}) => {
const dependencies = [
'prop-types',
`react@${reactVersion}`,
`react-dom@${reactVersion}`,
'wouter', // https://github.com/molefrog/wouter
...(useSnowpack ? [] : ['@hot-loader/react-dom'])
];
await install(dependencies, {latest: false, legacy: legacyNpm, skipInstall});
await install(DEV_DEPENDENCIES, {dev: true, skipInstall});
},
condition: ({skipInstall}) => !skipInstall && allDoExist('package.json')
}
];
export default addReact;
|