Skip to content

Commit

Permalink
no shitty site build
Browse files Browse the repository at this point in the history
  • Loading branch information
Dariusz authored and Dariusz committed Apr 2, 2018
1 parent 5db83b3 commit d14b9ae
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 48 deletions.
16 changes: 1 addition & 15 deletions src/build-tool/build.ts
Expand Up @@ -26,7 +26,6 @@ export interface BuildPathes {
build?: {
forNPMlink?: boolean;
withoutBackend?: boolean;
forSitePurpose?: boolean;
otherIsomorphicLibs?: string[];
}
onlyMainIndex?: boolean;
Expand Down Expand Up @@ -72,22 +71,9 @@ export function buildIsomorphicVersion(options?: BuildPathes) {
const BUILD = _.merge({
forNPMlink: true,
withoutBackend: false,
forSitePurpose: false,
otherIsomorphicLibs: []
}, build);



if (BUILD.forSitePurpose) {
const siteSrc = `tmp-site-${FOLDER.src}`;
child.execSync(`rimraf ${siteSrc}`);
child.execSync(`${TOOLS.cpr} ${FOLDER.src} ${siteSrc} --overwrite`)
FOLDER.src = siteSrc;
FOLDER.tsconfig.default = 'tsconfig.site.json'
FOLDER.tsconfig.browser = 'tsconfig.site.browser.json'
const filesForSite = glob.sync(`./${siteSrc}/**/*.ts`);
CodeTransform.for.baselineSite(filesForSite);
}
BUILD

if (!BUILD.withoutBackend) {
child.execSync(`${TOOLS.rimraf} ${FOLDER.dist}`)
Expand Down
53 changes: 20 additions & 33 deletions src/build-tool/isomorphic.ts
Expand Up @@ -13,14 +13,7 @@ export class CodeTransform {

public static get for() {
return {
baselineSite(filesPathes: string[]) {
filesPathes.forEach(f => {
new CodeTransform(f)
.replace.regionsFor.baselineSite()
.save()
})

},
isomorphicLib(filesPathes: string[], otherIsomorphicLibs: string[] = []) {
filesPathes.forEach(f => {
new CodeTransform(f, otherIsomorphicLibs)
Expand Down Expand Up @@ -66,7 +59,9 @@ export class CodeTransform {
return this;
}


/**
* Get "npm package name" from line of code in .ts or .js files
*/
private get resolvePackageNameFrom() {
const self = this;
return {
Expand All @@ -87,7 +82,7 @@ export class CodeTransform {
rawImport = rawImport.replace(new RegExp(`${usage}.+from\\s+`), '')
rawImport = rawImport.replace(new RegExp(`(\'|\")`, 'g'), '').trim()
if (rawImport.startsWith(`./`)) return null;
const fisrtName = rawImport.match(new RegExp(`[a-zA-z]+\\/`))
const fisrtName = rawImport.match(new RegExp(`([a-zA-z]|\-)+\\/`))
let res: string = (_.isArray(fisrtName) && fisrtName.length > 0) ? fisrtName[0] : rawImport;
if (res.endsWith('/') && res.length > 1) {
res = res.substring(0, res.length - 1)
Expand All @@ -99,18 +94,24 @@ export class CodeTransform {

private isomorphicLibs = ['ng2-rest', 'typeorm', 'ng2-logger', 'morphi'];


private package(packageName: string) {
/**
* Check if package of isomorphic-lib type
* @param packageName
*/
private isIsomorphic(packageName: string) {

// console.log('MORPHI this.isomorphicLibs', this.isomorphicLibs)
let realName = packageName;
let isIsomorphic = false;
if (packageName !== null) {
isIsomorphic = this.isomorphicLibs
.filter(p => {
isIsomorphic = !!this.isomorphicLibs
.find(p => {
if (p === packageName) {
return true;
}
const slashes = (p.match(new RegExp("\/", "g")) || []).length;
if (slashes === 0) {
return p == packageName
return p === packageName
}
// console.log('am here ', packageName)
// console.log('p', p)
Expand All @@ -121,8 +122,7 @@ export class CodeTransform {
return true;
}
return false;
})
.length >= 1;
});
}
return {
isIsomorphic,
Expand Down Expand Up @@ -155,11 +155,8 @@ export class CodeTransform {
if (_.isArray(imports)) {
imports.forEach(imp => {
const pkgName = self.resolvePackageNameFrom.TSimportExport(imp, usage);
// if (pkgName === null) {
// console.log('null for ', imp)
// process.exit(0)
// }
const p = self.package(pkgName)

const p = self.isIsomorphic(pkgName)
if (p.isIsomorphic) {
const replacedImp = imp.replace(p.realName, `${p.realName}/browser`);
self.rawContent = self.rawContent.replace(imp, replacedImp);
Expand All @@ -177,11 +174,8 @@ export class CodeTransform {
if (_.isArray(imports)) {
imports.forEach(imp => {
const pkgName = self.resolvePackageNameFrom.JSrequired(imp);
// if (pkgName === null) {
// console.log('null for ', imp)
// process.exit(0)
// }
const p = self.package(pkgName)

const p = self.isIsomorphic(pkgName)
if (p.isIsomorphic) {
// console.log('isomorphic: ', pkgName)
const replacedImp = imp.replace(p.realName, `${p.realName}/browser`);
Expand All @@ -203,15 +197,8 @@ export class CodeTransform {
"backendFunc"
], '')
return self;
},
baselineSite() {
self.rawContent = self.replaceRegionsWith(self.rawContent, [
'@cutForSite'
], '')
return self;
}
}

}
};

Expand Down

0 comments on commit d14b9ae

Please sign in to comment.